# NOT RUN {
library(terra)
# Raster
f <- system.file("extdata/cyl_temp.tif", package = "tidyterra")
r <- rast(f)
library(ggplot2)
ggplot() +
geom_spatraster_contour(data = r) +
facet_wrap(~lyr)
# Select one layer
ggplot() +
geom_spatraster_contour(data = r, aes(z = tavg_04))
# With aes on computed variable
ggplot() +
geom_spatraster_contour(
data = r, aes(color = after_stat(level)),
binwidth = 1,
size = 0.4
) +
facet_wrap(~lyr) +
scale_color_gradientn(
colours = hcl.colors(20, "Inferno"),
guide = guide_coloursteps()
) +
theme_minimal()
# Filled with breaks
ggplot() +
geom_spatraster_contour_filled(data = r, breaks = seq(5, 20, 2.5)) +
facet_wrap(~lyr)
# Both lines and contours aligned with breaks
ggplot() +
geom_spatraster_contour_filled(
data = r, breaks = seq(5, 20, 2.5),
alpha = .7
) +
geom_spatraster_contour(
data = r, breaks = seq(5, 20, 2.5),
color = "black"
) +
facet_wrap(~lyr)
# }
# NOT RUN {
# }
Run the code above in your browser using DataLab