可视化差异:Batman 与 Star Wars
在上一个练习中,您创建了 colors_joined。现在,您将绘制一个柱状图,每种颜色(name)对应一根柱子,展示比例差值。
由于因子和可视化超出了本课程的范围,我们已为您完成了一些预处理:下面是用于视频中 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")