Skip to content

Instantly share code, notes, and snippets.

@szechno
Last active November 21, 2025 12:10
Show Gist options
  • Select an option

  • Save szechno/b5db7d9393c5ccbc1eb9116cefea2687 to your computer and use it in GitHub Desktop.

Select an option

Save szechno/b5db7d9393c5ccbc1eb9116cefea2687 to your computer and use it in GitHub Desktop.
library(rnaturalearth)
library(rnaturalearthdata)
library(mapgl)
library(sf)
library(dplyr)
library(rmapshaper)
# https://www.naturalearthdata.com/features/
rivers50 <- ne_download(scale = 50, type = 'rivers_lake_centerlines',
category = 'physical')
lakes50 <- ne_download(scale = 50, type = 'lakes',
category = 'physical')
ocean50 <- ne_download(scale = 50, type = 'ocean',
category = 'physical')
# manually downloaded all bathy zip from website...
bathy_0 <- read_sf("./data/ne_10m_bathymetry_all/ne_10m_bathymetry_L_0.shp")
bathy_200 <- read_sf("./data/ne_10m_bathymetry_all/ne_10m_bathymetry_K_200.shp")
bathy_1000 <- read_sf("./data/ne_10m_bathymetry_all/ne_10m_bathymetry_J_1000.shp")
bathy_2000 <- read_sf("./data/ne_10m_bathymetry_all/ne_10m_bathymetry_I_2000.shp")
bathy_3000 <- read_sf("./data/ne_10m_bathymetry_all/ne_10m_bathymetry_H_3000.shp")
bathy_4000 <- read_sf("./data/ne_10m_bathymetry_all/ne_10m_bathymetry_G_4000.shp")
bathy_5000 <- read_sf("./data/ne_10m_bathymetry_all/ne_10m_bathymetry_F_5000.shp")
bathy_6000 <- read_sf("./data/ne_10m_bathymetry_all/ne_10m_bathymetry_E_6000.shp")
bathy_7000 <- read_sf("./data/ne_10m_bathymetry_all/ne_10m_bathymetry_D_7000.shp")
bathy_8000 <- read_sf("./data/ne_10m_bathymetry_all/ne_10m_bathymetry_C_8000.shp")
bathy_9000 <- read_sf("./data/ne_10m_bathymetry_all/ne_10m_bathymetry_B_9000.shp")
bathy_10000 <- read_sf("./data/ne_10m_bathymetry_all/ne_10m_bathymetry_A_10000.shp")
bathy_all <- bind_rows(bathy_0,
bathy_200,
bathy_1000,
bathy_2000,
bathy_3000,
bathy_4000,
bathy_5000,
bathy_6000,
bathy_7000,
bathy_8000,
bathy_9000,
bathy_10000
)
bathy_all_simp <- bathy_all |> ms_simplify(keep = 0.05)
maplibre(style = carto_style("dark-matter-no-labels")) |>
add_fill_layer(id = "ocean",
source = ocean50,
fill_color = "#008b8b") |>
add_fill_layer(id = "lakes",
source = lakes50,
fill_color = "#e0eeee") |>
add_line_layer(id = "rivers",
source = rivers50,
line_color = mapgl::interpolate(
column = "scalerank",
type = "linear",
values = c(1, 12),
stops = c("navy", "lightblue")
),
line_width = mapgl::interpolate(
column = "scalerank",
type = "linear",
values = c(1, 12),
stops = c(2, 1)
),
popup = "name") |>
add_fill_layer(id = "bathy",
source = bathy_all_simp,
fill_color = "#f0fff0",
fill_opacity = 0.4,
fill_outline = mapgl::interpolate(
column = "depth",
values = c(0, 10000),
stops = c("lightblue", "darkblue")
)
) |>
add_control("<div style='padding:5px'>
<b>Oceans, Rivers, and Lakes of the world</b><br />
with bathymetry from 0 to 10000m<br />
data: <a href='https://www.naturalearthdata.com/'>naturalearthdata.com</a><br />
macka szechno<br />20 November 2025
</div>")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment