typestar

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.

Start this tour

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

Encore

  • gg_dashboard.RFour plots from one dataset, arranged and written to a single file.

The other R tours