Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can R create a barplot image with clickable bars to insert on a webpage?

Tags:

r

I know how to create a barplot, and how to stick it on a webpage; e.g, using hwriteImage in the hwriter package.

What I'd like is for each bar to be a region which highlights on mouseover, and where each bar has a different link when clicked. Similar to this map of the U.S. using the jQuery maphilight plugin, but for a barplot rather than a map. I imagine R could calculate the coordinates of the regions around each bar, generate the HTML AREA tag etc and pass this to maphilight quite easily. Has it been done already? I searched but no luck so far.

like image 868
Matt Dowle Avatar asked Feb 17 '12 00:02

Matt Dowle


1 Answers

Have a look here, which summarises a couple of methods: rggobi and iplots. rggobi looks pretty promising, though maybe the installation looks a bit involved. iplots is only good for scatter plots.

Some other options (I think these are strongest ones at the moment):

googleVis

The googleVis package interfaces with the google charts API: try demo(googleVis) and the third & fourth one are bar chart (there could be more). It has the advantage of being pretty simple to get started with, although these are not R graphics:

df=data.frame(country=c("US", "GB", "BR"), val1=c(10,13,14), val2=c(23,12,32))
Column <- gvisColumnChart(df)
plot(Column)

gridSVG

The gridSVG exports the current grid graphics to an .svg file that can be included into a webpage. Unlike googleVis, it's R graphics (so you can use grid/ggplot2 which are more familiar). It looks like you may have to know some Javascript to further embellish your plots though (e.g. to animate on mouse over, you use grid.garnish(...,onmouseover=...)).

There's some example code you can try here (The really awesome ones are here - usually clicking on the "SVG file" link will have the full interactivity/animation.) (This one is a scatterplot where the points highlight when you move your mouse over them).

As I said - have a look at the package pages, demos, examples, etc to see which suits you.

like image 181
mathematical.coffee Avatar answered Sep 17 '22 11:09

mathematical.coffee