Skip to content
Prev 181013 / 398502 Next

combining xYplot with map

I'm using xYplot to create a bubble plot of values that I'd like to 
visualize on top of a filled-in map of the coast, but I'm too much of a 
lattice (which I understand xYplot is built on) and mapping newbie to 
figure out how to begin to make this happen.  Below is some sample code 
that doesn't work but illustrates my goal.  Any pointers anyone has 
would be much appreciated.  I'm using R v2.9.0 on Windows with Hmisc 
v3.6-0 and maps v2.1-0.

Cheers,
eric

library(Hmisc)
library(maps)

sample.data <- data.frame(lat = c(12.1667, 14.6333, -6.874, 2.6167, 
14.6833,
11.2, 3.2667, 11.4167, -13.8623, 13.1667), lon = c(-126.25, -103.4667,
-88.4572, -93.65, -97.7, -88.65, -111.0167, -119.7333, -100.0748,
-108.0333), exp.index = c(23.6266244576543, 2.06824648038330,
0, 1.46378849121688, 24.1824663424805, 0, 0.364600074527829,
4.468039274638, 0.543833744085446, 18.2301918845932))

xlim <- c(-150, -80)
ylim <- c(-5, 30)
print(xYplot(lat ~ lon, data = sample.data, size = sample.data$exp.index,
 xlim = xlim, ylim = ylim
))
map("world", fill = TRUE, col = "gray", xlim = xlim, ylim = ylim, add = 
TRUE)