ggplot2 is the R reference for publication-quality static graphics, based on Wilkinson's grammar of graphics. A figure is composed as data + aesthetic mappings + one or more geometries + scales + facets + theme. The modern defaults for publication are theme_classic + panel.grid.off + Okabe-Ito categorical palette + cairo_pdf TrueType-embedded export.
install.packages(c('ggplot2', 'scales', 'ggrepel', 'ggtext', 'viridis', 'scico', 'ggrastr'))
Tell your AI agent what you want to do: - "Build a scatter with theme_classic, no grid, Okabe-Ito colors" - "Faceted boxplot per tissue with free y-axis" - "Add log10 transform to the y-axis with formatted breaks" - "Programmatic plot from variable name passed as a string" - "Save as 89mm cairo_pdf for Nature submission"
"ggplot2 scatter with theme_classic baseline. Color by group using Okabe-Ito (#0072B2/#D55E00). Top/right spines removed. Save as 89mm cairo_pdf."
"Faceted boxplot of expression per tissue with overlaid jitter. Suppress boxplot outliers because jitter shows all points. Use Sheather-Jones bandwidth on violins."
"Build a plotting function that accepts the x-axis variable as a string and uses tidy evaluation (
aes(x = .data[[var]])) rather than deprecated aes_string."
"Use ggtext to render axis title 'log2 fold change' with proper subscripts and italics."
"Wrap geom_point in ggrastr::rasterise so 50000 points export as raster while axes stay vector."
aes() mappings.scales = 'fixed' unless free is justified.theme_classic + panel grid removed + black axis/tick lines.labs(); rich text via ggtext if needed.ggsave(..., device = cairo_pdf, units = 'mm') at journal-spec width (89 or 183).Use theme_classic + panel.grid = element_blank() as publication baseline. Remove top/right axis lines if Nature style: theme(axis.line = element_line()).
device = cairo_pdf for TrueType embedding. Default ggsave can produce non-embedded fonts; journals reject.
linewidth replaces size for lines in ggplot2 3.4+. size still works for points.
aes_string is deprecated. Use aes(x = .data[[var]]) for programmatic plots in ggplot2 3.0+.
Constants outside aes, mappings inside. geom_point(color = 'red') for constant; geom_point(aes(color = group)) for mapping. aes(color = 'red') makes 'red' a 1-level category.
max.overlaps = Inf on ggrepel - default 10 silently drops labels.
outlier.shape = NA on boxplot when jittering raw points; otherwise outliers render twice.
facet_wrap(scales = 'fixed') for cross-panel comparison (default). Use 'free_y' only when scales legitimately differ.
units = 'mm' explicit on ggsave. Default is inches; Nature single column = 89 mm; double = 183 mm.
ggrastr::rasterise(geom_point(...)) for large N - vector axes + raster scatter is the publication compromise.
ggtext::element_markdown() enables HTML in axis titles for subscripts and italics - much cleaner than expression().