svglite 1.0.0

[This article was first published on RStudio Blog, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

I’m pleased to announced a new package for producing SVGs from R: svglite. This package is a fork of Matthieu Decorde RSvgDevice and wouldn’t be possible without his hard work. I’d also like to thank David Gohel who wrote the gdtools package: it solves all the hardest problems associated with making good SVGs from R.

Today, most browsers have good support for SVG and it is a great way of displaying vector graphics on the web. Unfortunately, R’s built-in svg() device is focussed on high quality rendering, not size or speed. It renders text as individual polygons: this ensures a graphic will look exactly the same regardless of what fonts you have installed, but makes output considerably larger (and harder to edit in other tools). svglite produces hand-optimised SVG that is as small as possible.

Features

svglite is a complete graphics device: that means you can give it any graphic and it will look the same as the equivalent .pdf or .png. Please file an issue if you discover a plot that doesn’t look right.

Use

In an interactive session, you use it like any other R graphics device:

svglite::svglite("myfile.svg")
plot(runif(10), runif(10))
dev.off()

If you want to use it in knitr, just set your chunk options as follows:

```{r setup, include = FALSE}
library(svglite)
knitr::opts_chunk$set(
  dev = "svglite",
  fig.ext = ".svg"
)

(Thanks to Bob Rudis for the tip)

There are also a few helper functions:

  • htmlSVG() makes it easy to preview the SVG in RStudio.
  • editSVG() opens the SVG file in your default SVG editor.
  • xmlSVG() returns the SVG as an xml2 object.

To leave a comment for the author, please follow the link and comment on their blog: RStudio Blog.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)