compositeRGB,GRaster-method | R Documentation |
This function takes as arguments three rasters typically representing red, green, and blue color bands, and returns a single raster with values based on their combination. Typically, this raster should be plotted in grayscale.
## S4 method for signature 'GRaster'
compositeRGB(r, g = NULL, b = NULL, levels = 256, dither = FALSE)
r , g , b |
Either:
|
levels |
Either a single value that is an integer, or a vector of integers: Number of levels of red, green, and blue intensities represented in |
dither |
Logical: If |
A GRaster
.
plotRGB()
, terra::plotRGB()
, GRASS manual page for module r.composite
(see grassHelp("r.composite")
)
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.