| rgb2spLayout | R Documentation |
Raster* to Use with spplot()This function takes a red-green-blue SpatRaster or Raster* object and
produces a list with color information that can be passed on as 'sp.layout'
to sp::spplot().
rgb2spLayout(x, quantiles = c(0.02, 0.98), alpha = 1)
x |
A 3-layered |
quantiles |
Upper and lower quantiles used for color stretching. |
alpha |
Level of transparency. |
Tim Appelhans, Florian Detsch
terra::plotRGB().
b = terra::rast(system.file("ex/logo.tif", package="terra"))
## using plotRGB
terra::plotRGB(b)
## convert raster to list
lout = rgb2spLayout(b)
lout_alph = rgb2spLayout(b, alpha = 0.5)
## create random spatial points for plotting
df = data.frame(
dat = rnorm(100, 2, 1)
, x = rnorm(100, 50, 20)
, y = rnorm(100, 50, 25)
)
df = sf::st_as_sf(df, coords = c("x", "y"))
## plot spatial points with rgb background
if (require(sp, quietly = TRUE)) {
spplot(as(df, "Spatial"), sp.layout = lout)
spplot(as(df, "Spatial"), sp.layout = lout_alph)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.