An 'SVG' Graphics Device

A graphics device for R that produces 'Scalable Vector Graphics'. 'svglite' is a fork of the older 'RSvgDevice' package.

Build Status Coverage Status CRAN Status Badge

svglite is a graphics device that produces clean svg output, suitable for use on the web, or hand editing. Compared to the built-in svg(), svglite is considerably faster, produces smaller files, and leaves text as is.


Install the development version from github with:

# install.packages("devtools")


Compared to the base svg device, svglite is quite a bit faster:

x <- runif(1e3)
y <- runif(1e3)
tmp1 <- tempfile()
tmp2 <- tempfile()
  plot(x, y)
#>    user  system elapsed 
#>   0.003   0.001   0.003 
  svg(tmp2, onefile = TRUE)
  plot(x, y)
#>    user  system elapsed 
#>   0.015   0.001   0.017 

It also produces considerably smaller files:

file.size(tmp1) / 1024
#> [1] 93.54785
file.size(tmp2) / 1024
#> [1] 321.1357

In both cases, compressing to make .svgz is worthwhile:

gz <- function(in_path, out_path = tempfile()) {
  out <- gzfile(out_path, "w")
  writeLines(readLines(in_path), out)
file.size(gz(tmp1)) / 1024
#> [1] 9.064453
file.size(gz(tmp2)) / 1024
#> [1] 38.6123


svglite 1.2.1

This release makes svglite compatible with gdtools 0.1.6.

svglite 1.2.0

New features

  • The device functions gain system_fonts and user_fonts arguments.

  • Two new vignettes: vignette("fonts") and vignette("scaling"). The vignette on fonts explains in detail how to use the new fonts arguments and why. The vignette on scaling goes over scaling issues, e.g. when embedding svglite outputs in a web page.

  • xmlSVG() gains height and width arguments (#66).

  • New stringSVG() device function for quick testing.


  • Greatly improves the performance of svgstring() (#58).

  • Clip paths now get a unique identifier to avoid collisions when multiple plots are included in a document (#67).

  • Raster graphics are now correctly cropped (#64) and handle transparency properly.

  • The dimensions of text fields are now hardcoded in the SVGs to prevent alignment issues.

Bug fixes

  • editSVG() works again (#56).

  • The dashes in lines with lwd < 1 are scaled better (#68).

  • Transparent blacks are written correctly (#62, #63).

  • Text is now scaled correctly (#72, #59). See also the new vignette on scaling.

svglite 1.1.0

  • Text metrics now converted from points to pixels (#45, #48) - this fixes text alignment issues.

  • Intermediate outputs are always valid SVG (#53).

  • New svgstring() returns plot as a string (#40, @yixuan).

  • Use raster test compatible with older versions of R.

  • Add support for clip(). This also fixes a number of minor issues with grid graphics (@yixuan, #47 and #49).

  • Fix incorrect device size (#50).

svglite 1.0.0

svglite is fully featured svg graphics device that works on all platforms, forked from RSvgDevice. It supports all graphics device features:

  • All types of line dashing are supported (#15). All line end and line join styles are supported (#24).

  • Text is now coloured, and uses the same default fonts as R (Arial, Times New Roman, and Courier). Font metrics are computed using the gdtools package so that plotmath() and strwidth() now work.

  • Transparent colours are now generated with rgba() rather than using stroke-opacity and fill-opacity styles (#16). NA fills and colours are translated to "none".

  • par(bg) affects the background colour (#8).

  • Rasters are supported by embedding base64-encoded pngs in a data url (#2).

  • polypath() is now supported, which also allows the showtext package to render fonts correctly with this device (#36).

We also made a few other tweaks to the rendered SVG:

  • Only the viewBox attribute of <svg> is set (not width and height): I'm reasonably certain this makes it easier to use in more places (#12).

  • Default styling properties are specified in a global <style> element: this reduces overall file size, and should make it easier to re-style the output for your own needs.

  • You can now only produce a single page per device - previously this worked but produced incorrect output (#5).

  • Output no longer contains dummy <desc> element (#4)

And added some helper functions:

  • xmlSVG() and htmlSVG() make it easier to view generated SVG, either as raw XML or in RStudio/the browser.

  • editSVG() opens the SVG in the default SVG viewer/editor.

Reference manual

It appears you don't have a PDF plugin for this browser. You can click here to download the reference manual.


2.0.0 by Thomas Lin Pedersen, a year ago,

Report a bug at

Browse source code at

Authors: Hadley Wickham [aut] , Lionel Henry [aut] , Thomas Lin Pedersen [cre, aut] , T Jake Luciani [aut] , Matthieu Decorde [aut] , Vaudor Lise [aut] , Tony Plate [ctb] (Early line dashing code) , David Gohel [ctb] (Line dashing code and early raster code) , Yixuan Qiu [ctb] (Improved styles; polypath implementation) , Håkon Malmedal [ctb] (Opacity code) , RStudio [cph]

Documentation:   PDF Manual  

GPL (>= 2) license

Imports systemfonts

Suggests htmltools, testthat, xml2, covr, fontquiver, knitr, rmarkdown

Linking to cpp11, systemfonts

System requirements: C++11, libpng

Imported by BioVenn, InflectSSP, LLSR, WebGestaltR, actel, guiplot, kableExtra, leafpop, modelDown, netSEM, shinyloadtest, visvow.

Suggested by DeLorean, animint2, brokenstick, concurve, ggExtra, gganimate, ggdist, ggplot2, hrbrthemes, meditate, mlr, nmaplateplot, opencpu, pkgndep, projections,, rcmdcheck, rsvg, slackr, slickR, svgPanZoom, thematic, tidybayes, viridis.

See at CRAN