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)
}
Run the code above in your browser using DataLab