動畫入門

R 的 plotly 互動式資料視覺化:中級

Adam Loy

Statistician, Carleton College

CO2 排放與所得

問題:二氧化碳排放與所得之間的關係,是否隨時間改變?

world_indicators
# A tibble: 11,387 x 11
  country  year income     co2 military population  urban life_expectancy four_regions
  <chr>   <dbl>  <dbl>   <dbl>    <dbl>      <dbl>  <dbl>           <dbl> <chr>       
1 Afghan…  1960   1210  0.0461       NA    9000000 7.56e5            38.6 asia        
2 Albania  1960   2790  1.24         NA    1640000 4.94e5            62.7 europe      
3 Algeria  1960   6520  0.554        NA   11100000 3.39e6            52   africa      
4 Andorra  1960  15200 NA            NA      13400 7.84e3            NA   europe      
5 Angola   1960   3860  0.0975       NA    5640000 5.89e5            42.4 africa      
# … with 1.138e+04 more rows, and 2 more variables: eight_regions <chr>, six_regions <chr>
R 的 plotly 互動式資料視覺化:中級

六個年份中,人均 GDP 對 CO2 排放的散佈圖。

R 的 plotly 互動式資料視覺化:中級

1989–2014 年,人均 GDP 對 CO2 排放的散佈圖。

R 的 plotly 互動式資料視覺化:中級

1985–2014 年,人均 GDP 對 CO2 排放的動畫散佈圖

R 的 plotly 互動式資料視覺化:中級

關鍵影格動畫

影格 = 單一時間點的圖

散佈圖底片帶。

R 的 plotly 互動式資料視覺化:中級

frame 美學

world_indicators %>%
  plot_ly(x = ~income, y = ~co2) %>%
  add_markers(frame = ~year, showlegend = FALSE) %>%
  layout(xaxis = list(type = "log"), yaxis = list(type = "log"))
R 的 plotly 互動式資料視覺化:中級

物件恆常性

一個圖形元素(例如圖徵)應對應到特定資料點(例如 Belgium)。

1990 年代點順序互換的 GIF。

R 的 plotly 互動式資料視覺化:中級

ids 美學

world_indicators %>%
  plot_ly(x = ~income, y = ~co2) %>%
  add_markers(frame = ~year, ids = ~country, showlegend = FALSE) %>%
  layout(xaxis = list(type = "log"), yaxis = list(type = "log"))

21-object-constancy-fixed.gif

R 的 plotly 互動式資料視覺化:中級

一起來練習吧!

R 的 plotly 互動式資料視覺化:中級

Preparing Video For Download...