等值區域圖

使用 R 的 plotly 互動式資料視覺化

Adam Loy

Statistician, Carleton College

使用 R 的 plotly 互動式資料視覺化

800px-World_human_population_density_map.png

使用 R 的 plotly 互動式資料視覺化

在 plotly 繪製等值區域圖

head(turnout)
       state state.abbr turnout2018 turnout2014  ballots      vep      vap
1    Alabama         AL       0.474       0.332  1725000  3641209  3802714
2     Alaska         AK       0.537       0.548   280000   521777   554426
3    Arizona         AZ       0.486       0.341  2385000  4910625  5519036
4   Arkansas         AR       0.412       0.403   895000  2171940  2319740
5 California         CA       0.478       0.307 12250000 25635139 30836229
6   Colorado         CO       0.619       0.547  2540000  4103903  4445013
使用 R 的 plotly 互動式資料視覺化

在 plotly 繪製等值區域圖

turnout %>%

plot_geo(locationmode = 'USA-states') %>%
add_trace( z = ~turnout, # 設定顏色依據的數值 locations = ~state.abbr # 將資料列對應到多邊形 ) %>%
layout(geo = list(scope = 'usa')) # 地圖範圍僅限美國
使用 R 的 plotly 互動式資料視覺化

plot_geo() 的限制

locationmode:"USA-states" | "ISO-3" | "country names"

使用 R 的 plotly 互動式資料視覺化

地圖選項

scope = "usa"

  • "world" | "usa" | "europe" | "asia" | "africa" | "north america" | "south america"

projection = list(type = "mercator")

  • "conic conformal" | "mercator" | "robinson" | "stereographic" | 以及另外 18 種…

scale = 1

  • 值越大=縮放越近

center = list(lat = ~c.lat, lon = ~c.lon)

  • 設定 c.latc.lon 以置中地圖
使用 R 的 plotly 互動式資料視覺化

開始來做地圖吧!

使用 R 的 plotly 互動式資料視覺化

Preparing Video For Download...