/research-core:figure-exportfrom research-core
Exports publication-quality R figures (PDF/PNG/SVG) with proper font embedding and Inkscape-editable SVG. Covers ggsave, cairo_pdf, svglite, DPI, and dimensions for manuscripts.
Ships in research-core. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
Best practices for saving R figures as PDF, PNG, and SVG so they are high quality and editable in Inkscape.
Preliminary/exploratory plots may use PNG alone. The figure-producing run retained for phase-final review must export PNG, PDF and SVG at explicit dimensions, before any separate publication-code decision. Preserve project-reviewed styling; do not restyle accepted figures to match an example. For each retained figure, inspect the actual exports and discuss what it shows and any anomaly.
# PDF — use cairo_pdf to embed fonts properly (handles Arial, Helvetica, etc.)
ggsave("plot.pdf", plot = p, width = 6.8, height = 5.5, device = cairo_pdf)
# PNG — always 300 dpi
ggsave("plot.png", plot = p, width = 6.8, height = 5.5, dpi = 300)
# SVG — use svglite with fix_text_size = FALSE
ggsave("plot.svg", plot = p, width = 6.8, height = 5.5,
device = function(...) svglite::svglite(..., fix_text_size = FALSE))
Critical: svglite defaults to fix_text_size = TRUE, which adds textLength and lengthAdjust attributes to every <text> element. These lock the text width and prevent editing in Inkscape. Always set fix_text_size = FALSE.
This applies everywhere svglite is used:
# Via ggsave (ggplot2 plots)
ggsave(..., device = function(...) svglite::svglite(..., fix_text_size = FALSE))
# Via direct device call (pheatmap, base R graphics)
svglite::svglite("plot.svg", width = w, height = h, fix_text_size = FALSE)
grid::grid.newpage()
grid::grid.draw(p$gtable)
dev.off()
Do NOT use base R svg() or Cairo SVG — they produce bloated SVGs with many style attributes per element and can crash Inkscape with large plots.
Use cairo_pdf instead of the default pdf() device. The default PDF device may fail for fonts outside its configured PDF font families (e.g., Arial), with "failed to find or load PDF CID font". cairo_pdf supports font embedding; inspect the exported PDF's font properties when this matters.
# CORRECT
ggsave("plot.pdf", plot = p, device = cairo_pdf)
# May fail with Arial or other fonts not configured for the default PDF device
ggsave("plot.pdf", plot = p) # uses default pdf() device
Keep the project's reviewed font consistent across elements. Arial is one available example, not a reason to replace an accepted project style:
# In theme
theme_paper <- function(base_size = 12, base_family = "Arial") {
theme_bw(base_size = base_size, base_family = base_family) + ...
}
# In geom_text_repel and other text geoms
geom_text_repel(..., family = "Arial")
For plots with thousands of points (volcano plots, MA plots, scatter plots), rasterize the background points to prevent SVG bloat and Inkscape crashes. Keep foreground points and text as vectors for editability.
library(ggrastr)
ggplot() +
# Background points — rasterized (becomes single <image> in SVG)
rasterise(geom_point(
data = df_background,
aes(x = x, y = y),
colour = "grey70", alpha = 0.35, size = 0.9
), dpi = 1200) +
# Foreground points — vector (stays editable)
geom_point(
data = df_foreground,
aes(x = x, y = y, colour = group),
size = 1.2
) +
# Text labels — vector (stays editable)
geom_text_repel(...)
DPI for rasterized layers: Use 1200 dpi for publication quality. 300 dpi is sufficient for drafts.
ggrastr only works with ggplot2. For pheatmap or base R graphics, the cells are drawn as simple <rect> elements which are lightweight — rasterization is not needed.
When plots will be assembled into multi-panel figures, use identical width and height across all plots of the same type. This ensures the plotting windows align without rescaling in Inkscape.
# Define once, use everywhere
VOLCANO_WIDTH <- 6.8
VOLCANO_HEIGHT <- 5.5
ggsave_safe(..., width = VOLCANO_WIDTH, height = VOLCANO_HEIGHT)
Different axis limits or thresholds are fine — the key is that the outer plot dimensions match so panels can be tiled.
A helper that saves all 3 formats from a single call:
ggsave_safe <- function(filename, plot, width, height, units = "in", limitsize = TRUE, ...) {
# Accept a stem or a known format suffix (case-insensitive); keep other suffixes in the stem.
stem <- sub("\\.(pdf|png|svg)$", "", filename, ignore.case = TRUE)
# Preserve requested dimensions/units. ggplot2's physical-size check stays enabled unless
# the caller explicitly chooses limitsize = FALSE for a deliberately large figure.
# PDF
ggplot2::ggsave(paste0(stem, ".pdf"), plot = plot, width = width, height = height,
units = units, device = grDevices::cairo_pdf, limitsize = limitsize, ...)
# PNG
ggplot2::ggsave(paste0(stem, ".png"), plot = plot,
width = width, height = height, units = units,
dpi = 300, limitsize = limitsize, ...)
# SVG
ggplot2::ggsave(paste0(stem, ".svg"), plot = plot,
width = width, height = height, units = units,
device = function(...) svglite::svglite(..., fix_text_size = FALSE),
limitsize = limitsize, ...)
}
Use a fresh or explicitly disposable output destination; this helper does not establish overwrite permission.
library(ggrastr) # rasterise() for dense point layers
library(svglite) # clean SVG output
# cairo_pdf is built into grDevices (no extra package needed)
What SKILL.md sets; muted values are Claude Code's defaults
Other plugins' skills for the same job
25 skills in this plugin
/analysis-distillationDistill exploratory or complex scientific analysis into the smallest readable workflow that supports a phase review, paper, report, or durable handoff. Use when a settled phase result needs consolidation, or selected results need publication-ready code, a newcomer reproduction route, or a maintained analysis path. Do not use to choose an unresolved scientific method, perform ordinary session cleanup, or rewrite a working pipeline merely to impose a preferred structure.
/analysis-review-dashboardBuild or refresh a browser dashboard for independently reviewing a scientific analysis, from a short workflow to a branching pipeline. Organize existing evidence into a pipeline overview, scientific task pages and complete script reviews with file and object previews. Use when the user asks for an analysis review dashboard or linked pipeline/task/script pages. Do not use for a task-status dashboard, source-code distillation alone, or a script audit alone.
/audit-projectReview project documentation, authority, navigation and workflow drift; propose careful, reversible consolidation when useful. Use for project health or documentation reconciliation, not script correctness (audit-script) or skill quality (a separate maintainer audit; use plugin-feedback for a student plugin report).
npx claudepluginhub musserlab/lab-claude-skills --plugin research-core