R interface to Google Chart Tools

Hans Rosling eat your heart out! It is now possible to interface R statistics software to Google’s Gapminder inspired Chart Tools. The plots below were produced using the googleVis R package and three datasets from the Gapminder website. The first shows the relationship between income, life expectancy and population for 20 countries with the highest life expectancy in 1979 and the bottom plot shows the countries with the lowest 1979 life expectancy. Press play to see how the countries have faired over the past 50 years. You can also change the variables represented on each axes, the colours and the variable that controls the size of the bubbles.

Data: all_date, Chart ID: MotionChart_2011-01-10-10-16-25
R version 2.12.1 (2010-12-16),

Google Terms of Use


Data: all_date, Chart ID: MotionChart_2011-01-10-10-10-46
R version 2.12.1 (2010-12-16),

Google Terms of Use

It was a bit fiddly to get the data formatted correctly and I couldn’t manage to get the complete dataset in one plot because my browser kept crashing (Chrome is best). Even with these teething problems it is a great way to get people creating better visualizations with their data. If you want to see Hans Rosling demonstrating these plots with his trademark enthusiasm I thoroughly recommend “The Joy of Stats” a program produced for the BBC. You can watch it here.
For those who want to create their own plots, I’m not proud of the code I used to format the data above so to get you started try this example (provided with the package).
library(googleVis)
data(Fruits)
M1 <- gvisMotionChart(Fruits, idvar=”Fruit”, timevar=”Year”)
plot(M1)
Thanks to the Recology blog for promoting this.

Boris Bikes/Barclays Cycle Hire Average Journey Times


The visualisation above shows the average relative duration of Boris Bikers’ weekday journeys over a 4 month period at hourly intervals. For each time step the average journey time (in seconds) from each docking station has been calculated.This information is interesting because it shows the preference for short journeys around the City of London, whilst people on the outskirts of the the scheme (especially to the west) take longer journeys. I also like the the fact that journey times around Soho and the West End are longest around 23:00- perhaps correlating with the number of after-work drinks consumed. In one visualisation you get to see the changes in the cyclists behaviour- from the early morning commuters through to the late night cruisers
The data come from Transport for London’s recent release of 1.4 million Barclays Cycle Hire journeys to their developers area (thanks to this FOI request). The data are said include all the journeys between 30 July 2010 and 3 November 2010, except those starting between midnight and 6am. In this analysis journeys taking more than one hour are not included (there are relatively few and many were actually the bikes being removed for maintenance) and docking stations with fewer than 10 journeys within each hour across the time period have also been ignored.
The maps can be improved in many ways- stay tuned for more developments and I will also post something a bit more technical about the methods I used etc to create the map (I used a strange cocktail of R and ArcGIS 10) .

I also recommend Ollie O’Brien’s (@oobr) brilliant interactive visualisations these data.

Exporting KML from R

Google Earth has become a popular way of disseminating spatial data. KML is the data format required to do this. It is possible to load almost any type of spatial data format into R and export it as a KML file. In my experience R seems much quicker at doing this than many well-known GIS platforms, such as ArcGIS. The worksheet below explains how.
Data and Package Requirements:
London Cycle Hire Locations. Download.
Install the following packages (if you haven’t already done so):
maptools, rgdal (Mac users may wish to see here first).

Click here to view the tutorial code.

Handling Spatial Data with R

Spatial data are becoming increasingly common, as are the tools available in R to process it. It takes a little time to understand how R handles spatial data; this tutorial is designed to help get people started. It outlines how to create a simple spatial points object from as csv file, ambien load and export a shapefile and alter or add spatial projection information.
Data and Package Requirements:
London Sport Participation Shapefile. Download (requires unzipping).
London Cycle Hire Locations: Download.
Install the following packages (if you haven’t already done so):
maptools, rgdal (Mac users may wish to see here first).

Click here to view the tutorial code.

Geographical Mistakes: Keeping Geographers Busy

This is a cross post from Hodder Geography’s Expert Blog.

As geographers we try to better understand the world, and I believe one of our most important skills is the ability to apply a map’s representation of the world to reality. This can range from basic navigation using a paper map to understanding the impacts that climate change will have on people if model predictions are correct. That’s not to say we don’t ever make mistakes. Some are amusing, whilst others can have serious implications. Google, for example, have accidentally become involved in the dispute between Nicaragua and Costa Rica by drawing an incorrect border between the two countries. Google’s maps get scrutinised by thousands of people each hour so mistakes are unlikely to go unnoticed. The city of Sunrise in Florida, for example, was lost on Google Maps. This caused a great deal of concern for residents, one local commented, “It felt like a bizarre novel…We woke up one morning and we didn’t exist in the ether world!”. The disappearing places problem doesn’t even seem to stop at cities: the EU attracted controversy by accidentally missing out the entire Welsh nation on the cover of its annual statistics publication!

One of the most famous mistakes, amongst academic geographers at least, is the Economist magazine’s article on the threat of missiles from North Korea. The first map they published, shown above, did not account for the fact that the world is spherical. It therefore massively underestimated the distance that North Korea’s missiles could travel. As with Google’s mistake in South America, it is easy to see how this error had important geopolitical consequences. The corrected version is shown below.

In spite of their potential impact, some mistakes are deliberate. It is common for cartographers to draw in extra streets on a map. These so called “Trap Streets” can be found in anything from online maps to tourist guidebooks and are designed to identify illegitimate copies of a map.  You can find a long list trap streets on the OpenStreetMap website where they are known as “Copyright Easter Eggs“.
Even if the perfect map could be produced, technical perfection may not be enough. Research has shown that people think it takes longer to travel “up” (bottom to top) a map than “down” it. So next time you are in a hurry, be sure to turn your map so that you are always traveling downwards!