[This article was first published on r.iresmi.net, and kindly contributed to R-bloggers]. (You can report a problem with the content on this page here)
Want to share your content on R bloggers? click here if you have a blog, or here if you don’t.
Day 2 of 30 Day Card Challenge: « Lines » (earlier).
To display a digital elevation model as ridges…
Configuration
library(elevatr)
library(rnaturalearth)
# remotes::install_github("ropensci/rnaturalearthhires")
library(terra)
library(ggplot2)
library(ggridges)Facts
ch <- ne_countries(scale = 10, country = "switzerland") ele <- get_elev_raster(ch, z = 9) names(ele) <- "z"
Card
ele |>
mask(ch) |>
aggregate(fact = 20) |>
as.data.frame(xy = TRUE) |>
ggplot() +
geom_density_ridges(aes(x = x, y = y, group = y, height = z),
stat = "identity",
alpha = 0.3,
color = "red",
fill = "white",
scale = 10) +
labs(title = "Switzerland",
caption = paste("Elevation data from
https://registry.opendata.aws/terrain-tiles
https://r.iresmi.net/", Sys.Date())) +
theme_void() +
theme(plot.background = element_rect(fill = "grey"),
title = element_text(color = "red"),
plot.caption = element_text(color = "#777"),
plot.margin = margin(2, 2, 2, 5, unit = "mm"))
Figure 1: Swiss mountain ridges
Related
#Ridge #lines #bloggers


