開始使用免費開始

整理圖例與最後微調

來做最後的微調,然後把圖存起來。

圖中的每個元素都可以調整。顏色是否合適?大小是否恰當?標籤是否直覺?你的目標是凸顯資料本身,並弱化非資料元素。

我們對這張圖有些想法。來一起調幾個地方吧。

本練習屬於課程

在 R 視覺化地理空間資料

檢視課程

練習說明

  • 在 tm_fill() 呼叫中加入 title = "Median Income" 與 palette = "Greens",讓顏色代表的意義更清楚,並將收入對應到綠色漸層色盤。
  • 加上一層 tm_borders(),設定 col = "grey60" 與 lwd = 0.5,替分區加上細邊界,使區界更清楚。
  • 讓鄰里邊界比分區邊界更重要一些,將其設定為 col = "grey40" 與 lwd = 2。
  • 使用 tm_credits() 新增資料來源致謝,第一個引數為 "Source: ACS 2014 5-year Estimates, \n accessed via acs package",第二個引數為 position = c("right", "bottom")。
  • 最後,使用 tmap_save() 函式將圖存為 "nyc_income_map.png",並設定引數 width = 4 與 height = 7。

動手互動練習

試著完成這個範例程式碼,體驗一下這個練習。

library(tmap)

tm_shape(nyc_tracts_merge) +
  # Add title and change palette
  tm_fill(col = "estimate", 
          ___,
          ___) +
  # Add tm_borders()
  ___ +
  tm_shape(water) +
  tm_fill(col = "grey90") +
  tm_shape(manhat_hoods) +
  # Change col and lwd of neighborhood boundaries
  tm_borders() +
  tm_text(text = "name", size = 0.5) +
  # Add tm_credits()
  
  
        
# Save map as "nyc_income_map.png"
編輯並執行程式碼