# \donttest{
filepath <- system.file("extdata/volcano2.tif", package = "tidyterra")
library(terra)
volcano2_rast <- rast(filepath)
# Palette
plot(volcano2_rast, col = princess.colors(100))
library(ggplot2)
ggplot() +
geom_spatraster(data = volcano2_rast) +
scale_fill_princess_c()
# Binned
ggplot() +
geom_spatraster(data = volcano2_rast) +
scale_fill_princess_b(breaks = seq(70, 200, 10), palette = "denmark")
# 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_princess_d(na.value = "gray10", palette = "maori")
# }
# Display all the princess palettes
pals <- unique(princess_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 = princess.colors(ncols, i), main = i,
ylab = "", xaxt = "n", yaxt = "n", bty = "n"
)
}
par(opar)
Run the code above in your browser using DataLab