기본 누적 막대 그래프
이전 연습 문제에서 파이 차트와 와플 차트를 만들 때는 모든 연도를 합쳐서 살펴봤어요.
이제는 시간이 지나면서 패턴이 어떻게 변하는지 보려고 합니다. 이를 위해 관측 연도를 x축으로 두고 누적 막대 그래프를 그릴 거예요. 이전에 파이 차트를 만들 때처럼 데이터를 measles, mumps, other로 단순화하겠습니다.
이렇게 시각화해 보니, 데이터에서 특이한 점이 보이나요?
이 연습은 강의의 일부입니다
R로 배우는 시각화 베스트 프랙티스
연습 안내
aes()호출을 수정해 연도를 x축에 매핑하세요.geom_col()의position인수를 조정해 막대가 y축 전체를 채우도록 하세요.
실습형 인터랙티브 연습
이 예제를 이 샘플 코드를 완성하여 풀어보세요.
disease_counts <- who_disease %>%
mutate(disease = ifelse(disease %in% c('measles', 'mumps'), disease, 'other')) %>%
group_by(disease, year) %>% # note the addition of year to the grouping.
summarise(total_cases = sum(cases))
# add the mapping of year to the x axis.
ggplot(disease_counts, aes(___, y = total_cases, fill = disease)) +
# Change the position argument to make bars full height
geom_col(___)