svglite 1.0.0

December 10, 2015
By

(This article was first published on RStudio Blog, and kindly contributed to R-bloggers)

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 on topics such as: Data science, Big Data, R jobs, visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...



If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Comments are closed.

Sponsors

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)