View source: R/rasterizePoints.R
| rasterizePoints | R Documentation |
Turn a dataframe or SpatiaPointsDataFrame into a RasterLayer or RasterStack with a certain resolution and certain extent.
rasterizePoints(
data,
long = NA,
lat = NA,
res = 0.5,
tres = NA,
...,
crop = T,
crs = sp::CRS("+proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0")
)
data |
SpatialPointsDataFrame or dataframe |
long |
|
lat |
|
res |
Desired resolution for ridded output data |
tres |
Desired temporal resolution |
... |
Additional arguments for rasterize function. |
crop |
logical. Crop raster by bounding box of SpatialPoints, default is FALSE. |
crs |
projection of input data, if data is not a SpatialPointsDataFrame |
rasterstack with data
data(meuse, package="sp")
library(ggplot2)
ggplot(aes(x = x, y = y, color = zinc), data = meuse) +
geom_point() + theme(legend.position=c(0.85,0.2))
gr_meuse <- rasterizePoints(data=meuse, res=100, crs=sp::CRS("+init=epsg:28992"))
library(raster)
ggplot(aes(x = x, y = y, fill = cadmium), data = data.frame(rasterToPoints(gr_meuse))) +
geom_raster()
# If long and lat are not called x,y,
# you have to specify their columnNames
# in the rasterizePoints function accordingly
meuse_longlat <- meuse
colnames(meuse_longlat)[c(1,2)] <- c("Longitude", "Latitude")
gr_meuse <- rasterizePoints(data=meuse_longlat, long="Longitude", lat="Latitude",
res=100, crs=sp::CRS("+init=epsg:28992"))
ggplot(aes(x = x, y = y, fill = lead), data = data.frame(rasterToPoints(gr_meuse))) +
geom_raster()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.