英文:
Add the names of the polygons all the time in Mapview R?
问题
我在R中使用mapview来绘制地图。我有100多个多边形,想在地图上每次都显示它们的名称。但我找不到解决这个问题的方法。有什么建议吗?
英文:
I am using mapview in R to plot maps. I have more tha 100 polygons and I want to show them on the map with the names on it every time. But I couldn’t find a solution to this issue. Any idea?
mp<-st_read('https://raw.githubusercontent.com/mgaitan/departamentos_argentina/master/departamentos-buenos_aires.json',stringsAsFactors= FALSE)
mapview(mp, zcol='cabecera')
答案1
得分: 3
假设你想要在地图上始终显示静态标签,而不仅在悬停时显示,你可以使用 addStaticLabels()
函数来实现,它来自 {leafem} 包:
library(leafem)
mp <- st_read('https://raw.githubusercontent.com/mgaitan/departamentos_argentina/master/departamentos-buenos_aires.json', stringsAsFactors = FALSE)
mapview(mp, zcol = 'cabecera') %>%
addStaticLabels(mp,
mp$cabecera,
noHide = TRUE,
textsize = "6px",
style = list("background-color" = "white", "font-weight" = "bold"))
这会产生如下效果:
英文:
Assuming that you mean you want static labels that are always on the map, rather than just when you hover on them, you could use addStaticLabels()
from {leafem}:
library(leafem)
mp<-st_read('https://raw.githubusercontent.com/mgaitan/departamentos_argentina/master/departamentos-buenos_aires.json',stringsAsFactors= FALSE)
mapview(mp, zcol='cabecera') %>%
addStaticLabels(mp,
mp$cabecera,
noHide = TRUE,
textsize = "6px",
style = list("background-color" = "white", "font-weight" = "bold"))
which gives:
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论