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
- Use the strftime command to get the month from each date and make another variable (Month).
- Change the month to a numerical value by using as.numeric.
- Now, use ggplot to make a plot of closing prices versus months.
- Plot the data using geom_point (color=red).
- Change the x scale to show each month, and label the x-axis, such that each month is shown.
- Title your plot Monthly closing stock prices: Facebook.
The following is a screenshot of the output:
Analysis
As you can see, although the closing prices have a lot of fluctuation during each month, the mean has less variation and indicates some trends; we can conclude that the closing prices get slightly higher as we approach December.