Key Points
-
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.
- 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.
- 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.
- 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)
- 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
-
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