Prototype: More Web-Friendly Visualizations in R

June 12, 2010
By

(This article was first published on TechPolicy.ca » R, and kindly contributed to R-bloggers)

I've spent some more time thinking about how best to put together the package for creating web-friendly, interactive data visualizations in R. I have a pretty substantial JavaScript package that does a lot of basic visualizations now, and it's really exciting to see where this is going. With this in mind, I'm releasing a new version of the R package prototype I keep discussing in this blog.

A number of functions are included here, including wv.plot(), wv.lineplot(), wv.snaplot(), wv.bargraph. The documentation still needs a lot of work, and there are no interactive abilities yet (though they exist in the JavaScript code).

What is most exciting about this package is that a lot of the steps one takes to make a complete graph have been split into individual functions. Thus, while one can make a scatterplot with wv.plot(), one can also use wv.axis() and wv.points() to do so as well. Each data visualization gets its own ID, or can be assigned one, so one can later start passing visualization (e.g. the points in the scatterplot itself) as arguments to other functions, thus allowing one to begin adding functions for interactivity.

A few examples of the visualizations are shown below, along with the necessary R code to get them to display. Note that these are embedded into the blog, I did so through the use of an inline frame.

Basic Scatterplot

The code below will generate a basic scatterplot.
x = rnorm(30)
y = rnorm(30)
wv.plot(x, y, "~/Desktop/scatterplot", height=300, width=300, xlim=c(-2.5,2.5), ylim=c(-2.5,2.5), xbreaks=c(0), ybreaks=c(0))



Plot with Multiple Data Types

Supposing you want to have a scatterplot with multiple point types and a line. You can build this manually with the following code.

x = rnorm(30); y = rnorm(30); z = runif(30);
wv.open("~/Desktop/plot3/", height=300, width=300);
wv.axis(c(-3.5, 3.5), c(-3.5, 3.5), xbreaks=-2:2, ybreaks=-2:2);
wv.points(x, y, xlim=c(-3.5, 3.5), ylim=c(-3.5, 3.5));
wv.lines(sort(x), z, col="red", xlim=c(-3.5, 3.5), ylim=c(-3.5, 3.5));
wv.close();



Bar Graph

This is a new graph format.

x = c(2.5, 7, 11);
wv.bargraph(x, cats, "~/Desktop/barplot", ylim=c(0, 15), ybreaks=(1:5)*3);



As always, comments are welcome.

To leave a comment for the author, please follow the link and comment on his blog: TechPolicy.ca » R.

R-bloggers.com offers daily e-mail updates about R news and tutorials on topics such as: visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...



If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Tags: ,

Comments are closed.