我正在制作一张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
最佳答案 一种方法是在addPolygons中使用highlight选项,如下所示:
leaflet(df) %>% addTiles() %>%
addPolygons(data=df,weight=.85,
highlight = highlightOptions(
weight = 5, color= "#666",
dashArray = "", fillOpacity = 0.7,
bringToFront = TRUE),
label=~df$labelyouwant)
当您将鼠标悬停在多边形上时,将显示标签.