시작하기무료로 시작하기

차이 시각화: Batman과 Star Wars

이전 연습 문제에서 colors_joined를 만들었어요. 이제 각 색(name)에 대해 막대 하나씩, 비율 차이를 보여주는 막대 그래프를 만들어 볼 거예요.

요인(factor)과 시각화 내용은 이 강의 범위를 벗어나므로, 일부 전처리는 미리 해 두었습니다. 아래 코드는 영상에서 사용할 colors_joined 테이블을 만드는 데 사용된 코드예요.

colors_joined <- batman_colors %>%
  full_join(star_wars_colors, by = "color_id", suffix = c("_batman", "_star_wars")) %>%
  replace_na(list(total_batman = 0, total_star_wars = 0)) %>%
  inner_join(colors, by = c("color_id" = "id")) %>%
  mutate(difference = fraction_batman - fraction_star_wars,
         total = total_batman + total_star_wars) %>%
  filter(total >= 200) %>%
  mutate(name = fct_reorder(name, difference)) 

이 연습은 강의의 일부입니다

dplyr로 데이터 결합하기

강의 보기

연습 안내

  • colors_joined 테이블을 사용해 Batman과 Star Wars 테마에서 두드러지는 색을 보여주는 막대 그래프를 만들고, 막대의 색은 각 name으로 지정하세요.

실습형 인터랙티브 연습

이 예제를 이 샘플 코드를 완성하여 풀어보세요.

# Create a bar plot using colors_joined and the name and difference columns
ggplot(___, aes(___, ___, fill = ___)) +
  geom_col() +
  coord_flip() +
  scale_fill_manual(values = color_palette, guide = "none") +
  labs(y = "Difference: Batman - Star Wars")
코드 편집 및 실행