Get startedGet started for free

Basic time series plots

While simple commands such as print(), length(), head(), and tail() provide crucial information about your time series data, another very useful way to explore any data is to generate a plot.

In this exercise, you will plot the River Nile annual streamflow data using the plot() function. For time series data objects such as Nile, a Time index for the horizontal axis is typically included. From the previous exercise, you know that this data spans from 1871 to 1970, and horizontal tick marks are labeled as such. The default label of "Time" is not very informative. Since these data are annual measurements, you should use the label "Year". While you're at it, you should change the vertical axis label to "River Volume (1e9 m^{3})".

Additionally, it helps to have an informative title, which can be set using the argument main. For your purposes, a useful title for this figure would be "Annual River Nile Volume at Aswan, 1871-1970".

Finally, the default plotting type for time series objects is "l" for line. Connecting consecutive observations can help make a time series plot more interpretable. Sometimes it is also useful to include both the observations points as well as the lines, and we instead use "b" for both.

This exercise is part of the course

Time Series Analysis in R

View Course

Exercise instructions

  • Use plot() to display the Nile dataset.
  • Use a second call to plot() to display the data, but add the additional arguments: xlab = "Year", ylab = "River Volume (1e9 m^{3})".
  • Use a third call to plot() with your Nile data, but this time also add a title and include observation points in the figure by specifying the following arguments: main = "Annual River Nile Volume at Aswan, 1871-1970", type ="b".

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# Plot the Nile data
plot(___)

# Plot the Nile data with xlab and ylab arguments
plot(___, xlab = "___", ylab = "___")

# Plot the Nile data with xlab, ylab, main, and type arguments

Edit and Run Code