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

Ray Brownrigg Ray.Brownrigg at ecs.vuw.ac.nz
Sun Aug 12 23:28:50 CEST 2012


On 08/10/12 11:01, Cable, Sam B Civ USAF AFMC AFRL/RVBXI wrote:
> 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.
> 
The reason that a projection "does not work" is that a projection
involves remapping the axes, even for a rectangular projection.

However as Duncan states, using the default, i.e. no, projection should
do what you want.  However it seems that you have not read the posting
guide.  I don't see any code (with data) to reproduce your problem and
one can only guess what "neither one actually fits the map to the region
of the filled contour" really means.

I suspect the problem is an issue of aspect ratio, but the map()
function is generally quite happy to accept whatever weird aspect ratio
you have set up when you use add=TRUE.

Also if you RTFM ?mapproject, you may realise that performing the
projection first, then the (projected) filled contour (then overlaying
the map again may achieve what you want.

Ray Brownrigg

> 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 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
> 
> 
> 
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list