library(sf)
library(geojsonsf)
library(tidyverse)
library(leaflet)
I plotted an interactive map with R.
Load packages we are going to use:
- Download roads (OSi - National 250k Map of Ireland) from the Ordnance Survey Ireland
<- "Roads_-_National_250k_Map_Of_Ireland.geojson"
roads_250k_path
<- geojsonsf::geojson_sf(roads_250k_path) |>
roads_250k mutate(RTT = as.factor(RTT)) |>
mutate(RTT_name = factor(recode(RTT,
"-32768" = "Null",
"984" = "Local Route",
"14" = "Primary Route",
"15" = "Secondary Route",
"16" = "National Motorway"),
levels = c(
"Null",
"Local Route",
"Primary Route",
"Secondary Route",
"National Motorway")
) )
- Plot the map
<- paste("<strong> OBJECTID: </strong>", roads_250k$OBJECTID, "<br>",
p_popup "<strong> RTT: </strong>", roads_250k$RTT_name, "<br>",
"<strong> LEN: </strong>", round(roads_250k$LEN, 2), "km")
<- colorFactor("YlOrRd", NULL, n = 4)
pal_fun <- leaflet() %>%
road_250k_map addPolylines(data = roads_250k,
stroke = TRUE,
weight = 2,
col = ~pal_fun(roads_250k$RTT_name),
fillOpacity = 0.5,
highlightOptions = highlightOptions(color = "blue",
weight = 3,
bringToFront = TRUE),
label = paste("OBJECTID:", roads_250k$OBJECTID),
popup = p_popup) %>%
addTiles() %>%
addLegend(data = roads_250k,
pal = pal_fun,
values = ~RTT_name,
opacity = 1,
title = "Roads - OSi National 250k Map of Ireland")
road_250k_map