Tout réunir

Cartes interactives avec leaflet en R

Rich Majerus

Vice President of Strategy & Planning, Queens University of Charlotte

Révision

  • Leaflet et htmlwidgets
  • Fonds de carte
  • Marqueurs circulaires
  • Palettes de couleurs
  • Polygones
  • Couches
  • Effets visuels

Carte choroplèthe du revenu consigné en NC 2

Carte choroplèthe du revenu consigné en NC 3

Cartes interactives avec leaflet en R

Tout réunir

leaflet() %>% 
  addTiles(group = "OSM") %>% 
  addProviderTiles("CartoDB", group = "Carto") %>% 
  addProviderTiles("Esri", group = "Esri") %>%

addPolygons(data = shp, weight = 1, fillOpacity = .75, color = ~nc_pal(log(mean_income)), label = ~paste0("Mean Income: ", dollar(mean_income)), group = "Mean Income") %>%
Cartes interactives avec leaflet en R

Tout réunir

  addCircleMarkers(data = nc_public, radius = 2, 
                   label = ~htmlEscape(name), 
                   color = ~pal(sector_label),group = "Public") %>% 
  addCircleMarkers(data = nc_private, radius = 2, 
                   label = ~htmlEscape(name),
                   color = ~pal(sector_label), group = "Private") %>% 
  addCircleMarkers(data = nc_profit, radius = 2, 
                   label = ~htmlEscape(name),
                   color = ~pal(sector_label),
                   group = "For-Profit") %>% 

addLayersControl(baseGroups = c("OSM", "Carto", "Esri"), overlayGroups = c("Public", "Private", "For-Profit", "Mean Income"))
Cartes interactives avec leaflet en R

Tout réunir

Carte choroplèthe du revenu consigné en NC 4

Cartes interactives avec leaflet en R

Enregistrer une carte

# Store leaflet map in object
m <- leaflet() %>% 
     addTiles() %>%
     addMarkers(data = ipeds,
                clusterOptions = markerClusterOptions()) %>% 
     addPolygons(data = shp)
# save leaflet object as html file
library(htmlwidgets)

saveWidget(m, file="myMap.html")
Cartes interactives avec leaflet en R

Passons à la pratique !

Cartes interactives avec leaflet en R

Preparing Video For Download...