# NOT RUN {
filepath <- system.file("extdata/cyl_temp.tif", package = "tidyterra")
library(terra)
cyl_temp <- rast(filepath)
# Modify with tidyverse methods
library(dplyr)
continous <- cyl_temp %>% select(tavg_05)
library(ggplot2)
ggplot() +
geom_spatraster(data = continous) +
scale_fill_terrain_c()
# Binned
ggplot() +
geom_spatraster(data = continous) +
scale_fill_terrain_b(breaks = seq(5, 20, 2.5))
# With discrete values
factor <- continous %>% mutate(tavg_05 = cut(tavg_05,
breaks = c(0, 7, 9, 11, 13, 15),
labels = c(
"Very Cold", "Cold", "Mild", "Hot",
"Very Hot"
)
))
ggplot() +
geom_spatraster(data = factor) +
scale_fill_terrain_d(na.value = "gray80")
# }
Run the code above in your browser using DataLab