简体   繁体   English

当我将鼠标悬停在用tmap制作的地图上时,如何修复标签

[英]How to fix label when I hover mouse over map made with tmap

I plotted a map of Puerto Rico with poverty rate data by county (municipalities) using tmap. 我使用tmap绘制了波多黎各的地图,其中有按县(市)划分的贫困率数据。 When I turn the interactive version on, I am able to click on the municipality and the correct data show up. 当我打开交互式版本时,我可以单击市政当局,并显示正确的数据。

However, when I hover my mouse over the municipalities, Puerto Rico's FIPS code (72) shows up in a white box. 但是,当我将鼠标悬停在市政上时,波多黎各的FIPS代码(72)出现在一个白框中。 How can I change it so when I hover my mouse over the municipality, its name shows up instead of the 72? 如何将其更改为将鼠标悬停在市政上时,其名称会显示而不是72?

#Create map plot
    PRmap2 <- tm_shape(PRmap) +
      tm_fill("Pobreza",
          popup.vars = c("Municipio" = "COUNTY", "Pobreza (%)" = "Pobreza",
                       "Ingreso per cápita ($)" = "Ingreso_per_cápita"),
          title = "Pobreza (%)",
          style = "pretty",
          breaks = c(-Inf, 0, 20, 40, 60, Inf)) +
      tm_style(c("col_blind")) +
      tm_borders() +
      tm_layout("Pobreza en Puerto Rico",
        legend.title.size = 1.5,
        legend.text.size = 0.6,
        legend.position = c("left","bottom"),
        legend.bg.color = "white",
        legend.bg.alpha = 1)

#Visualization mode changed to view so we can interact
tmap_mode("view")

#Interactive visualization
PRmap2 + 
  tm_basemap(server = "OpenStreetMap.HOT")

You can find the interactive map here: http://rpubs.com/Javier_927/461125 您可以在此处找到交互式地图: http : //rpubs.com/Javier_927/461125

您可以在tm_polygons中设置“ id”: https ://www.rdocumentation.org/packages/tmap/versions/2.2/topics/tmap_mode

tm_polygons("income_grp", palette="-Blues", contrast=.7, id="name", title="Income group") 

If you change the order of your dataframe, it uses the first column to determine the hover over text. 如果更改数据框的顺序,它将使用第一列来确定将鼠标悬停在文本上。 There should be a more direct way to assign it, but this at least works. 应该有一种更直接的方式来分配它,但这至少是可行的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM