# \donttest{
library(terra)
# Raster
f <- system.file("extdata/volcano2.tif", package = "tidyterra")
r <- rast(f)
library(ggplot2)
ggplot() +
geom_spatraster_contour(data = r)
# Labelled
ggplot() +
geom_spatraster_contour_text(
data = r, breaks = c(110, 130, 160, 190),
color = "grey10", family = "serif"
)
ggplot() +
geom_spatraster_contour(
data = r, aes(color = after_stat(level)),
binwidth = 1,
linewidth = 0.4
) +
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(80, 200, 10)) +
scale_fill_hypso_d()
# Both lines and contours
ggplot() +
geom_spatraster_contour_filled(
data = r, breaks = seq(80, 200, 10),
alpha = .7
) +
geom_spatraster_contour(
data = r, breaks = seq(80, 200, 2.5),
color = "grey30",
linewidth = 0.1
) +
scale_fill_hypso_d()
# }
Run the code above in your browser using DataLab