加入自訂 cognostics

使用 R 的 Trelliscope 視覺化巨量資料

Ryan Hafen

Author, TrelliscopeJS

以新變數作為 cognostics

傳入 ggplot() 的所有變數都會被檢查,作為 cognostics 的候選。

  • 若變數是數值,且在每個分面群組內會變動,會對每個面板計算一組摘要統計。
  • 若變數在每個分面群組內皆為常數,會對每個面板計算一個該值的 cognostic。
使用 R 的 Trelliscope 視覺化巨量資料

將最新預期壽命作為 cognostic

gap <- gapminder %>%
  group_by(country) %>%
  mutate(latestLifeExp = tail(lifeExp, 1))

gap
# A tibble: 1,704 x 7
# Groups:   country [142]
   country     continent  year lifeExp      pop gdpPercap latestLifeExp
   <fct>       <fct>     <int>   <dbl>    <int>     <dbl>         <dbl>
 1 Afghanistan Asia       1952    28.8  8425333       779          43.8
 2 Afghanistan Asia       1957    30.3  9240934       821          43.8
 3 Afghanistan Asia       1962    32.0 10267083       853          43.8
 4 Afghanistan Asia       1967    34.0 11537966       836          43.8
 5 Afghanistan Asia       1972    36.1 13079460       740          43.8
 6 Afghanistan Asia       1977    38.4 14880372       786          43.8
# ... with 1,698 more rows
使用 R 的 Trelliscope 視覺化巨量資料

將超連結作為 cognostics

gap <- gapminder %>%
  group_by(country, continent) %>%
  mutate(wiki = paste0("https://en.wikipedia.org/wiki/", country))

使用 R 的 Trelliscope 視覺化巨量資料

自訂 cognostics 的客製化

在 Trelliscope 中,可以用 cog() 包住變數,細部調整 cognostic 的行為。

使用 cog() 時,你可以設定的重點包含:

  • desc:為該 cognostic 提供有意義的說明
  • default_label:布林值,指定是否預設以標籤顯示該 cognostic
gap$wiki <- cog_href(gap$wiki, 
                     desc = "Link to wikipedia", 
                     default_label = TRUE)
使用 R 的 Trelliscope 視覺化巨量資料

一起來練習吧!

使用 R 的 Trelliscope 視覺化巨量資料

Preparing Video For Download...