Learn R Programming

ggsketch (version 2.0.0)

ggsketch_save: Save a sketch plot with a font-aware device

Description

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,
  ...
)

Value

Invisibly, filename.

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().

Details

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

  • .svg -- svglite when installed.

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

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

See Also

Other sketch-theme: CoordSketch, CoordSketchPolar, element_sketch_line(), ggsketch_check_fonts(), register_sketch_font(), scale_pressure_continuous(), scale_roughness_continuous(), scale_sketch, scale_tone_continuous(), sketch_palette(), theme_sketch()

Examples

Run this code
# \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)
# }

Run the code above in your browser using DataLab