ドットプロットの仕上げ

Tidyverseによるデータコミュニケーション

Timo Grossenbacher

Data Journalist

Tidyverseによるデータコミュニケーション

因子のレベル

  • 因子のレベルの順序が、ggplot2での表示順序を決定します。
ilo_data$country
Austria        Belgium        Czech Rep.     Finland       
France         Germany        Hungary    ...
 ...
 17 Levels: Austria Belgium Czech Rep. Finland France ... United Kingdom
Tidyverseによるデータコミュニケーション

forcatsパッケージによる因子の並べ替え

  • library(forcats) で読み込む
  • fct_drop:レベルの削除
  • fct_rev:レベルの逆順化
  • fct_reorder:レベルの並べ替え

1 詳細はtidyverse.org (http://forcats.tidyverse.org/) を参照
Tidyverseによるデータコミュニケーション

fct_reorder関数

ilo_data
# A tibble: 34 x 4
      country   year hourly_compensation working_hours
        <fct>  <fct>               <dbl>         <dbl>
 1    Austria   1996               24.75      31.99808
 2    Austria   2006               30.46      31.81731
 3    Belgium   1996               25.25      31.65385
 4    Belgium   2006               31.85      30.21154
ilo_data <- ilo_data  %>% 
    mutate(country = fct_reorder(country, working_hours, mean))
ilo_data$country
17 Levels: Netherlands Norway Germany Sweden ... Czech Rep.
Tidyverseによるデータコミュニケーション

Tidyverseによるデータコミュニケーション

hjustとvjustによるラベルの位置調整

ggplot(ilo_data) +
  geom_path(aes(...)) +
  geom_text(
        aes(...,
            hjust = ifelse(year == "2006", 
              1.4, 
              -0.4)
        )
    )
Tidyverseによるデータコミュニケーション

練習しましょう!

Tidyverseによるデータコミュニケーション

Preparing Video For Download...