繼續往下探索
在上一個練習中,SpatialPolygonsDataFrame 的 polygons 欄位裡有一個 Polygons 清單,而且清單中的每個 Polygons 物件也都有一個 Polygons 欄位。也就是說,有很多多邊形……但你還沒到這個階層結構的最底層!
我們再來看看 countries_spdf 的 Polygons 欄位中第 169 個元素。請執行上一個練習的這段程式碼:
one <- countries_spdf@polygons[[169]]
str(one, max.level = 2)
Polygons 欄位裡包含一個長度為 10 的清單。這些物件是什麼呢?我們繼續往下挖吧……
本練習屬於課程
在 R 視覺化地理空間資料
練習說明
- 對
one的Polygons欄位呼叫str(),並設max.level = 2。 - 對
one的Polygons欄位中第 6 個元素呼叫str(),並設max.level = 2。你有看到看起來像是空間資料的東西嗎? - 對
one的Polygons欄位中第 6 個元素的coords欄位呼叫plot()。你認得這個物件裡包含的是什麼資料嗎?
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
one <- countries_spdf@polygons[[169]]
# str() with max.level = 2, on the Polygons slot of one
# str() with max.level = 2, on the 6th element of the one@Polygons
# Call plot on the coords slot of 6th element of one@Polygons