scale_coltab | R Documentation |
SpatRaster
Some categorical SpatRaster
objects may have an associated color table.
This function extract those values. These functions generates scales and
vector of colors based on the color table terra::coltab()
associated to a
SpatRaster
.
You can also get a vector of colors named with the corresponding
factor with get_coltab_pal()
.
Additional parameters ...
would be passed on to
ggplot2::discrete_scale()
.
Note that tidyterra just documents a selection of these
additional parameters, check ggplot2::discrete_scale()
to see the full
range of parameters accepted.
scale_fill_coltab(
data,
...,
alpha = 1,
na.translate = FALSE,
na.value = "transparent",
drop = TRUE
)
scale_colour_coltab(
data,
...,
alpha = 1,
na.translate = FALSE,
na.value = "transparent",
drop = TRUE
)
get_coltab_pal(x)
data , x |
A |
... |
Arguments passed on to
|
alpha |
The alpha transparency, a number in [0,1], see argument alpha in
|
na.translate |
Should |
na.value |
Missing values will be replaced with this value. By default,
tidyterra uses |
drop |
Should unused factor levels be omitted from the scale? The
default ( |
The corresponding ggplot2 layer with the values applied to the
fill/colour
aesthetics.
terra::coltab()
, ggplot2::discrete_scale()
,
ggplot2::scale_fill_manual()
,
library(terra)
# Geological Eras
# Spanish Geological Survey (IGME)
r <- rast(system.file("extdata/cyl_era.tif", package = "tidyterra"))
plot(r)
# Get coltab
coltab_pal <- get_coltab_pal(r)
coltab_pal
# With ggplot2 + tidyterra
library(ggplot2)
gg <- ggplot() +
geom_spatraster(data = r)
# Default plot
gg
# With coltabs
gg +
scale_fill_coltab(data = r)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.