plotRGB,GRaster-method | R Documentation |
This function takes as its main argument a GRaster
with at least three layers typically representing red, green, and blue components (plus possibly an "alpha", or transparency layer). As with plot()
, this function is somewhat of a hack in that it downsamples the layers to a coarser resolution using aggregate()
, saves the raster to disk, then uses terra::plotRGB()
to do the actual plotting.
## S4 method for signature 'GRaster'
plotRGB(x, r = 1, g = 2, b = 3, a = NULL, simplify = TRUE, ...)
x |
A |
r , g , b |
Either a numeric integer or the |
a |
Either |
simplify |
Logical: If |
... |
Arguments to pass to |
Nothing (makes a plot).
terra::plotRGB()
, plot()
, compositeRGB()
if (grassStarted()) {
# Example data
madElev <- fastData("madElev") # elevation raster
madLANDSAT <- fastData("madLANDSAT") # multi-layer raster
madRivers <- fastData("madRivers") # lines vector
# Convert SpatRaster to GRaster and SpatVector to GVector
elev <- fast(madElev)
rivers <- fast(madRivers)
landsat <- fast(madLANDSAT)
# Plot:
plot(elev)
plot(rivers, add = TRUE)
# Histograms:
hist(elev)
hist(landsat)
# Plot surface reflectance in RGB:
plotRGB(landsat, 3, 2, 1) # "natural" color
plotRGB(landsat, 4, 1, 2, stretch = "lin") # emphasize near-infrared (vegetation)
# Make composite map from RGB layers and plot in grayscale:
comp <- compositeRGB(r = landsat[[3]], g = landsat[[2]], b = landsat[[1]])
grays <- paste0("gray", 0:100)
plot(comp, col = grays)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.