第一個繪圖
到目前為止,你已經讀入一些空間檔案,將空間資料轉換到相同的投影,並把資料框合併到空間物件。現在把這些工作整合起來,看看地圖的樣子。對每個資料集,你都需要先呼叫 tm_shape() 指定資料來源,接著用一個 tm_* 圖層(像是 tm_fill()、tm_borders() 或 tm_bubbles())把內容畫到地圖上。
首先,從上一個練習延續,將鄰里與水域加到你的繪圖中。
本練習屬於課程
在 R 視覺化地理空間資料
練習說明
- 為
water物件新增一個圖層,使用tm_shape()。接著用tm_fill(),並將顏色設為"grey90"。 - 同樣地,為
neighborhoods物件新增圖層。使用tm_borders()繪出鄰里的邊界線。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
library(tmap)
tm_shape(nyc_tracts_merge) +
tm_fill(col = "estimate") +
# Add a water layer, tm_fill() with col = "grey90"
tm_shape(___) +
tm_fill(___) +
# Add a neighborhood layer, tm_borders()
+