Lesson 14 / 25
Facets, Scales, Labels and Themes
Make publication-quality charts with facets, scales, labels and themes.
From exploration to communication
Exploratory plots are quick; plots for reports need care. Facets split one plot into small multiples by a variable: facet_wrap(~ city) or facet_grid(rows ~ cols), often clearer than crowding many colours into one panel. Scales control how data maps to visuals: scale_y_continuous(labels = scales::label_comma()) or scales::label_currency(prefix = "₹") for readable numbers, scale_colour_brewer() or scale_colour_viridis_d() for colour-blind-friendly palettes, and log scales for skewed data. labs() sets the title, subtitle, axis labels, caption (cite your data source) and legend titles. Themes change the look: theme_minimal(), theme_bw(), and theme() adjustments for font sizes, legend position and gridlines; you can set a default with theme_set(). Extensions such as patchwork combine plots, ggrepel avoids overlapping labels, and plotly (ggplotly()) adds interactivity. Good charts start the y-axis at zero for bars, avoid 3D effects, and label directly where possible.
A polished faceted chart
Readable currency labels, a colour-blind-friendly palette and a clean theme.
library(ggplot2)
library(scales)
monthly <- sales |>
dplyr::mutate(month = lubridate::floor_date(order_date, "month")) |>
dplyr::summarise(revenue = sum(amount_inr), .by = c(city, month))
ggplot(monthly, aes(x = month, y = revenue, colour = city)) +
geom_line(linewidth = 1) +
geom_point() +
facet_wrap(~ city, ncol = 2) +
scale_y_continuous(labels = label_comma(prefix = "Rs ")) +
scale_colour_viridis_d(guide = "none") + # facets already identify cities
labs(
title = "Monthly revenue by city",
subtitle = "Financial year 2026-27",
x = NULL, y = "Revenue",
caption = "Source: internal orders database"
) +
theme_minimal(base_size = 12)Tidying a room before guests arrive
An exploratory plot is a room you live in: functional but messy. A report plot is the same room tidied for guests: labels on the doors, colours that match, and nothing distracting on the floor.
Quick check: What does facet_wrap(~ city) do?
- Changes the colour palette
- Sorts the data
- Saves the plot
- Creates small multiples: one panel per city
Answer
Creates small multiples: one panel per city — Faceting splits the data into panels by a variable.