R Populated longitude grids - latitude grid on the map

I have a data frame comprising a plurality of data points (x,y,z), (x,y)- lower right cell longitude latitude coordinate size w(e.g., mesh with one degree). The value zwas averaged over this cell.

I would like to plot these points in R so that the entire grid cell is filled with some color derived from z.

The result will look something like this: longitude-latitude grid cells filled

The projection itself (for example, Lambert's conformal conic conformation, equiangular) does not matter, only the structure of the grid.

My data is sparse: not every cell of longitude and latitude will have data associated with it.

My hope would be a solution similar

library(maps)
map("state")
grid_points(my_data,c("x","y","z"),0.5)

where 0.5 is the resolution of the grid above, indicating a cell with 0.5 degrees.

Any thoughts?

Thank!

+5
4

spplot image ggplot2. geom_raster geom_tile. , - . :

ggplot(aes(x = x, y = y, fill = value), data = dat_grid) + geom_tile() + 
  geom_path(data = ant_ggplot)

orginates from blogpost. , ggplot2 mapproj, . coord_map .

( YOUR_DATA x, y, z):

library(ggplot2)
library(maps)
us_states <- map_data("state")
(ggplot(aes(x=x,y=y,fill=z),data=YOUR_DATA) + geom_tile())+geom_polygon(data=us_states,aes(x=long, y=lat, group=group), colour="black", fill="white", alpha=0)
+6

data.frame "x", :

library(sp)
coordinates(x) <- c("x", "y", "z")
gridded(x) <- TRUE
image(x, col = terrain.colors(256), useRaster = TRUE)

, , , , , , R.

gridded()<-, , x y , . / , , , raster , , rgdal.

library(raster)
?projectRaster

library(rgdal)
?project
?spTransform

( " ", : http://www.colorado.edu/geography/gcraft/notes/mapproj/mapproj_f.html).

. http://spatialreference.org, PROJ.4 , sp raster.

+3

I tried to make such a map recently and ended up using the interplibrary function akimato interpolate z data into a regular grid before plotting (any projections must be completed before use interp):

library(akima)
interp(x,y,z,xo=seq(min(x),max(x),by=0.5),yo=seq(min(y),max(y),by=0.5),extrap=FALSE,linear=TRUE) -> xygrid
image(xygrid,breaks=seq(min(z),max(z),length=10), col=1:10)
+2
source

You can do it:

library(raster)
r <- rasterFromXYZ(xyz)
plot(r)
0
source

All Articles