SVG in R

January 25, 2009

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()

One Response to “SVG in R”


Leave a Reply