[R] overlay histograms on map at map coordinates

Steve Bellan sbellan at berkeley.edu
Tue Nov 23 05:41:05 CET 2010

Hi all,

I'm trying to visualize animal movement data characteristics  
spatiotemporally by overlaying many different histograms on a map.  I  
want the histograms to be plotted at coordinates in the map that  
matches a region they describe.  If I was just doing this once, I'd  
fiddle in Illustrator after R and avoid the headache. But I'll be  
doing it many many times so it seems worth the elegance & repeatability.

For example, say we have the following data:

covariate <- rep(letters[1:10], each = 100)
shape.pars <- rep(seq(.5,.7, length.out = 10), each = 100)
zz <- rgamma(1000, shape = shape.pars,  scale = 2)
map <- data.frame(factor = unique(covariate), xx = rnorm(10), yy =  

I'd like to be able to have 10 histograms plotted for each level of  
the covariate at the coordinates specified in the map data.frame.   
Ideally, I'd like to be able to specify whether they were plotted to  
the left, right, top, bottom or center of the coordinates similar to  
in text() and other graphical functions.  Looking around the archives,  
all I've come across are the viewport system in library(grid) which  
doesn't seem to be able to handle plot() hist() or other such  
functions.  Otherwise, I could create viewports for each histogram  
inside the map's coordinate system.

Any ideas?  Thanks!


Steve Bellan
MPH, Epidemiology
PhD Candidate, Environmental Science, Policy & Management
Getz Lab
University of California, Berkeley

More information about the R-help mailing list