R Leaflet Map - addPolygon地理标签

sco*_*tus 5 label r polygon layer leaflet

我正在制作一张 R 传单地图,该地图有人口普查区,每个区域都有一个相关的数字。当您滚动或使用图层控制单选按钮时,是否可以在地图上显示标签。

标签已经在形状文件中:

map1<-leaflet()%>%
  addTiles()%>%

addPolygons(data = plotMerge,
          fillColor = ~pal(plotMerge$incomePerCapita),
          color = "#000000", #this is an outline color hoping to
          fillOpacity = 0.8, # add the labels inside this outline
          weight = 0.2,
          popup=popup)%>%
addLegend(pal = pal,
            values  = plotMerge$incomePerCapita,
            position = "bottomright",
            title = "State-wide Income Percentiles",
            labFormat = labelFormat(digits=1))

saveas(map1, "map1.html")
map1
Run Code Online (Sandbox Code Playgroud)

Ben*_*Ben 2

一种方法是像这样使用该highlight选项addPolygons

leaflet(df) %>% addTiles() %>%
addPolygons(data=df,weight=.85,
    highlight = highlightOptions(
    weight = 5, color= "#666",
    dashArray = "", fillOpacity = 0.7,
    bringToFront = TRUE),
   label=~df$labelyouwant)
Run Code Online (Sandbox Code Playgroud)

当您将鼠标悬停在多边形上时,将出现标签。