19 Time Series

This chapter originated as a community contribution created by HaiqingXu

This page is a work in progress. We appreciate any input you may have. If you would like to help improve this page, consider contributing to our repo.

19.1 Overview

This section discusses drawing graphics for time series data.

19.2 Single/Multiple Time Series

We can draw time series using geom_line() with time on the x-axis. X-axis should be an object in the Date class, assuming there is no hour/minute/second data.

We can also draw multiple time series on one plot for comparison purpose:

The following exmaple shows the closing price for four big technology companies in the US. When analyzing GDP, salary level and stock prices, it is often difficult to compare trends since the scales are so different. For example, since AAPL and MSFT prices per share are so much lower than GOOG’s price per share, it’s hard to discern the trends:

In such a case, it can be helpful to rescale the data. We rescaled the data to make sure these four stocks have a price of 100 on Jan 2013:

19.3 Secular Trend

Instead of looking at observations over time, we often want to ovserve overall long-term trend in our time series data. In this case, we can use geom_smooth(). Here we will show secular trend using the Loess Smoother.

Experiment with different smoothing parameters.