Visualize flight data
Now that you have a grip on your data, the next step is to visualize trends in your data over time. In this exercise, you'll plot the flights_xts
data over time using a few different methods for plotting time series data.
Often the simplest way to plot xts objects is to use plot.xts(), which requires only a single argument for the y-axis in the plot. The x-axis is supplied by the time index in your xts object.
For more complicated plots, you may want to use plot.zoo(), which allows you to include multiple columns of data. In particular, the plot.type
argument allows you to specify whether you'd like your data to appear in a single panel ("single"
) or multiple panels ("multiple"
). This can be useful when comparing multiple columns of data over time.
Diese Übung ist Teil des Kurses
Case Study: Analyzing City Time Series Data in R
Anleitung zur Übung
- Use
plot.xts()
to view the total monthly flights into BOS (total_flights
) over time. This command only requires you to specify the data for the y-axis, although you do need to be specific about which column of data you want to plot. - Use another call to
plot.xts()
to produce a plot of monthly delayed flights into BOS over time. - Generate a plot of all four time series columns in
flights_xts
usingplot.zoo()
. Set theplot.type
argument to"multiple"
to produce a plot with four different panels. Leave theylab
argument as is. - Put all four plots on a single panel using another call to
plot.zoo()
. Leave thelty
argument and thelegend
function as they are.
Interaktive Übung
Versuche dich an dieser Übung, indem du diesen Beispielcode vervollständigst.
# Use plot.xts() to view total monthly flights into BOS over time
plot.xts(___)
# Use plot.xts() to view monthly delayed flights into BOS over time
# Use plot.zoo() to view all four columns of data in their own panels
plot.zoo(___, plot.type = "___", ylab = labels)
# Use plot.zoo() to view all four columns of data in one panel
plot.zoo(___, plot.type = "___", lty = lty)
legend("right", lty = lty, legend = labels)