セットを組み合わせる
前の演習で集計したデータは、batman_colors と star_wars_colors としてあらかじめ読み込まれています。可視化の前に、テーマごとの色を直接比較できるよう、これらのテーブルを結合しましょう。
batman_colors <- inventory_parts_themes %>%
filter(name_theme == "Batman") %>%
group_by(color_id) %>%
summarize(total = sum(quantity)) %>%
mutate(fraction = total / sum(total))
star_wars_colors <- inventory_parts_themes %>%
filter(name_theme == "Star Wars") %>%
group_by(color_id) %>%
summarize(total = sum(quantity)) %>%
mutate(fraction = total / sum(total))
この演習はコースの一部です
dplyr で行うデータの結合
実践的なインタラクティブ演習
このサンプルコードを完成させて、この演習に挑戦してみましょう。
batman_colors %>%
# Join the Batman and Star Wars colors
___(star_wars_colors, by = "color_id", suffix = c("_batman", "_star_wars")) %>%
# Replace NAs in the total_batman and total_star_wars columns
___ %>%
inner_join(colors, by = c("color_id" = "id"))