Day 3 - ggplot and beyond

Questions before we begin?

Today - all about plotting data

But first, a crash course on using ChatGPT in R - by Julian Schüssler

Then, we’re covering quite some ground regarding ggplot and its wider universe.

  1. Recap basic concepts: Data, Aesthetics, Layers

  2. Recap basic concepts: Facets, Scales, Coordinate Systems

  3. Combining plots using {patchwork}

  4. Plotting models

  5. Practice: plot your own data / Recreate the plot challenge

A quick survey

  • What’s your previous experience with ggplot?
  • What are your proudest moments?
  • What have you been struggling with?

Introduction to ggplot2 and the Grammar of Graphics

What is ggplot2?

  • ggplot2 is an R package for creating data visualizations.
  • It follows the principles of the Grammar of Graphics.

Recap

Let’s learn from a professional

To cover the basic ground, we’re going through two slidedecks by the brilliant Cedric Scherer.

This is not because I’m lazy, but just because anything I’d done myself would have been worse than these beautiful slides.

The Grammar of {ggplot2}

The Grammar of {ggplot2}


Component Function Explanation
Data ggplot(data)          The raw data that you want to visualise.
Aesthetics           aes() Aesthetic mappings between variables and visual properties.
Geometries geom_*() The geometric shapes representing the data.
Statistics stat_*() The statistical transformations applied to the data.
Scales scale_*() Maps between the data and the aesthetic dimensions.
Coordinate System coord_*() Maps data into the plane of the data rectangle.
Facets facet_*() The arrangement of the data into a grid of plots.
Visual Themes theme() and theme_*() The overall visual defaults of a plot.