在Mapview中一直添加多边形的名称?

huangapple go评论76阅读模式
英文:

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')

在Mapview中一直添加多边形的名称?

答案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"))

这会产生如下效果:

在Mapview中一直添加多边形的名称?

英文:

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&lt;-st_read(&#39;https://raw.githubusercontent.com/mgaitan/departamentos_argentina/master/departamentos-buenos_aires.json&#39;,stringsAsFactors= FALSE)
mapview(mp, zcol=&#39;cabecera&#39;) %&gt;%
  addStaticLabels(mp,
                  mp$cabecera,
                  noHide = TRUE,
                  textsize = &quot;6px&quot;,
                  style = list(&quot;background-color&quot; = &quot;white&quot;, &quot;font-weight&quot; = &quot;bold&quot;))

which gives:

在Mapview中一直添加多边形的名称?

huangapple
  • 本文由 发表于 2023年3月23日 08:02:37
  • 转载请务必保留本文链接:https://go.coder-hub.com/75818233.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定