막대형/점 그래프 다듬기

R로 배우는 시각화 베스트 프랙티스

Nick Strayer

Instructor

복잡한 막대그래프

who_disease %>% 
  filter(region == 'EMR', disease == 'measles', year == 2015) %>% 
  ggplot(aes(x = country, y = cases)) +
    geom_col()
R로 배우는 시각화 베스트 프랙티스

R로 배우는 시각화 베스트 프랙티스

막대 뒤집기

  • geom_bar()geom_col()은 y축에 범주를 둘 수 없음
    busy_bars <- who_disease %>% 
    filter(region == 'EMR', disease == 'measles', year == 2015) %>% 
    ggplot(aes(x = country, y = cases)) +
    geom_col() 
    
  • 그래서 축을 뒤집습니다!
busy_bars + coord_flip() # x, y 축 교체!
R로 배우는 시각화 베스트 프랙티스

R로 배우는 시각화 베스트 프랙티스

과도한 그리드

  • 막대그래프에는 평행한 그리드가 불필요함
  • 점 그래프는 점 위치에 맞는 그리드만 필요

R로 배우는 시각화 베스트 프랙티스

R로 배우는 시각화 베스트 프랙티스

세로 그리드 제거

plot <- who_disease %>% 
  filter(country == "India", year == 1980) %>% 
  ggplot(aes(x = disease, y = cases)) +
    geom_col()
# Remove vertical grid lines
 plot + theme(
    panel.grid.major.x = element_blank()
  )
R로 배우는 시각화 베스트 프랙티스

R로 배우는 시각화 베스트 프랙티스

점 그래프에 밝은 배경

  • 기본 회색 배경은 점에 대비가 낮을 수 있음
  • theme_minimal()로 간단히 개선
  • 점 크기를 키우면 더 잘 보임
who_subset %>% 
  ggplot(aes(y = reorder(country, cases_2016), x = log10(cases_2016))) +
  # Point size increased
  geom_point(size = 2) +
  # Theme minimal for light background
  theme_minimal()
R로 배우는 시각화 베스트 프랙티스

R로 배우는 시각화 베스트 프랙티스

연습해 봅시다!

R로 배우는 시각화 베스트 프랙티스

Preparing Video For Download...