Activity: Plot the Monthly Closing Stock Prices and the Mean Values

Scenario

We are interested in looking at the monthly fluctuations in stock prices (as daily stock prices have too much variation) and identifying any trends.

Aim

To plot the monthly closing stock prices, and then use the summary tools to plot the mean closing stock price. Steps for Completion

  1. Use the strftime command to get the month from each date and make another variable (Month).
  2. Change the month to a numerical value by using as.numeric.
  3. Now, use ggplot to make a plot of closing prices versus months.
  4. Plot the data using geom_point (color=red).
  5. Change the x scale to show each month, and label the x-axis, such that each month is shown.
  6. Title your plot Monthly closing stock ...

Get Applied Data Visualization with R and ggplot2 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.