Plotting an aggregated time series with ggplot2
Aggregating data allows you to uncover general patterns and trends in your data, but can often lead to a loss of information and context. However, using methods from ggplot2 can give some context back to the aggregated data.
In this exercise, you'll practice plotting weekly aggregated temperature readings, weekly_avg, alongside the original, unaggregated time series, hourly_temperature, which represents temperature readings for an entire year, sampled every hour.
The time series hourly_temperature and weekly_avg, as well as the ggplot2 and zoo packages are available to you.
Este exercício faz parte do curso
Manipulating Time Series Data in R
Instruções do exercício
Using the
ggplot()function, plot thehourly_temperaturetime series as a line plot.Add the y-axis label
"Degrees Celsius"and the title"Temperature Readings".Complete the second call to
geom_line()andaes()to overlay theweekly_avgtime series on your plot.Change the line color of the weekly aggregate to red and the size of the line to
2.
Exercício interativo prático
Experimente este exercício completando este código de exemplo.
# Create a plot of the hourly_temperature time series
ggplot(___, aes(___)) +
___ +
scale_y_continuous() +
# Add axis label and title
labs(___) +
# Add a line plot for the weekly aggregated time series
geom_line(data = ___, aes(___),
# Color the aggregated line in red, with a size of 2
___)