Creating a Time Series Plot with the Mean, Median, and Quantiles

In this section, we'll create a time series plot, and then plot its mean, median, and 10% and 90% quantiles. Let's execute the following code:

ggplot(df_fb, aes(Month,Close)) + geom_point(color="red",alpha=1/2,position = position_jitter(h=0.0,w=0.0))+ geom_line(stat='summary',fun.y=mean, color="blue",size=1)+geom_line(stat='summary',fun.y=median,color="orange",size=1)+geom_line(stat='summary',fun.y=quantile, fun.args=list(probs=0.1), linetype=2,color='green',size=1.)+geom_line(stat='summary',fun.y=quantile, fun.args=list(probs=0.9),linetype=2,color='green',size=1.)+scale_x_continuous(breaks=seq(0,13,1))+ggtitle("Monthly Closing Stock Prices: Facebook")+theme_classic()

Take a ...

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.