svgstring: Access current SVG as a string.

View source: R/SVG.R

svgstringR Documentation

Access current SVG as a string.

Description

This is a variation on svglite that makes it easy to access the current value as a string.

Usage

svgstring(
  width = 10,
  height = 8,
  bg = "white",
  pointsize = 12,
  standalone = TRUE,
  system_fonts = list(),
  user_fonts = list(),
  web_fonts = list(),
  id = NULL,
  fix_text_size = TRUE,
  scaling = 1
)

Arguments

height, width

Height and width in inches.

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

[Superseded] 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

[Superseded] 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.

web_fonts

A list containing web fonts to use in the SVG. The fonts will still need to be available locally on the computer running the code, but viewers of the final SVG will not need the font if specified as a web font. Web fonts can either be specified using font_face() or given as a single string in which case they are taken to be URL's for an ⁠@import⁠ directive to e.g. Google Fonts.

id

A character vector of ids to assign to the generated SVG's. If creating more SVG files than supplied ids the exceeding SVG's will not have an id tag and a warning will be thrown.

fix_text_size

Should the width of strings be fixed so that it doesn't change between svg renderers depending on their font rendering? Defaults to TRUE. If TRUE each string will have the textLength CSS property set to the width calculated by systemfonts and lengthAdjust='spacingAndGlyphs'. Setting this to FALSE can be beneficial for heavy post-processing that may change content or style of strings, but may lead to inconsistencies between strings and graphic elements that depend on the dimensions of the string (e.g. label borders and background).

scaling

A scaling factor to apply to the rendered line width and text size. Useful for getting the right sizing at the dimension that you need.

Details

See svglite() documentation for information about specifying fonts.

Value

A function with no arguments: call the function to get the current value of the string.

Examples

s <- svgstring()
s()

plot.new()
s()
text(0.5, 0.5, "Hi!")
s()
dev.off()

s <- svgstring()
plot(rnorm(5), rnorm(5))
s()
dev.off()

svglite documentation built on June 22, 2024, 6:46 p.m.