[R] How to overlay a global map on a filled contour?

Duncan Murdoch murdoch.duncan at gmail.com
Fri Aug 10 00:39:13 CEST 2012


On 12-08-09 6:14 PM, Cable, Sam B Civ USAF AFMC AFRL/RVBXI wrote:
> I would like to plot some lat-lon data in a filled contour, and then
> overlay a map of the globe on top. I am trying something like this:
>
>
>
> filled.contour(lons, lats, glb.data,
> plot.axes={axis(1);axis(2);map(projection='rectangular',parameters=0,add
> =T)}
> )
>
>
>
> The filled contour plots fine, and the map shows up, but only as a very
> tiny little black rectangle in a small area of the contour plot. Of
> course, I want the map to stretch over the entire area of the filled
> contour plot.
>
>
>
> I've also tried something like:
>
> filled.contour(lons, lats, glb.data,
> plot.axes={axis(1);axis(2);map(projection='rectangular',x=lons,y=lats,pa
> rameters=0,add=T)}
> )
>
>
>
> In this case, the map does not plot at all and I get an error message
> "nothing to draw: all regions out of bounds"
>
>
>
> People apparently do this successfully all the time, but I haven't been
> able to get it to work. Can anyone tell me what I am doing wrong? BTW, I
> don't want to use the lattice package. It will not work with the other
> stuff my group is doing. Thanks.
>

Your code doesn't quite make sense.  The map function doesn't want to 
know the x and y values; it just wants to know the region to plot, which 
should have been set by the data.  So, assuming that 
filled.contour(lons, lats, glb.data) produces something sensible, you'd 
get what you want with

filled.contour(lons, lats, glb.data, plot.axes={axis(1); axis(2); 
map(add=TRUE)})

Duncan Murdoch



More information about the R-help mailing list