[R] plotting tripgrid on PBSmapping

Michael Sumner mdsumner at gmail.com
Tue Mar 11 04:27:19 CET 2014


Hi, this doesn't have much to do with tripGrid, since the object to
plot is just a SpatialGridDataFrame.

I don't use PBSmapping, so I haven't looked at that - perhaps there is
an add = TRUE option to plotMap (?), so perhaps you could do this:

image(x2009.final)
plotMap(..., add = TRUE)

Your main issue may be that you are using the Pacific view (0, 360)
longitudes rather than (-180,180).  I don't know how/if plotMap deals
with that,

Otherwise, I would use a different data set and just use the sp plot functions.

image(x2009.final)
library(maptools)
data(wrld_simpl)
plot(elide(wrld_simpl, shift = c(360, 0)), add = TRUE)

You need to "elide" it to shift it 360 in longitude since your range
is c(292,303.5)
The same will work with other polygon data in longlat read with
rgdal::readOGR or maptools::readShapePoly. To actually crop wrld_simpl
you can use "[" with matches on the data attributes, or use
rgeos::gIntersection.

You also could modify your input data to be in the range -180,180, or
use a map projection before using the trip* functions.

I know there's a lot of options listed above, but it really does
depend on which aspects matter to you.

HTH



On Tue, Mar 11, 2014 at 10:09 AM, Trevor Davies <davies.trevor at gmail.com> wrote:
> Hello,
>
> Sorry for the lack of a complete example but this is more of a class type
> question.
>
> I have a map of the coast that I generated through PBSmapping:
>
> xlims <- c(292,303.5)
> ylims <- c(41.5,49.5)
> plotMap(worldLLhigh, xlim=xlims, ylim=ylims, col=grey(0.1),bg=grey(0.9),
> xlab="", ylab="", las=1, tck=-0.015, axes=F)
>
> I want to add an intensity grid from an object that I created through the
> excellent 'trip' package (results in an sp class object
> (SpatialGridDataFrame)) and this is where I'm having difficulty.  I know
> maptools allows you to change formats from sp to PBSmapping but I can't
> seem to identify how to do it for a SpatialGridDataFrame.
>
> I get the SpatialGridDataFrame object via:
>
> x2009.grid <- makeGridTopology(data2009.sp, cells.dim = c(cell.x1,
> cell.y1), xlim=xlims, ylim=ylims,buffer = 0, cellsize = NULL,adjust2longlat
> = FALSE)
> x2009.final <- tripGrid(data2009.sp, grid = x2009.grid, method =
> "pixellate")
>
> For most of these maps I usually just add the grid layer using the image
> function but what I currently have worked out is quite messy and I think
> prone to error for other applications.
>
> Of course, I can plot the SpatialGridDataFrame object
> via: spplot(x2009.final) which would be great but I can't figure out how to
> add my coastline via the PBSmapping plotMap call.
>
> Could someone please suggest a more direct approach?
> Thank you.
>
>         [[alternative HTML version deleted]]
>
> ______________________________________________
> 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.



-- 
Michael Sumner
Hobart, Australia
e-mail: mdsumner at gmail.com




More information about the R-help mailing list