[英]How to manipulate tmap legend?
I'm creating a thematic map of percent change per year for bird species. 我正在创建一个关于鸟类每年变化百分比的专题图。 here is the code I have:
这是我的代码:
tm_shape(grid83)+
tm_fill("trend", title = "Percent change per Year", textNA = "None counted", style="fixed",
breaks=c(-Inf, -1.5, -0.25, 0.25, 1.5, Inf),
palette = c("red", "orange", "yellow", "turquoise", "blue", "white"))+
tm_borders(NA)+
tm_shape(uscan83)+ # add US and CAN
tm_borders()+
tm_layout(
"Western Grebe",
legend.title.size=1,
legend.text.size = 0.6,
legend.position = c("left","bottom"),
legend.bg.color = "white",
legend.digits = 5,
legend.bg.alpha = 1)
Currently all NA values show up as gray. 目前,所有NA值都显示为灰色。 I've tried to change the color palette:
我试图改变调色板:
palette = c("red", "orange", "yellow", "turquoise", "blue", "white"))
but this doesn't seem to be working. 但这似乎没有用。 NA values are all still gray.
NA值仍然是灰色的。 What am I doing wrong?
我究竟做错了什么?
Thanks so much! 非常感谢!
So you are trying to change the color specifically for NA values? 所以你试图专门为NA值改变颜色? The
colorNA
argument to tm_fill()
serves that purpose. tm_fill()
的colorNA
参数用于此目的。
Here's an example: 这是一个例子:
library(tmap)
data(Europe)
tm_shape(Europe) +
tm_fill("gdp_cap_est", title = "GDP", style = "fixed",
breaks = c(0, 10000, 20000, 30000, 40000, Inf),
textNA = "Dunno",
colorNA = "green", # <-------- color for NA values
palette = c("red", "orange", "yellow", "turquoise", "blue", "white")) +
tm_borders() +
tm_layout("Wealth (or so)",
legend.title.size = 1,
legend.text.size = 0.6,
legend.position = c("left","bottom"),
legend.bg.color = "white",
legend.digits = 5,
legend.bg.alpha = 1)
It looks like this: 它看起来像这样:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.