Cable, Sam B Civ USAF AFMC AFRL/RVBXI
2012-Aug-09 22:14 UTC
[R] How to overlay a global map on a filled contour?
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. [[alternative HTML version deleted]]
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
Cable, Sam B Civ USAF AFMC AFRL/RVBXI
2012-Aug-09 23:01 UTC
[R] How to overlay a global map on a filled contour?
Duncan, I agree that my second code doesn't make sense. Sorry for the red herring. I was grasping at straws. My first code, however, differs from your suggestion only in that I am asking for a rectangular projection, AFAICT. As it turns out, I do get quite different results when asking for the rectangular projection and when I just accept the default, as in your code. But neither one actually fits the map to the region of the filled contour. I have found a kluge that works, involving re-setting par(usr) before the call to map(), but it is really ugly and "empirical". I am hoping there is a better way. Thanks. -----Original Message----- From: Duncan Murdoch [mailto:murdoch.duncan at gmail.com] Sent: Thursday, August 09, 2012 4:39 PM To: Cable, Sam B Civ USAF AFMC AFRL/RVBXI Cc: r-help at r-project.org Subject: Re: [R] How to overlay a global map on a filled contour? ...>Your code doesn't quite make sense. The map function doesn't want to knowthe 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