[R-sig-Geo] Plotting continuous data (gridded) clipped to shape boundary
Roger Bivand
Roger.Bivand at nhh.no
Tue Mar 4 10:38:42 CET 2008
On Wed, 27 Feb 2008, Shawn P. Serbin wrote:
> All,
>
> I was hoping there was someone (or several folks) who could assist me. I
> have spent some time lately trying to figure out a way to plot gridded
> data in Latitude and Longitude values with a map overlay and ultimately
> the gridded data would be clipped to the boundary of the map, i.e. a
> Wisconsin state boundary shapefile (either custom or from the maps
> package). The idea is to create code that can inject netCDF output and
> quickly create maps that can be used in presentations/publications.
>
> I have cleared the first hurdle (well not really a hurdle) and have a
> pretty clean way of importing the netCDF files into R arrays, vectors,
> data.frames (I guess these would be considered Spatial.data.frames)
> which I can then manipulate.
>
> The problem lies with the actual mapping. Now I can easily map the data
> in the Lattice package(s) and display a very nice, custom legend bar
> with contour overlays. However, when I try to use ?image? in the
> spatstat package either 1) I can only view the data on a standard grid
> (i.e. 0 to 1 in the x and y) or 2) I get an error message letting me
> know that ?expecting increasing x and y? or 3) ?x does not increase
> consistently?
It is not impossible that the difficulties come from mixing projected and
geographical coordinates. Could you please try to show is your problem as
code, say using volcano? Could you also say what you mean by "clipping" -
do you mean painting over the areas outside Wisconsin with background
colour? Or do you mean setting the grid cells falling outside Wisconsin to
NA, and omitting them from the display?
If the polygon is a SpatialPolygons object, and the data are a
SpatialGridDataFrame or SpatialPixelsDataFrame in the same coordinate
reference system, overlay() methods in sp will do this. If not in the same
CRS, use spTransform() on the SpatialPolygons object to get it to the grid
CRS. For obvious reasons, you cannot transform the CRS of the grid.
Roger
>
> Again, I have tried many mapping and spatial packages but have yet to
> find one that can handle the lat and long as well as clipping to a
> boundary. Now I have seen an example on the web where using image you
> can create a binary mask (i.e. meuse) but have yet to see how I can get
> this to work with a vector shapefile. If I could get this to work with
> plotting lat and long in image I think I would be good to go.
> Alternatively, if there is a package that can handle what I am looking
> to do then that would be great as well. It seems however that I am
> having difficulty getting the data in the correct format and / or using
> the correct plotting.
>
> What I would like to do is something similar to the ?volcano? demo where
> I plot the gridded data (in native 8km grid cell resolution) then
> overlay contours of my chosen spacing and the clip the data to
> Wisconsin, with Lat and Long x and y and a legend bar.
>
> Thanks in advance to any and all who are better at this than me!
>
> Shawn
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at stat.math.ethz.ch
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>
--
Roger Bivand
Economic Geography Section, Department of Economics, Norwegian School of
Economics and Business Administration, Helleveien 30, N-5045 Bergen,
Norway. voice: +47 55 95 93 55; fax +47 55 95 95 43
e-mail: Roger.Bivand at nhh.no
More information about the R-sig-Geo
mailing list