interactiveSVG

An R package using ECMAScript interactivity with simple SVG plots. Uses RSVGTipsDevice package to make SVG plots with tooltips.

zoomablePairsSVG() creates pairs plots, in which the subplots can be enlarged to fill the plotting window.

clickableSVG() reads SVG files of simple bar plots or simple scatterplots and assigns values to rect or circle elements. A legend with a total or mean quantity is updated when the bars or points are clicked.

Examples:

zoomablePairsSVG("zoomablePairs.svg", state.x77)
#read in a 2 column csv file
budget <- read.csv("budget.csv")
# make an SVG plot using RSVGTipsDevice
devSVGTips("budget.svg", toolTipMode=0, title="2010 U.S. Budget", width=10, height=12)
par(mar=c(8,28,5,5))
barplot(budget$amount, names.arg = budget$expenditure, horiz=TRUE, las=1, cex.names=0.8, main="2010 U.S. Budget", sub="Mandatory (green), Discretionary (orange), in billion USD", col=c(rep("green", 6),rep("orange", 26)))
dev.off()
# make the rectangles clickable
clickableSVG(file.in="budget.svg", values=as.vector(budget$amount), clickable.element="rect", update="total", text.x=400, text.y=80)
# make some data: get PE ratios, and average every 5 years
pe <- read.csv("pe.csv")
pe <- pe[-1537]
ts <- ts(pe$P.E.Ratio, start=1881, frequency=12)
years <- seq(from=1880, to=2005, by=5)
averages <- sapply(years, function(x) mean(window(ts, x, x+5)))
# make an SVG plot using RSVGTipsDevice
devSVGTips("peratio.svg", height=4, width=6)
barplot(averages, names.arg=years, main="PE Ratios")
dev.off()
# make the rectangles clickable
clickableSVG("peratio.svg", clickable.element="rect", values=averages, update="mean", text.x=60, text.y=60)