First Publication-Ready Figure

EE BIOL C177/C234

Chuliang Song

Today’s Menu 🎯

  1. Choose a good theme
  2. Customize geometry, colors, shapes
  3. Make plots self-contained (labels, titles, legends)
  4. Dealing with legends (position, removal, alternatives)
  5. Use larger annotations
  6. Export for publication (PDF, PNG, SVG)

Themes

Where We Left Off

Choose a Good Theme

Don’t settle for the default grey! Try these:

Other Theme Options

  • jtools::theme_nice() β€” clean and minimalistic
  • theme_minimal() β€” built-in, no gridlines
  • ggthemr β€” collection of themes from GitHub
  • hrbrthemes::theme_ipsum() β€” popular typography-focused
  • hrbrthemes::theme_modern_rc() β€” dark background

Customizing Geometry

Better Point Shapes

Use shape 21 (circle with border) + fill + transparency:

Why Shape 21?

  • Default points overlap into an unrecognizable blob
  • Shape 21 = circle with a border
  • fill = inside color, color = border color
  • White border separates overlapping points
  • alpha adds transparency for dense data

Assign Unique Shapes

Different shapes for black-and-white printing:

Group Boundaries with Ellipses

Custom Colors

Use scale_fill_manual() for precise control:

πŸ’‘ Named Colors are Safer

# ❌ Risky β€” which species gets which color?
scale_fill_manual(
  values = c("#00AFBB", "#E7B800", "#FC4E07")
)

# βœ… Safe β€” explicit assignment
scale_fill_manual(
  values = c(
    "Adelie" = "#00AFBB",
    "Chinstrap" = "#E7B800",
    "Gentoo" = "#FC4E07"
  )
)

🎨 Fun Palettes

Self-Contained Plots

The Goal

  • The reader should understand the plot without reading the text
  • Clear axis labels, informative title, visible legend
  • Trend lines to highlight patterns
  • Every element should earn its place

Add Labels and Titles

Add Trend Lines

Color vs Fill

  • fill = inside of shapes (shape 21–25, bars, areas)
  • color = border/outline of shapes, lines
  • They are separate aesthetics β†’ set them separately!
  • scale_fill_manual() for fill, scale_color_manual() for color

Dealing with Legends

Legend Position: Inside

Coordinates: c(x, y) β€” from 0 (left/bottom) to 1 (right/top)

Legend Position: Top

Also try: "bottom", "left", "right", "none"

Rewriting Legend Titles

Rename all legend aesthetics for a merged legend:

No Legend: Use Facets

No Legend: Text Annotations

No Legend: Colored Subtitle

Use ggtext to embed colored HTML in the subtitle:

Legend Strategy Summary

  • Quick & easy β†’ legend.position = "top" or "bottom"
  • Clean look β†’ position inside plot with c(x, y)
  • No legend needed β†’ facet_wrap() to separate panels
  • Publication polish β†’ annotate("text", ...) or ggtext subtitle
  • Remove title β†’ legend.title = element_blank()

Annotations & Font Size

Use Larger Annotations!

Pay attention to your axis labels. Chances are they are too small. β€” Claus Wilke

Font Size Pitfall

  • Font sizes in ggplot2 are fixed (in points)
  • They do not scale when you resize the plot
  • A font that looks good in RStudio preview may be tiny when exported at 8Γ—6 inches
  • Solution: finalize plot dimensions first, then adjust fonts

The Full Code

The Logic Behind Every ggplot2 Figure

  1. Canvas β†’ ggplot() with data + aesthetics
  2. Geometries β†’ geom_*() layers (points, lines, ellipses)
    • ⚠️ Layer order matters! First layer = bottom
  3. Scales β†’ scale_*() to customize aesthetics
  4. Labels β†’ labs() for axis labels, title, legend titles
  5. Theme β†’ theme_*() + theme() for non-data elements

Exporting Plots

Save as PDF (Best for Papers)

Always specify width and height for reproducibility!

Why Specify Dimensions?

  • RStudio window size varies across computers
  • Figures look distorted without fixed dimensions
  • Font sizes are fixed β†’ don’t scale with plot size
  • Reproducibility = same dimensions every time

Save as PNG

Some journals only accept raster formats:

Use ragg::agg_png for high-fidelity rendering of fonts and details.

Save as SVG β†’ Edit in PowerPoint

  1. Export as .svg (vector format)
  2. Import into PowerPoint/Keynote
  3. Ungroup β†’ edit individual elements
  4. Add annotations, arrows, illustrations
  5. Perfect for conference talks!

Making Transparent Backgrounds

Transparent backgrounds let your plot blend into any slide design!

🎨 Where to Find Illustrations

  • Hire an artist β€” best quality, full customization
  • BioRender β€” popular with biologists (but pricey)
  • NIH BioArt Source β€” free, from NIH
  • Bio Icons β€” free open-source icons
  • AI tools β€” getting good, but use carefully!

Summary

  • Pick a good theme (not the default!)
  • Use shape 21 with fill + transparency
  • Add labels, titles, and trend lines
  • Manage legends: reposition, rename, or remove entirely
  • Make annotations larger
  • Export with fixed dimensions (width, height)
  • Use SVG β†’ PowerPoint for conference talks