[R] how to image.plot a XY grid file into a lat-lon map

Vladimir Eremeev wl2776 at gmail.com
Mon Apr 9 12:37:55 CEST 2007

Hello Linda,

Friday, April 6, 2007, 2:47:43 AM, you wrote:

LS> On 4/5/07, Vladimir Eremeev <wl2776 at gmail.com> wrote:
VE>> If your country or state borders are polygons or polylines, you could convert
VE>> them to desired projection using
VE>> the function project from the package rgdal.

VE>> Latitude-longitude grid also could be added by generating desired polylines
VE>> in lat-lon and converting them to the desired projection using project.

LS> Linda Smith wrote:

LS>>> I have a netcdf gridded file with LCC projection. I can easily use
LS>>> image.plot to visualize it. However, as the axises are in X,Y, not Lat and
LS>>> Lon, I could not add state or country maps onto it (or lat lon
LS>>> information).
LS>>> I do have a grid2d file that describes the lat and lon for each (X,Y)
LS>>> grid,
LS>>> but the lat and lon are not regularly spaced, so I could not use
LS>>> image.plot.
LS>>> Does anyone know how to plot this type of gridded data so that country or
LS>>> state borders can be easily added? Thanks a lot!

VE>> What do you mean by "grid2d file that describes the lat and lon for each
VE>> (X,Y) grid"?
VE>> If this are two rasters of the same size having corresponding latitude and
VE>> longitude values in each raster cell, then you could use contourLines to get
VE>> lat-lon grid. However, you, probably, will want to smooth it.

LS> Yes, they are. I could add lat and lon info that way, but
LS> still I could not use map() function to overlay state borders onto
LS> my image plot because this image is not  in lat and lon
LS> coordinates.

I presume you are using the function map() from the maps package.
?map says that it returns a list with x, y, range, and names
You could do something like following, for example (UNTESTED).

  state.borders<-project(cbind(state.borders.ll$x,state.borders.ll$y),proj="+proj=lcc +lat_1=48 +lat_2=33 +lon_0=-100")

Best regards,
 Vladimir                            mailto:wl2776 at gmail.com


More information about the R-help mailing list