# \donttest{
filepath <- system.file("extdata/volcano2.tif", package = "tidyterra")
library(terra)
volcano2_rast <- rast(filepath)
# Palette
plot(volcano2_rast, col = cross_blended.colors(100, palette = "arid"))
# Palette with uneven colors
plot(volcano2_rast, col = cross_blended.colors2(100, palette = "arid"))
library(ggplot2)
ggplot() +
geom_spatraster(data = volcano2_rast) +
scale_fill_cross_blended_c(palette = "cold_humid")
# Full map with true tints
f_asia <- system.file("extdata/asia.tif", package = "tidyterra")
asia <- rast(f_asia)
ggplot() +
geom_spatraster(data = asia) +
scale_fill_cross_blended_tint_c(
palette = "warm_humid",
labels = scales::label_number(),
breaks = c(-10000, 0, 5000, 8000),
guide = guide_colorbar(reverse = TRUE)
) +
labs(fill = "elevation (m)") +
theme(
legend.position = "bottom",
legend.title.position = "top",
legend.key.width = rel(3),
legend.ticks = element_line(colour = "black", linewidth = 0.3),
legend.direction = "horizontal"
)
# Binned
ggplot() +
geom_spatraster(data = volcano2_rast) +
scale_fill_cross_blended_b(breaks = seq(70, 200, 25), palette = "arid")
# With breaks
ggplot() +
geom_spatraster(data = volcano2_rast) +
scale_fill_cross_blended_b(
breaks = seq(75, 200, 25),
palette = "arid"
)
# 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_cross_blended_d(na.value = "gray10", palette = "cold_humid")
# Tint version
ggplot() +
geom_spatraster(data = factor, aes(fill = cats)) +
scale_fill_cross_blended_tint_d(
na.value = "gray10",
palette = "cold_humid"
)
# }
# Display all the cross-blended palettes
pals <- unique(cross_blended_hypsometric_tints_db$pal)
# 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 = cross_blended.colors(ncols, i), main = i,
ylab = "", xaxt = "n", yaxt = "n", bty = "n"
)
}
par(opar)
# Display all the cross-blended palettes on version 2
pals <- unique(cross_blended_hypsometric_tints_db$pal)
# 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 = cross_blended.colors2(ncols, i), main = i,
ylab = "", xaxt = "n", yaxt = "n", bty = "n"
)
}
par(opar)
Run the code above in your browser using DataLab