開始使用免費開始

用 ggplot2 製作點密度地圖

在本課程最後一個練習中,你要把已取得與產生的資料集合起來,使用 ggplot2 製作點密度地圖。你會用 geom_sf() 繪製你產生的點與輔助資料集,並加入一些有資訊性的製圖元素,做出一個完整的地圖成品。

本練習屬於課程

在 R 中分析美國人口普查資料

檢視課程

練習說明

  • 使用 geom_sf() 繪製你的 simple features 物件。
  • 透過正確指定你建立的物件來繪製水域與道路要素。
  • labs() 中使用 caption 參數,替你的地圖加入具資訊性的說明文字。

動手互動練習

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

# Plot your datasets and give your map an informative caption
___() + 
  ___(___ = dc_boundary, color = NA, fill = "white") + 
  ___(data = dc_dots, ___(color = group, fill = group), size = 0.1) + 
  ___(data = ___, color = "lightblue", fill = "lightblue") + 
  ___(data = ___, color = "grey") + 
  coord_sf(crs = 26918, datum = NA) + 
  scale_color_brewer(palette = "Set1", guide = FALSE) +
  scale_fill_brewer(___ = "Set1") +
  labs(title = "The racial geography of Washington, DC", 
       subtitle = "2010 decennial U.S. Census", 
       fill = "", 
       ___ = "1 dot = approximately 100 people.\nData acquired with the R tidycensus and tigris packages.")
編輯並執行程式碼