library(tidyverse)
library(mapgl)
Introduction
I wanted to experiment with the mapboxgl::
package to see what kinds of interactive maps I could produce in R. I’ve seen lots of great posts from Kyle Walker on the functionality of this new package, and I wanted to give it a try.
Setup
Required packages:
I followed Kyle’s instructions on this Youtube video (and plan to purchase his material for deeper learning).
Mapping
Steps:
- Create a Mapbox account.
- Generate an access key.
- Using the
usethis::edit_r_environ()
function, add the Mapbox access token. - Render the map as shown in the demo.
# commenting out code as it doesn't render on Github pages, but it works in Quarto
# mapboxgl(
# style = mapbox_style('satellite-streets'),
# center = c(-114.26608, 32.7213),
# zoom = 14,
# pitch = 80,
# bearing = 41
# ) |>
# add_raster_dem_source(
# id = 'mapbox-dem',
# url = 'mapbox://mapbox.mapbox-terrain-dem-v1',
# tileSize = 512,
# maxzoom = 14
# ) |>
# set_terrain(
# source = 'mapbox-dem',
# exaggeration = 1.5
# )
Some further pieces still to figure out:
- It looks like I’m unable to render the interactive map on my Github pages site (I receive an error that it’s not an in-memory calc).
- There’s also functionality to overlay data (such as Census data), which would be a neat continuation to explore.
- Soon, I’d like to use this to map Mount Blue Sky – our most recent 14er hike in Colorado!