svg_px | R Documentation |
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()]
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()
)
file |
Identical to |
width |
The width of the plot in pixels. Default |
height |
The height of the plot in pixels. Default |
res |
The resolution at which it is displayed. Default |
bg |
Default background color for the plot (defaults to "white"). |
pointsize |
Default point size. |
standalone |
Produce a standalone svg file? If |
system_fonts |
Consider using
|
user_fonts |
Consider using
|
x |
a ggplot2 object |
A plot device is opened: nothing is returned to the R interpreter
save_svg_px
:
svglite
# 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)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.