绘制州内高校分布

在 R 中使用 leaflet 构建交互式地图

Rich Majerus

Vice President of Strategy & Planning, Queens University of Charlotte

缅因州有多少所四年制高校?

ipeds %>% 
   filter(state == "ME")
# A tibble: 21 x 5
                     name       lng      lat state sector_label
                    <chr>     <dbl>    <dbl> <chr>        <chr>
1           Bates College -70.20333 44.10530    ME      Private
2         Bowdoin College -69.96524 43.90690    ME      Private
3           Colby College -69.66337 44.56421    ME      Private
4 College of the Atlantic -68.22885 44.39958    ME      Private
...
在 R 中使用 leaflet 构建交互式地图

绘制州内高校分布

# Assuming 'lng' and 'lat' are longitude and latitude, respectively
maine_colleges_map <- 
  leaflet() %>% 
  addProviderTiles("CartoDB") %>% 
  addMarkers(data = maine_colleges)

缅因州高校标记 1

在 R 中使用 leaflet 构建交互式地图

绘制州内高校分布

maine_colleges_map <- 
   leaflet() %>% 
   addProviderTiles("CartoDB")%>% 
   addMarkers(data = maine)

缅因州高校标记 1

# adding more markers will 
# not remove existing markers
maine_colleges_map %>%
   addCircleMarkers(data = maine)

缅因州高校标记 2

在 R 中使用 leaflet 构建交互式地图

绘制州内高校分布

# adding more markers will 
# not remove existing markers
maine_colleges_map %>% 
   addCircleMarkers(data = maine)

缅因州高校标记 2

maine_colleges_map %>% 
   clearMarkers() %>% 
   addCircleMarkers(data = maine, 
                    radius = 3)

缅因州高校标记 3

在 R 中使用 leaflet 构建交互式地图

绘制州内高校分布

maine_colleges_map <- 
  maine_colleges_map %>% 
  clearMarkers %>% 
  addCircleMarkers(
          data = maine_colleges, 
          radius = 3)

缅因州高校标记 3

maine_colleges_map %>% 
  addCircleMarkers(
           data = maine_colleges, 
           radius = 4,
           color = "red",
           popup = ~name)

缅因州高校标记 4

在 R 中使用 leaflet 构建交互式地图

让我们来练习!

在 R 中使用 leaflet 构建交互式地图

Preparing Video For Download...