The 'rsvg' Package: High Quality Image Rendering in R
January 25, 2016
The new rsvg package renders (vector based) SVG images into high-quality bitmap arrays. The resulting image is an array of 3 dimensions: height * width * 4 (RGBA) and can be written to png, jpeg or webp format:
The advantage of storing your plots in svg format is they can be rendered later into an arbitrary resolution and format without loss of quality! Each rendering fucntion takes a
height parameter. When neither width or height is set bitmap resolution matches that of the input svg. When either width or height is specified, the image is scaled proportionally. When both width and height are specified, the image is stretched into the requested size. For example suppose we need to render the plot into ultra HD so that it is crisp as toast when printed a conference poster:
Rather than actually dealing with the bitmap array in R, rsvg also allows you to directly render the image to various output formats, which is slighly faster.
Added bonus is that librsvg does not only do a really good job rendering, it is also super fast. It would even be fast enough to render the svg tiger on the fly at 10~20fps!
webp format is the new high-quality image format by Google which I will talk about in another post.