plot,GRaster,missing-method | R Documentation |
plot()
displays a GRaster
or GVector
.
This function is essentially a hack, as it it not possible to dependably call the appropriate GRASS modules and display a raster or vector without potential confusion on the user side. Instead, this function 1) simplifies the focal GRaster
or GVector
to make it smaller when saved to disk; 2) writes the object to disk; 3) (internally) creates a SpatRaster
or SpatVector
object; then 4) plots the object using terra::plot()
. Thus, if you are interested in making maps, it will always be faster to make them directly with terra or sf.
## S4 method for signature 'GRaster,missing'
plot(x, y, simplify = TRUE, ...)
## S4 method for signature 'GVector,missing'
plot(x, y, maxGeoms = 10000, ...)
x |
A |
y |
Missing–leave as empty. |
simplify |
Logical: If |
... |
Other arguments to send to |
maxGeoms |
Positive integer (vectors only): Maximum number of features before vector simplification is applied before saving to disk then creating a |
Nothing (displays a raster or vector).
terra::plot()
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.