Skip to content
AgileLogics
6 min read

Customizing Charts: Facets, Scales, and Themes

Prerequisites: Data visualization with ggplot2

A good chart needs more than the right geom. These tools make charts clearer and ready to share.

Facets — small multiples

Facets split one chart into a panel per group, making comparisons easy:

library(ggplot2)

ggplot(mpg, aes(x = displ, y = hwy)) +
  geom_point(alpha = 0.6) +
  facet_wrap(~ drv, labeller = as_labeller(c(`4` = "4-wheel drive", f = "Front-wheel", r = "Rear-wheel")))

facet_wrap(~ drv) draws one panel per drive type, all on the same axes. facet_grid(rows ~ cols) arranges panels by two variables.

Scales — axes, colours, and labels

Scales control how data values map to what you see:

library(ggplot2)

ggplot(economics, aes(x = date, y = unemploy * 1000)) +
  geom_line(colour = "firebrick") +
  scale_y_continuous(labels = scales::label_comma()) +
  scale_x_date(date_breaks = "10 years", date_labels = "%Y") +
  labs(x = NULL, y = "Unemployed people (US)")
  • scales::label_comma() formats 8000000 as 8,000,000; label_percent() and label_dollar() are similar helpers.
  • scale_x_date controls date axis breaks and formats.
  • scale_colour_brewer(palette = "Set2") or scale_colour_viridis_d() choose colour palettes that are distinct and colour-blind friendly.

Themes — the overall look

library(ggplot2)

ggplot(mpg, aes(x = class, y = hwy)) +
  geom_boxplot() +
  theme_minimal(base_size = 13) +
  theme(
    panel.grid.major.x = element_blank(),
    axis.text.x = element_text(angle = 30, hjust = 1),
    plot.title.position = "plot"
  ) +
  labs(title = "Highway fuel economy by car class", x = NULL, y = "MPG")

Built-in themes (theme_minimal, theme_classic, theme_bw) set the overall style; theme() adjusts individual elements. Set a theme for a whole script with theme_set(theme_minimal()).

Making charts honest and readable

  • Title the finding, not just the variables: "Unemployment peaked in 2009" beats "Unemployment over time".
  • Start bar charts at zero — shortened bars exaggerate differences.
  • Sort categories by value, not alphabetically, unless the order is meaningful.
  • Don't rely on colour alone to carry meaning; label lines directly where you can, and use colour-blind-friendly palettes.
  • Remove clutter — extra gridlines, borders, and 3D effects make charts harder to read.