R and Google Earth

This is a simple example of using R to create input for Google Earth. We are not concerning ourselves here with the best way to display the data at this point. Rather we are exercising the mechanism for generating KML from data in R so that we can display information on Google Earth.

You can load this into Google Earth by clicking on this link. Alternatively, you can look at some screen shots

The data are temperature measurements for each of 100 cities in the US taken in each of January, April, July and October. So, for each city we have a time series, and for any of these 4 times, we have a picture of the distribution of temperature across the US geographically.

By displaying the information in Google Earth, we get different forms of interactivity relatively easily. A user can click on a point and get an HTML document to appear in a popup "bubble" window. The user can zoom in and out and see the big picture or individual cities. We could setup an animation so that we can see how the temperature varies over time dynamically rather than looking at the different time series.

For better or worse, we will do something reasonably obvious but not necessarily visually effective.

We can see

We also notice that Grand Rapids, Michigan is mis-located, especially if we have the borders displayed on Google Earth. The latitude was intentionally altered in this data.

A lattice/trellis plot of couse shows this information also, but we don't get the layout of the panels corresponding to the geographical positions of the cities. Of course, we should improve it to use the same coloring scheme for the lines as we use in our plots, and arrange the panels by latitude to show the effect of the increasingly northern latitude.

The Code

  • Code to generate XML
    This creates the KML document in R and the serializes it to a file.
  • Code to generate images
    This is done once, not each time we generate the XML, so
    createHist(temperature); createHist(temperature, mini = TRUE); createLegend(temperature)      
    
    is the command.
  • There are lots of things to cleanup including the legend, the plots, comments in the code, etc.

    Information about how to create the KML files is available at http://code.google.com/apis/kml/documentation/.

    Future work

    There are lots more interesting things to do with this interface.
  • On Windows, we can control Google Earth directly using a DCOM client interface.
  • We can work with different example data
    For instance, earthquake information, animal migration.
  • Have interactive controls in R (e.g. via RGtk, RwxWidgets, RQt, tcltk) and have queries in R select points in a dataset and highlight those in Google Earth
  • Interpolate the temperatures for time and space over all the US and superimpose a surface. And then allow the user to transition between these over time via the Google Earth time control.
  • Notes

    This is a fresh start, but relates to the work that Motoki Wu did in an "Advanced Computing Topics" class in Davis in 2007.
    Duncan Temple Lang <duncan@wald.ucdavis.edu>
    Last modified: Tue May 15 10:39:05 PDT 2007