rgb2spLayout: Convert an RGB Raster* to Use with 'spplot()'

View source: R/rgb2spLayout.R

rgb2spLayoutR Documentation

Convert an RGB Raster* to Use with spplot()

Description

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().

Usage

rgb2spLayout(x, quantiles = c(0.02, 0.98), alpha = 1)

Arguments

x

A 3-layered SpatRaster* or Raster* object.

quantiles

Upper and lower quantiles used for color stretching.

alpha

Level of transparency.

Author(s)

Tim Appelhans, Florian Detsch

See Also

terra::plotRGB().

Examples

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)
}


Orcs documentation built on Jan. 6, 2023, 5:14 p.m.