scale_whitebox {tidyterra} | R Documentation |
Gradient scales from WhiteboxTools color schemes
Description
Implementation of the gradient palettes provided by WhiteboxTools. Three scales are provided:
-
scale_*_whitebox_d()
: For discrete values. -
scale_*_whitebox_c()
: For continuous values. -
scale_*_whitebox_b()
: For binning continuous values.
Additionally, a color palette whitebox.colors()
is provided. See also
grDevices::terrain.colors()
for details.
Additional parameters ...
would be passed on to:
Discrete values:
ggplot2::discrete_scale()
.Continuous values:
ggplot2::continuous_scale()
.Binned continuous values:
ggplot2::binned_scale()
.
Note that tidyterra just documents a selection of these additional parameters, check the ggplot2 functions listed above to see the full range of parameters accepted by these scales.
Usage
scale_fill_whitebox_d(
palette = "high_relief",
...,
alpha = 1,
direction = 1,
na.translate = FALSE,
drop = TRUE
)
scale_colour_whitebox_d(
palette = "high_relief",
...,
alpha = 1,
direction = 1,
na.translate = FALSE,
drop = TRUE
)
scale_fill_whitebox_c(
palette = "high_relief",
...,
alpha = 1,
direction = 1,
na.value = "transparent",
guide = "colourbar"
)
scale_colour_whitebox_c(
palette = "high_relief",
...,
alpha = 1,
direction = 1,
na.value = "transparent",
guide = "colourbar"
)
scale_fill_whitebox_b(
palette = "high_relief",
...,
alpha = 1,
direction = 1,
na.value = "transparent",
guide = "coloursteps"
)
scale_colour_whitebox_b(
palette = "high_relief",
...,
alpha = 1,
direction = 1,
na.value = "transparent",
guide = "coloursteps"
)
whitebox.colors(n, palette = "high_relief", alpha = 1, rev = FALSE)
Arguments
palette |
A valid palette name. The name is matched to the list of
available palettes, ignoring upper vs. lower case. Values available are:
|
... |
Arguments passed on to
|
alpha |
The alpha transparency, a number in [0,1], see argument alpha in
|
direction |
Sets the order of colors in the scale. If 1, the default, colors are ordered from darkest to lightest. If -1, the order of colors is reversed. |
na.translate |
Should |
drop |
Should unused factor levels be omitted from the scale? The
default ( |
na.value |
Missing values will be replaced with this value. By default,
tidyterra uses |
guide |
A function used to create a guide or its name. See
|
n |
the number of colors ( |
rev |
logical indicating whether the ordering of the colors should be reversed. |
Value
The corresponding ggplot2 layer with the values applied to the
fill/colour
aesthetics.
Source
https://github.com/jblindsay/whitebox-tools, under MIT License. Copyright (c) 2017-2021 John Lindsay.
See Also
terra::plot()
, ggplot2::scale_fill_viridis_c()
See also ggplot2 docs on additional ...
parameters.
Other gradient scales and palettes for hypsometry:
scale_color_coltab()
,
scale_cross_blended
,
scale_grass
,
scale_hypso
,
scale_princess
,
scale_terrain
Examples
filepath <- system.file("extdata/volcano2.tif", package = "tidyterra")
library(terra)
volcano2_rast <- rast(filepath)
# Palette
plot(volcano2_rast, col = whitebox.colors(100))
library(ggplot2)
ggplot() +
geom_spatraster(data = volcano2_rast) +
scale_fill_whitebox_c()
# Binned
ggplot() +
geom_spatraster(data = volcano2_rast) +
scale_fill_whitebox_b(breaks = seq(70, 200, 10), palette = "atlas")
# With discrete values
factor <- volcano2_rast %>% mutate(cats = cut(elevation,
breaks = c(100, 120, 130, 150, 170, 200),
labels = c(
"Very Low", "Low", "Average", "High",
"Very High"
)
))
ggplot() +
geom_spatraster(data = factor, aes(fill = cats)) +
scale_fill_whitebox_d(na.value = "gray10", palette = "soft")
# Display all the whitebox palettes
pals <- c(
"atlas", "high_relief", "arid", "soft", "muted", "purple",
"viridi", "gn_yl", "pi_y_g", "bl_yl_rd", "deep"
)
# Helper fun for plotting
ncols <- 128
rowcol <- grDevices::n2mfrow(length(pals))
opar <- par(no.readonly = TRUE)
par(mfrow = rowcol, mar = rep(1, 4))
for (i in pals) {
image(
x = seq(1, ncols), y = 1, z = as.matrix(seq(1, ncols)),
col = whitebox.colors(ncols, i), main = i,
ylab = "", xaxt = "n", yaxt = "n", bty = "n"
)
}
par(opar)