This document explains time series related plotting using ggplot2 and ggfortify.

Installation

First, install ggfortify from github.

library(devtools)
install_github('sinhrks/ggfortify')

Plotting ts objects

ggfortify let ggplot2 know how to interpret ts objects. After loading ggfortify, you can use ggplot2::autoplot function for ts objects.

library(ggfortify)
autoplot(AirPassengers)

To change line colour and line type, use ts.colour and ts.linetype options. Use help(autoplot.ts) (or help(autoplot.*) for any other objects) to check available options.

autoplot(AirPassengers, ts.colour = 'red', ts.linetype = 'dashed')

Multivariate time series will be drawn with facets.

library(vars)
data(Canada)
autoplot(Canada)

Specify facets = FALSE to draw on single axes.

autoplot(Canada, facets = FALSE)

Also, autoplot can handle other time-series-likes. Supported packages are:

library(xts)
autoplot(as.xts(AirPassengers), ts.colour = 'green')

library(timeSeries)
autoplot(as.timeSeries(AirPassengers), ts.colour = ('dodgerblue3'))