在下面的示例中,我希望在显示的tm_text("name")
图层中仅显示 Ghana 的标签。
知道怎么做吗?谢谢您的帮助。
library(tmap)
data("World")
tmap_mode("view")
tm_shape(World) +
tm_polygons("HPI", id="HPI")+tm_text("name")
在下面的示例中,我希望在显示的tm_text("name")
图层中仅显示 Ghana 的标签。
知道怎么做吗?谢谢您的帮助。
library(tmap)
data("World")
tmap_mode("view")
tm_shape(World) +
tm_polygons("HPI", id="HPI")+tm_text("name")
这应该为您提供所需
的内容:关键行是:tm_shape(filter(World, name == "Ghana"))
用于dplyr::filter()
将变量子集化为name
所需名称。
加纳用红色勾勒出来,以便更清楚标签所指的国家。
library(tmap)
library(dplyr)
data("World")
tm_shape(World) +
tm_polygons("HPI", id="HPI")+
tm_shape(filter(World, name == "Ghana")) +
tm_borders(col = "red")+
tm_text("name", xmod = -1, ymod = -1)
由reprex 包于 2021-04-12 创建 (v2.0.0 )