5 gis maps r data-visualization tmap
我正在使用 R 包 Tmap 创建变量的等值线,该变量有时为正,有时为负。默认发散调色板以绿色显示正值,以红色显示负值。我想扭转这一点,用红色显示正值,用绿色显示负值,以符合我使用顺序调色板的其他 choropleths。我翻阅了手册并尝试了各种方法,但似乎无法使其正常工作。这是一个可重现的示例。
library(tmap)
data(Europe)
Europe$outcome = c(scale(1:nrow(Europe)))
tm_shape(Europe) +
tm_polygons(col="outcome",
style="cont")
Run Code Online (Sandbox Code Playgroud)
我试过“auto.palette.mapping=F”、“fill.palette="-div"”、“fill.palette="YlGnBu"”等,但我似乎无法改变任何东西。
您应该指定布局:
library(tmap)
data(Europe)
Europe$outcome = c(scale(1:nrow(Europe)))
tm_shape(Europe) +
tm_polygons(col = "outcome",
style ="cont", palette = "seq") +
tm_layout(aes.palette = list(seq = "-RdYlGn"))
Run Code Online (Sandbox Code Playgroud)
tm_shape(Europe) +
tm_polygons(col = "outcome",
style ="cont", palette = "seq") +
tm_layout(aes.palette = list(seq = "RdYlGn"))
Run Code Online (Sandbox Code Playgroud)
按照 user3386170 在较新版本的评论中的建议进行编辑tmap(我在 2.3-2 上进行了测试,不确定在发布原始答案时是否可行)以下简化可用:
tm_shape(Europe) +
tm_polygons(col = "outcome",
style ="cont", palette = "-RdYlGn")
tm_shape(Europe) +
tm_polygons(col = "outcome",
style ="cont", palette = "RdYlGn")
Run Code Online (Sandbox Code Playgroud)