svg_px: Create svg for the web, specifying size in pixels

View source: R/plot_devices.R

svg_pxR Documentation

Create svg for the web, specifying size in pixels

Description

This is a thin wrapper around svglite for creating images for the web in svg format, but enables you specify the size in pixels, which is more useful for web work. Internally, it simply converts the width and height to inches at the resolution specified.

'save_svg_px' is a wrapper function around 'svg_px' analagous to [ggplot2::gsave()]

Usage

svg_px(
  file = "Rplots.svg",
  width = 800,
  height = 800,
  res = 72,
  bg = "white",
  pointsize = 12,
  standalone = TRUE,
  system_fonts = list(),
  user_fonts = list()
)

save_svg_px(
  x,
  file = "Rplots.svg",
  width = 800,
  height = 800,
  res = 72,
  bg = "white",
  pointsize = 12,
  standalone = TRUE,
  system_fonts = list(),
  user_fonts = list()
)

Arguments

file

Identical to filename. Provided for backward compatibility.

width

The width of the plot in pixels. Default 800.

height

The height of the plot in pixels. Default 800.

res

The resolution at which it is displayed. Default 72. You should rarely have to change this.

bg

Default background color for the plot (defaults to "white").

pointsize

Default point size.

standalone

Produce a standalone svg file? If FALSE, omits xml header and default namespace.

system_fonts

Consider using systemfonts::register_font() instead. Named list of font names to be aliased with fonts installed on your system. If unspecified, the R default families sans, serif, mono and symbol are aliased to the family returned by font_info().

user_fonts

Consider using systemfonts::register_font() instead. Named list of fonts to be aliased with font files provided by the user rather than fonts properly installed on the system. The aliases can be fonts from the fontquiver package, strings containing a path to a font file, or a list containing name and file elements with name indicating the font alias in the SVG output and file the path to a font file.

x

a ggplot2 object

Value

A plot device is opened: nothing is returned to the R interpreter

Functions

  • save_svg_px:

See Also

svglite

Examples


# You want to display at 500 * 500 in the web:
svg_px("myplot.png", width = 500, height = 500)
plot(x = 1:500, y = rnorm(500))
dev.off()
if (suppressPackageStartupMessages(require("ggplot2", quietly = TRUE))) {
p <- ggplot(mtcars, aes(x = cyl, y = mpg)) + geom_point()
file <- tempfile(fileext = ".svg")
save_svg_px(p, file)
}

bcgov/envreportutils documentation built on Feb. 1, 2024, 8:48 p.m.