有没有办法在tm_bubbles项目的弹出窗口中建立超链接?

时间:2019-04-16 15:13:03

标签: tmap

我正在使用tmap包来可视化地图中的某些值。 有人知道在交互式地图的弹出框中集成超链接的方法吗?

我所做的是使用下面的代码。我确实看到了所需的URL,但是无法单击它。

然后我在字符串中添加了< A HREF="URL">name< / A >。但这不能使其正常工作。

tmap_mode("view")

tm_shape(dataset) +
  tm_bubbles(size = 1, col = "value1", palette = "-RdBu", popup.vars = c("value2","URL"), text = "value3")

如果能找到所有可能的帮助,我将不胜感激。

1 个答案:

答案 0 :(得分:0)

据我所知,您几乎无法控制tmap中的弹出窗口。 通过软件包leaflet直接使用传单库要容易得多。

我首先将弹出窗口的文本粘贴为HTML,然后在leaflet::addCircleMarkers()调用中将其用作弹出窗口参数(波浪线很重要)。

传单中的圆圈标记非常类似于tmap气泡,可以进行调整以使其看起来更细;为了简洁起见,我专注于主要主题,即交互式地图的弹出气球中的可自定义超链接。

library(dplyr)   # for mutate & pipe
library(tmap)    # for the metro dataset
library(leaflet) # interface to leaflet

data("metro") # from the tmap package

metro %>% 
  mutate(label = paste("marvel at ", name, " and follow <a href = https://stackoverflow.com/>stack overflow</a>")) %>% 
  leaflet() %>%
  addTiles(group = "OSM") %>%
  addCircleMarkers(popup = ~label)

screenshot