SVG in R

I just heard about a really convenient package, RSVGTipsDevice, for making SVG graphics from R.  It allows for tooltips (text that shows up when you hover over a point) and URLs to be associated with points/regions.  You open a device, plot some things, and call setSVGShapeToolTip() immediately before the points or regions you want to have tooltips.

Here’s some sample code which would make a basic scatterplot with five labelled points.

library(RSVGTipsDevice)
devSVGTips("plot.svg", toolTipMode=1, title="SVG title")
x <- runif(5)
y <- runif(5)
z <- runif(5, 2, 7)
names <- rep(c("one","two","three","four","five"))
plot(c(0,1), c(0,1), type="n", xlab="x", ylab="y", main="Plot title")
invisible(sapply(1:5, function(i) {
setSVGShapeToolTip(title=paste("point", names[i]))
points(x[i], y[i], cex=z[i], pch=1, col='black')}))
dev.off()

Advertisements

3 thoughts on “SVG in R”

  1. Hello Mike,

    I would like to know if you are the developer of this SVG library for R. Because I´m trying to generate some charts with it but I need to customize them to do not convert text to paths, and make them scalable to browser resolutions.
    Thank you.
    Douglas

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s