gplot-methods | R Documentation |
This function displays Raster*
and SpatRaster
objects with the ggplot2
system. Note that the function in the
rasterVis
package is called gplot
with a single 'g'.
gplot
uses geom_raster
to display the
data, sets the color map with
scale_fill_viridis_c
, and sets the coordinate
reference system with coord_sf
. For multilayer
objects, it uses facet_wrap
to display a matrix
of panels.
## S4 method for signature 'Raster'
gplot(x, maxpixels=50000, palette = "magma",
show.legend = TRUE, ...)
## S4 method for signature 'SpatRaster'
gplot(x, maxpixels=50000, palette = "magma",
show.legend = TRUE, ...)
x |
A Raster* or SpatRaster object |
maxpixels |
Maximum number of pixels to use |
palette |
If |
show.legend |
logical, if |
... |
Additional arguments for ggplot |
Robert J. Hijmans and Oscar Perpiñán; based on an example by Paul Hiemstra
plot, spplot
## Not run:
library(raster)
library(terra)
library(ggplot2)
library(sf)
theme_set(theme_bw())
r <- raster(system.file("external/test.grd", package="raster"))
r2 <- stack(r, r*2)
names(r2) <- c('meuse', 'meuse x 2')
## With raster
gplot(r)
gplot(r2)
## With terra
s <- rast(r)
s2 <- rast(r2)
gplot(s)
gplot(s2)
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.