Plotting a time series object
Plotting a time series object will make trends and seasonal composition clearly visible. In this recipe, we introduce how to plot time series data with the plot.ts
function.
Getting ready
Ensure you have completed the previous recipe by generating a time series object and storing it in two variables: m
and m_ts
.
How to do it…
Please perform the following steps to plot time series data:
- First, use the
plot.ts
function to plot time series data,m
:> plot.ts(m)
- Also, if the dataset contains multiple time series objects, you can plot multiple time series data in a separate sub-figure:
> plot.ts(m_ts, plot.type = "multiple",)
- Alternatively, you can plot all four time series objects in a single figure:
> plot.ts(m_ts, plot.type = "single", col=c("red","green","blue", "orange"))