R Leaflet Map - addPolygon地理标签

时间:2016-05-13 19:36:38

标签: r leaflet polygon layer labels

我正在制作一张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

1 个答案:

答案 0 :(得分:1)

一种方法是使用addPolygons中的leaflet(df) %>% addTiles() %>% addPolygons(data=df,weight=.85, highlight = highlightOptions( weight = 5, color= "#666", dashArray = "", fillOpacity = 0.7, bringToFront = TRUE), label=~df$labelyouwant) 选项,如下所示:

s = ['st', 'nd', 'rd', 'th']
string = 'Mar 1st 2017 00:00 am'
string = 'Mar 2nd 2017 00:00 am'
string = 'Mar 3rd 2017 00:00 am'
string = 'Mar 4th 2017 00:00 am'
for i in s:
    a = string.replace(i, '')
a = [string.replace(i, '') for i in s][0]
print(a)

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