Skip to contents

A drop-in ggplot2::ggsave() wrapper that picks a device which can see fonts registered with register_sketch_font() / systemfonts:

Usage

ggsketch_save(
  filename,
  plot = ggplot2::last_plot(),
  width = 8,
  height = 5,
  dpi = 300,
  device = NULL,
  ...
)

Arguments

filename

File to write; the extension picks the device.

plot

Plot to save. Default ggplot2::last_plot().

width, height

Size in inches. Defaults 8 x 5.

dpi

Resolution for raster formats. Default 300.

device

Override the chosen device (a function or name); passed through to ggplot2::ggsave() untouched when supplied.

...

Other arguments passed on to ggplot2::ggsave().

Value

Invisibly, filename.

Details

  • .png / .jpeg / .jpg / .tiffragg when installed (falls back to the ggsave default with a hint).

  • .svgsvglite when installed.

  • .pdfcairo_pdf (embeds registered fonts; the base pdf device does not).

  • .eps / .pscairo_ps, with a warning: PostScript cannot embed handwriting faces reliably, so prefer PDF.

Examples

# \donttest{
library(ggplot2)
p <- ggplot(mtcars, aes(wt, mpg)) + geom_sketch_point(seed = 1L) +
  theme_sketch()
out <- file.path(tempdir(), "sketch.png")
ggsketch_save(out, p)
unlink(out)
# }