Explanation of the Code

When we use geom_line, we need to specify group=1, because for line graphs, the data points must be grouped. In this case, since all of the points should be connected, the value of the group=1. When more variables are used and multiple lines are drawn, the line grouping is usually done by a variable.

Now, instead of a time series depicting daily prices, we would like to make a plot of prices for every month and also look at the mean closing price for every month.

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.