D3: Publication-Quality Figures

Practical workshop — bring your laptop

Friday Workshop — ~50 minutes. Bring your laptop with R and ggplot2 installed. We’ll work through real examples together. If you have a figure from your own research that you’d like to improve, bring it.


Why This Matters

A figure in a published paper is the first thing a reader actually looks at. Before they read the abstract, before they check the methods — they look at the figures. A clear, well-made figure communicates at a glance. A cluttered or confusing figure makes referees skeptical before they’ve read a word.

Most default ggplot2 output is not publication-ready. This session is about closing that gap.


What We’ll Cover

Typography and layout - base_size in themes — stop using the default - element_text() for font control - Axis label sizing and angle - plot.title, plot.subtitle, plot.caption — when to use each

Color - Avoid default ggplot2 colors in publication (they don’t print well in grayscale) - Colorblind-safe palettes: scale_color_brewer(), scale_color_viridis_d() - When to use color vs. shape vs. linetype - Manual palettes: scale_color_manual()

Composing multi-panel figures - patchwork package: p1 + p2, p1 / p2, (p1 | p2) / p3 - Adding panel labels (A, B, C): plot_annotation(tag_levels = "A") - Shared legends: plot_layout(guides = "collect")

Exporting - ggsave() — resolution, dimensions, file format - PDF vs PNG: when to use each - Fonts in exported PDFs (the cairo_pdf device)


Workshop Exercises

# 1. Start with this (bad figure) and make it publication-ready
library(ggplot2)
ggplot(iris, aes(x = Sepal.Length, y = Petal.Length, color = Species)) +
  geom_point()

# 2. Make a two-panel figure with shared color legend
# Panel A: Sepal.Length vs Petal.Length
# Panel B: distribution of Sepal.Length by species
# Hint: install.packages("patchwork")

Key Packages

install.packages(c("ggplot2", "patchwork", "ggrepel", "scales"))
  • patchwork — composing multi-panel layouts
  • ggrepel — non-overlapping text labels (geom_label_repel())
  • scales — axis formatting (comma, percent, scientific)

Resources


Tip

Bring a figure you’ve already made — from your research, from a homework, from anywhere. We’ll spend the last 15 minutes making targeted improvements to real figures from the room.