| Sun | Mon | Tue | Wed | Thu | Fri | Sat |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | ||||
| 4 | 5 | 6 | 7 | 8 | 9 | 10 |
| 11 | 12 | 13 | 14 | 15 | 16 | 17 |
| 18 | 19 | 20 | 21 | 22 | 23 | 24 |
| 25 | 26 | 27 | 28 | 29 | 30 | 31 |
« Simulating Major League Baseball | Main | A born-again frequentist? »
2 April 2008
Late last year Google released the Google Chart API, which gives programmers access to a web service that renders charts. So this url
http://chart.apis.google.com/chart?cht=p3&chd=t:60,40&chs=250x100&chl=Hello|World
will produce a chart like this:
Try it yourself -- copy the url into your browser; change the text from "Hello World" to something else, etc. And the API supports bar plots, line charts, Venn diagrams (!) and even, recently, maps.
People have written libraries in various languages to provide interfaces to the API (here's a list of them), and tonight I hacked together a little R interface to the scatterplot charts. It's quite rough, but I'd be curious if anyone wants to extend it or can show anything cool with it.
From R, all you have to do is:
> source("http://people.fas.harvard.edu/~aeggers/code/googleplot.r")
And then where you might say
> plot(1:9, c(4,2,4,3,6,4,7,8,5), cex = 1:9, xlim = c(0, 10), ylim = c(1,10))
you can use the same syntax with the googleplot function
> googleplot(1:9, c(4,2,4,3,6,4,7,8,5), cex = 1:9, xlim = c(0, 10), ylim = c(1,10))
and get back a long url encoding those parameters
"http://chart.apis.google.com/chart?cht=s&chd=s:GMSYekqw2,SGSMeSkqY,
GNUbhov29&chxt=x,y&chxl=0:|0|2|5|7|10|1:|1|3|5|7|10&chs=250x200"
which, when entered into an address bar or embedded in an img tag in a web page, gives you a figure like this:
It seems like this approach could provide a convenient way to publish a figure on the web in some circumstances, but setting aside the insufficiency of my R function, the graphics flexibility of the API isn't quite large enough yet (eg can't pass an axis label, ie xlab in R). In most cases it seems like you'd just want to create a nice PNG in R or whatever and then publish that. But I'd love to hear if anyone finds a way to use this or thinks it'is worth extending further.
Posted by Andy Eggers at April 2, 2008 1:07 AM
This looks very cool.
Is there any way to get it to download the image into R? Or is that asking too much!
Posted by: Andy
at April 2, 2008 6:23 AM
that's really a fantastic post ! ! added to my favourite blogs list..
Posted by: Beauty articles at April 2, 2008 7:47 AM
This is awesome! Thanks.
Now instead of sending an e-mail with an attached PNG file you can just paste a link to, say, MSN chat so that the other person can see the picture :)
Posted by: michal at April 2, 2008 9:01 AM
This is great!
Posted by: dominik at April 2, 2008 9:12 AM
true eggerism! fascinating.
Posted by: Jens at April 2, 2008 9:26 AM
I'm glad people are in interested in this. Andy -- yes, I think you could write this in a way that would download the PNG directly by using R to send a request to the generated URL and then saving the result. I believe a bunch of the libraries (python, ruby, etc) do this. I will not be able to look into this soon but maybe someone else can.
Posted by: Andy Eggers
at April 2, 2008 9:35 AM
You should be able to add axis labels... http://code.google.com/apis/chart/#axes_labels
Posted by: pushmedia1 at April 4, 2008 4:20 AM
I can't believe the things you can "google" these days. My friends and I who have been out of high school for almost 10 years now,
Posted by: jordan shoes at April 8, 2008 2:29 AM
Great Post, Thanks for the information.
Posted by: Martin Hall at April 11, 2008 3:43 AM
That's really cool. Thanks for posting.
Posted by: Professional Translators at April 17, 2008 4:05 AM
Very nice google charts, thanks for the information.
Posted by: Tracking Google Bot @ Web Development blog at May 1, 2008 2:01 PM
Hi,
The ability to send links in an email that
translate into a graph certainly speeds up
having to send multiple graphical
representations of something in an email.
Would be nice to be able to add axis labels.
I've been in those shoes many times with long
loading emails of graphs!
Thanks
Steve
Posted by: Steve Madden at May 1, 2008 5:13 PM