moplot_export: Export a MoPlot figure using publication-ready settings

View source: R/moplot_export.R

moplot_exportR Documentation

Export a MoPlot figure using publication-ready settings

Description

moplot_export() exports a plot created by moplot_onepred() or moplot_multpred() using dimensions recommended from the graphical complexity of the plot: the number of displayed quantities (or of polynomial components and levels), the depth of the interaction hierarchy, and the presence of the coefficient panel.

PNG and TIFF files are exported at high resolution. TIFF files use lossless LZW compression. PDF files are exported through the Cairo device to improve rendering of Unicode symbols used in MoPlot figures.

Usage

moplot_export(
  plot,
  filename,
  width = NULL,
  height = NULL,
  dpi = 600,
  bg = "white"
)

Arguments

plot

A plot object created by moplot_onepred() or moplot_multpred(). Other plots can be exported by supplying both width and height.

filename

Character string specifying the output filename. Supported extensions are .png, .tif, .tiff, and .pdf.

width

Optional export width in inches. If NULL, the recommended width stored in plot is used.

height

Optional export height in inches. If NULL, the recommended height stored in plot is used.

dpi

Resolution in dots per inch for raster formats. The default is 600. This argument is ignored for PDF output.

bg

Background colour. The default is "white".

Value

Invisibly returns the normalized path of the exported file.

Examples

set.seed(123)

dat <- data.frame(
  group = factor(rep(c("A", "B", "C"), each = 20)),
  y = rnorm(60, mean = rep(c(0, 0.4, 0.9), each = 20))
)

contrasts(dat$group) <- contr.helmert(3)

plot <- moplot_onepred(
  model = lm(y ~ group, data = dat),
  predictor = "group",
  caption = FALSE
)

# Recommended dimensions, stored in the plot.
attr(plot, "moplot_export_size")

path <- moplot_export(
  plot,
  filename = file.path(tempdir(), "moplot.png"),
  dpi = 150
)

file.exists(path)
unlink(path)


MoPlot documentation built on Nov. 25, 2026, 5:10 p.m.