1. Learn
  2. /
  3. Courses
  4. /
  5. Joining Data with dplyr

Connected

Exercise

Visualizing the difference: Batman and Star Wars

In the last exercise, you created colors_joined. Now you'll create a bar plot with one bar for each color (name), showing the difference in fractions.

Because factors and visualization are beyond the scope of this course, we've done some processing for you: here is the code that created the colors_joined table that will be used in the video.

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)) 

Instructions

100 XP
  • Create a bar plot using the colors_joined table to display the most prominent colors in the Batman and Star Wars themes, with the bars colored by their name.