Ridgelines

R-bloggers 2025-11-02

[This article was first published on r.iresmi.net, and kindly contributed to R-bloggers]. (You can report issue about 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.

A photo of a hiking trail below a steep ridge in the clouds

Hiking Path – CC BY-NC-SA by HD

Day 2 of 30DayMapChallenge: « Lines » (previously).

Representing a digital elevation model as ridgelines…

Config

library(elevatr)library(rnaturalearth)# remotes::install_github("ropensci/rnaturalearthhires")library(terra)library(ggplot2)library(ggridges)

Data

ch <- ne_countries(scale = 10, country = "switzerland")ele <- get_elev_raster(ch, z = 9)names(ele) <- "z"

Map

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"))
A map of Switzerland altitude
Figure 1: Swiss ridgelines
To leave a comment for the author, please follow the link and comment on their blog: r.iresmi.net.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
Continue reading: Ridgelines