점 그래프 다듬기

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...