Title: | An 'SVG' Graphics Device |
Version: | 2.2.1 |
Description: | A graphics device for R that produces 'Scalable Vector Graphics'. 'svglite' is a fork of the older 'RSvgDevice' package. |
License: | GPL-2 | GPL-3 [expanded from: GPL (≥ 2)] |
URL: | https://svglite.r-lib.org, https://github.com/r-lib/svglite |
BugReports: | https://github.com/r-lib/svglite/issues |
Depends: | R (≥ 4.1) |
Imports: | base64enc, cli, lifecycle, rlang (≥ 1.1.0), systemfonts (≥ 1.2.3), textshaping (≥ 0.3.0) |
Suggests: | covr, fontquiver (≥ 0.2.0), htmltools, knitr, rmarkdown, testthat (≥ 3.0.0), xml2 (≥ 1.0.0) |
LinkingTo: | cpp11, systemfonts, textshaping |
VignetteBuilder: | knitr |
Config/build/compilation-database: | true |
Config/Needs/website: | tidyverse/tidytemplate |
Config/testthat/edition: | 3 |
Config/usethis/last-upkeep: | 2025-04-25 |
Encoding: | UTF-8 |
RoxygenNote: | 7.3.2 |
SystemRequirements: | libpng |
NeedsCompilation: | yes |
Packaged: | 2025-05-12 14:44:20 UTC; thomas |
Author: | Hadley Wickham [aut],
Lionel Henry [aut],
Thomas Lin Pedersen
|
Maintainer: | Thomas Lin Pedersen <thomas.pedersen@posit.co> |
Repository: | CRAN |
Date/Publication: | 2025-05-12 18:50:02 UTC |
svglite: An 'SVG' Graphics Device
Description
A graphics device for R that produces 'Scalable Vector Graphics'. 'svglite' is a fork of the older 'RSvgDevice' package.
Author(s)
Maintainer: Thomas Lin Pedersen thomas.pedersen@posit.co (ORCID)
Authors:
Hadley Wickham hadley@posit.co
Lionel Henry lionel@posit.co
T Jake Luciani jake@apache.org
Matthieu Decorde matthieu.decorde@ens-lyon.fr
Vaudor Lise lise.vaudor@ens-lyon.fr
Other contributors:
Tony Plate (Early line dashing code) [contributor]
David Gohel (Line dashing code and early raster code) [contributor]
Yixuan Qiu (Improved styles; polypath implementation) [contributor]
Håkon Malmedal (Opacity code) [contributor]
Posit Software, PBC (03wc8by49) [copyright holder, funder]
See Also
Useful links:
Report bugs at https://github.com/r-lib/svglite/issues
Add web font imports to an already created SVG file
Description
This function allows you to add web fonts after creation. The result is the
same as using the web_fonts
argument in svglite()
. Only SVGs created with
svglite can get web fonts added.
Usage
add_web_fonts(filename, web_fonts)
Arguments
filename |
The svgfile(s) or |
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 |
Value
Invisibly returns filename
. If any of elements of this were inline
SVGs then these have been modified to include the imports
Convert an svg file to svgz, overwriting the old file
Description
Convert an svg file to svgz, overwriting the old file
Usage
create_svgz(file)
Arguments
file |
the path to the file to convert |
Run plotting code and open svg in OS/system default svg viewer or editor.
Description
This is useful primarily for testing or post-processing the SVG.
Usage
editSVG(code, ..., width = NA, height = NA)
Arguments
code |
Plotting code to execute. |
... |
Other arguments passed on to |
height , width |
Height and width in inches. |
Examples
if (interactive()) {
editSVG(plot(1:10))
editSVG(contour(volcano))
}
Create a font-face specification
Description
Webfonts in SVG and HTML can either be specified manually using the
@font-face
at-rule, or imported from e.g. Google Fonts using the @import
at-rule. font_face()
helps you create a valid @font-face
block for the
web_fonts
argument in svglite()
and svgstring()
functions.
Usage
font_face(
family,
woff2 = NULL,
woff = NULL,
ttf = NULL,
otf = NULL,
eot = deprecated(),
svg = deprecated(),
local = NULL,
weight = NULL,
style = NULL,
range = NULL,
variant = NULL,
stretch = NULL,
feature_setting = NULL,
variation_setting = NULL,
embed = FALSE
)
Arguments
family |
The font family name this font should respond to. |
woff2 , woff , ttf , otf |
URLs to the font in different formats. At least one must be given. Best browser support is provided by the woff format. |
eot , svg |
|
local |
One or more font names that local installations of the font may have. If a local font is found with either of the given names it will be used and no download will happen. |
weight |
An optional value for the |
style |
An optional value for the |
range |
An optional value for the |
variant |
An optional value for the |
stretch |
An optional value for the |
feature_setting |
An optional value for the |
variation_setting |
An optional value for the |
embed |
Should the font data be embedded directly in the SVG |
Value
A character string with the @font-face
block.
Examples
font_face(
family = "MyHelvetica",
ttf = "MgOpenModernaBold.ttf",
local = c("Helvetica Neue Bold", "HelveticaNeue-Bold"),
weight = "bold"
)
Run plotting code and view svg in RStudio Viewer or web browser.
Description
This is useful primarily for testing. Requires the htmltools
package.
Usage
htmlSVG(code, ...)
Arguments
code |
Plotting code to execute. |
... |
Other arguments passed on to |
Examples
if (interactive() && require("htmltools")) {
htmlSVG(plot(1:10))
htmlSVG(hist(rnorm(100)))
}
Objects exported from other packages
Description
These objects are imported from other packages. Follow the links below to see their documentation.
- systemfonts
add_fonts
,font_feature
,fonts_as_import
,register_font
,register_variant
,require_font
Run plotting code and return svg as string
Description
This is useful primarily for testing but can be used as an
alternative to svgstring()
.
Usage
stringSVG(code, ...)
Arguments
code |
Plotting code to execute. |
... |
Other arguments passed on to |
Examples
stringSVG(plot(1:10))
An SVG Graphics Driver
Description
This function produces graphics compliant to the current w3 svg XML standard. The driver output is currently NOT specifying a DOCTYPE DTD.
Usage
svglite(
filename = "Rplot%03d.svg",
width = 10,
height = 8,
bg = "white",
pointsize = 12,
standalone = TRUE,
web_fonts = list(),
id = NULL,
fix_text_size = TRUE,
scaling = 1,
always_valid = FALSE,
file,
system_fonts = list(),
user_fonts = list()
)
Arguments
filename |
The file where output will appear. |
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 |
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 |
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
|
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. |
always_valid |
Should the svgfile be a valid svg file while it is being
written to? Setting this to |
file |
Identical to |
system_fonts |
|
user_fonts |
|
Details
svglite provides two ways of controlling fonts: system fonts
aliases and user fonts aliases. Supplying a font alias has two
effects. First it determines the font-family
property of all
text anchors in the SVG output. Secondly, the font is used to
determine the dimensions of graphical elements and has thus an
influence on the overall aspect of the plots. This means that for
optimal display, the font must be available on both the computer
used to create the svg, and the computer used to render the
svg. See the fonts
vignette for more information.
Author(s)
This driver was written by T Jake Luciani jakeluciani@yahoo.com 2012: updated by Matthieu Decorde matthieu.decorde@ens-lyon.fr
References
W3C Scalable Vector Graphics (SVG): https://www.w3.org/Graphics/SVG/
See Also
Examples
# Save to file
svglite(tempfile("Rplots.svg"))
plot(1:11, (-5:5)^2, type = "b", main = "Simple Example")
dev.off()
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,
web_fonts = list(),
id = NULL,
fix_text_size = TRUE,
scaling = 1,
system_fonts = list(),
user_fonts = list()
)
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 |
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 |
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
|
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. |
system_fonts |
|
user_fonts |
|
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()
Run plotting code and return svg
Description
This is useful primarily for testing. Requires the xml2
package.
Usage
xmlSVG(code, ..., standalone = FALSE, height = 7, width = 7)
Arguments
code |
Plotting code to execute. |
... |
Other arguments passed on to |
standalone |
Produce a standalone svg file? If |
height , width |
Height and width in inches. |
Value
A xml2::xml_document
object.
Examples
if (require("xml2")) {
x <- xmlSVG(plot(1, axes = FALSE))
x
xml_find_all(x, ".//text")
}