Pages Menu
TwitterRss
Categories Menu

Posted by on Feb 12, 2011 in R Spatial, Visualisation | 3 comments

Using R to Map with Google Chart Tools

The release of the R package “googleVis” has made the production of interactive maps through Google’s Chart Tools a simple task. Ignoring the some basic data manipulation the below map was produced with these two lines of code:

library(googleVis)

Geo=gvisGeoMap(Map, locationvar=”Country”, numvar=”Percentage”,

options=list(height=350, dataMode=’regions’))

plot(Geo)

This map, although simple to produce, is nontrivial as it shows the percentages of 5-14 year olds in each country conducting child labour. You can download the data for it here, and the rest of the R code here.

Data: Map, Chart ID: GeoMap_2011-01-11-09-36-24

R version 2.12.1 (2010-12-16),

Google Terms of Use

If you print the “Geo” object you will get a load of code that you can then paste into your website. I am amazed by how straightforward it is, thanks to the clever people at Google some great programming from R contributors. It isn’t perfect (I think the Mercator projection is inappropriate here) but it’s a great start.

Share on Facebook
Bookmark this on Google Bookmarks
Share on reddit
Bookmark this on Digg
Share on StumbleUpon
Share on LinkedIn

3 Comments

  1. I run the R code but when I type plot(Geo) a internet browser but empty, so nothing is plotted. Any idea what I am doing wrong?
    Regards

  2. Works for me. if you cut and pasted make sure that the quotes are done correctly

  3. The map frame will stay empty if your browser refuses to open a non-HTTPS connexion to the Google API. Typically, if you have HTTPS Everywhere installed, you will have to untick it from the blocklist for the maps to show up.

Trackbacks/Pingbacks

  1. Data Journalism Developer Studio – Release 0.6.0 » Borasky Research Journal - [...] I've added the googleVis package to the base appliance. As the name implies, googleVis is an interface to the …
  2. R with Google Chart Tool | Mumahuang's Blog - [...] Thanks to the code from http://spatialanalysis.co.uk/2011/02/using-r-to-map-with-google-chart-tools/ [...]

Post a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>