Overview
ggplot2 is a grammar of graphics, a coherent system for describing and building graphs.
- data (data frame):
ggplot(dataset)
- aesthetic mapping (coordination system, color, size, line type, position etc):
aes()
- geometries:
geom_point
, geom_line
, geom_bar
, …
- stat (summarization/transformation of data):
stat_smooth
,
- scale (map data values into computer values):
scale_y_continuous()
, scale_x_log10
, …
- facet:
facet_wrap
, facet_grid
- fine tuning coordinatae, theme, labels:
coordinate_*
, theme_bw
, labs(x=..., y=...)
Exercise
- Plot the daily bike counts for Hawthorne and Tilikum with ggplot2; Experiement with different options and select the one works best for you;
- Plot weekly, monthly, and annual bike counts for Hawthorne and Tilikum;
- Now think about and try out different ways to plot weather information along with your daily bike counts (separately or together);
- You can combine time series stats and ggplot2/ggfortify to plot seasonal variation, trend and noise separately. See here for an example of how to do this.