종합 정리

R로 만드는 leaflet 인터랙티브 지도

Rich Majerus

Vice President of Strategy & Planning, Queens University of Charlotte

복습

  • Leaflet과 htmlwidgets
  • 기본 지도
  • 원형 마커
  • 색상 팔레트
  • 폴리곤
  • 레이어
  • 시각적 요소

NC 로그 소득 단계구분도 2

NC 로그 소득 단계구분도 3

R로 만드는 leaflet 인터랙티브 지도

종합 정리

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") %>%
R로 만드는 leaflet 인터랙티브 지도

종합 정리

  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"))
R로 만드는 leaflet 인터랙티브 지도

종합 정리

NC 로그 소득 단계구분도 4

R로 만드는 leaflet 인터랙티브 지도

지도 저장하기

# 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")
R로 만드는 leaflet 인터랙티브 지도

연습해 봅시다!

R로 만드는 leaflet 인터랙티브 지도

Preparing Video For Download...