2015-10-01 38 views
4

我正在創建鳥類物種每年百分比變化的專題圖。這裏是我的代碼:如何操作tmap圖例?

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) 

當前所有的NA值都顯示爲灰色。我試圖改變調色板:

palette = c("red", "orange", "yellow", "turquoise", "blue", "white")) 

但這似乎並沒有工作。 NA值仍然是灰色的。我究竟做錯了什麼?

非常感謝!

回答

4

所以你試圖改變顏色專門爲NA值?爲tm_fill()提供的參數colorNA即可達到該目的。

下面是一個例子:

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) 

它看起來像這樣:

enter image description here

+0

非常感謝你WhiteViking。這正是我想要的。 :) – wallflower