1. 学ぶ
  2. /
  3. コース
  4. /
  5. dplyr で行うデータの結合

Connected

演習

差を可視化する:Batman と Star Wars

前の演習では、colors_joined を作成しました。ここでは各色(name)ごとに 1 本のバーを持つ棒グラフを作り、比率の差を表示します。

このコースの範囲を超える要素(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)) 

指示

100 XP
  • colors_joined テーブルを使って棒グラフを作成し、Batman と Star Wars テーマで目立つ色を表示します。バーの色分けはそれぞれの name によって行ってください。