Key Points

ggplot2 Essentials


  • ggplot2 can quickly create simple plots for exploratory data analysis.
  • ggplot2 plots are built around the grammer of graphics where the key components of a plot can be extended with the additional geom layers.

Explore Relationships


  • Scatterplots are useful for exploring relationships between variables.
  • Aesthetic mappings connect variables in the data to visual properties such as colour.
  • Aesthetic settings apply the same visual property to all observations.
  • ggplot2 plots can be built up by adding layers with +.
  • Different layers can have different aesthetic mappings.

Understand Distributions


  • A distribution describes how a single variable’s values are spread.
  • geom_density() creates a smooth representation of that distribution.
  • Mapping fill allows comparison across groups.
  • Focus on shape, spread, and overlap
  • Histograms show the same idea, but with binned counts instead of a smooth curve.

Compare Groups


  • Boxplots summarise distributions using median, spread, and outliers
  • Mapping x = group and y = numeric creates group comparisons
  • Boxplots are useful when comparing many groups
  • They trade detail (shape) for clarity (summary)

Explore Composition


  • Bar plots show how data are divided into categories
  • geom_bar() counts observations automatically
  • Mapping fill shows composition within groups
  • position = "fill" converts counts to proportions
  • Composition focuses on parts of a whole, rather than shape or summary

Communicate Results


  • labs() adds informative titles and axis labels
  • facet_wrap() creates a panel for each group
  • Faceting can make complex plots easier to interpret
  • Small theme adjustments can improve readability
  • Effective visualisation includes clear communication, not just correct code