Prototype: Web-Friendly Visualizations in R
Developing web-friendly data visualizations is not very difficult, though as far as I know, a package that allows one to do this directly in R does not exist (e-mail me if you know of one). As someone who has been developing lots of data-oriented software tools, it's always nice to post visualizations online. To facilitate this task, I've been fooling around with creating a data visualization prototype in R. While the package is very limited in what it does, I hope it'll generate a discussion on the types of visualization tools that could help R users post their work on the web.
At this stage, the package has three functions to illustrate scatter plots, line graphs, and social networks. Each function creates a new directory with all the necessary JavaScript and HTML files. The HTML file could then be embedded using an inline frame (as done below) or used as a standalone website.
You can download the prototype here, and below are some examples of visualizations.
Scatter Plot
x = rnorm(25)
y = rnorm(25)
wv.scatterplot(x, y, "/wv-scatterplot", height=300, width=300, marginsize=0.1)
Line Graph
x = -100:100/10
y = sin(x)
wv.lineplot(x, y, "/wv-lineplot", height=300, width=300, marginsize=0.1)
Social Network
library(igraph)
g <- erdos.renyi.game(15, 0.175)
wv.sna(g, "/wv-sna", rnorm(15, 2, 0.75), width=400, height=400)
Next Steps
I apologize in advance, as some of the code above may be buggy and it certainly isn't very customizable. The next step -- assuming there's interest -- is to abstract the graph drawing to individual functions so one can then produce multiple graphs in one canvas or frame. Making more options for interactivity, labels, and so on is also a must. Again, comments and suggestions are very welcome.
May 18th, 2010 - 20:48
Good work! I know a little with R, sometimes I use MATLAB. R is free, doesn’t it?
May 19th, 2010 - 03:05
Hi Wojciech,
Wonderful post and direction!
I will e-mail you now.
May 19th, 2010 - 19:14
Thanks for the comments!
Also, based on the e-mail discussion, to actually embed graphs into the article or another page, I use inline frame. Sample code for one of the graphs above is below:
<center>
<iframe src=”http://www.techpolicy.ca/wp-content/manual/may18/wv-scatterplot/scatterplot.html” width=320 height=320 border=1> Your browser does not support inline frames.</iframe>
</center>
May 20th, 2010 - 14:05
I’m impressed. Certainly a way to combine output on a single sheet would be useful. To me the more important next step is to explore ways to add/change the on-mouse-rollover aspect of the graph, without mucking with the javascript by hand.
Note: there is a CRAN package “webvis” which appears to be similar; how does your package compare?
May 21st, 2010 - 13:11
Adding multiple outputs on one sheet is actually quite easy, but not implemented yet. It’s one of the next steps, after I abstract a lot of the features above so that one can make numerous different types of graphs.
Thanks for letting me know about “webvis”! I haven’t seen it, and I think our work is quite similar.