開始使用免費開始

使用 plot() 的 sf 視覺化

如你所見,sf 物件可以用 base R 的 plot() 函式繪圖。第一張圖會作為地圖的底圖,接著可以用 plot() 疊加後續圖層。

以下有四個 sf 物件,分別為:

  • london_poly
  • london_loop
  • london_capital
  • num_listings

完成下方程式碼,使用 plot() 將這些 sf 物件拼在一起,得到一張地理空間地圖。繪圖時請用 st_geometry() 確認所有物件確實以 sf 幾何型態呈現。

已經載入 sftidyverse 函式庫。

本練習屬於課程

使用 shinydashboard 建立儀表板

檢視課程

練習說明

  • 繪出第一層為多重多邊形(multipolygon)的 london_poly
  • 繪出 london_loop,並設為紫色。
  • 繪出 london_capital,並設為綠色。
  • num_listings 中的每個點加上紅色標記。

動手互動練習

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

# Plot the first layer which is a multipolygon
___(___(london_poly), 
     col = sf.colors(length(london_poly$Name), 
                     categorical = TRUE), 
     axes=TRUE, border=grey(0.2, 0.5))
# Plot london_loop and color it purple
___(___(london_loop), add=___, col=___)
# Plot london_capital and color it green
___
# Add red markers for each point in num_listings
___
編輯並執行程式碼