ggplot2
15 steps in 5 sets of R.
Still the best implementation of a grammar of graphics anywhere, and the reason a lot of people put up with R. The grammar first: data, aesthetics, geometries, and the distinction between mapping a variable and setting a constant, which trips up everyone once.
Then geometries, facets and scales, and the theme work that finishes a plot. Fifteen steps, ending with a dashboard.
The grammar
- The grammarData, aesthetic mapping, geometry: every plot is those three plus extras.
- AestheticsColor, shape and size can carry data, or be fixed constants.
- ggplot2 scatter plotsThe grammar of graphics: data, aesthetics, layers.
Geometries
- Bar chartsgeom_col takes the heights you supply; geom_bar counts rows for you.
- DistributionsHistogram, density, boxplot and violin, each answering a different question.
- Trendsgeom_smooth fits a line or a loess curve, with a confidence band.
- ggplot2 bars and facetsCategorical charts and small multiples.
Panels & scales
- FacetsSmall multiples: the same plot, once per group.
- ScalesScales control the mapping from data to pixels, colors and breaks.
- Color scalesDiscrete palettes, continuous gradients, and naming colors yourself.
- Coordinatescoord_flip, zooming without dropping data, and fixed aspect ratios.
Finishing a plot
- Labels and annotationTitles, captions, and pointing at the one observation that matters.
- ThemesA theme is every non-data element: fonts, grids, legends, margins.
- From data to plot in one pipelineThe tidyverse habit: reshape, then plot, without an intermediate variable.
Encore
- gg_dashboard.RFour plots from one dataset, arranged and written to a single file.