Get startedGet started for free

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

This exercise is part of the course

Joining Data with dplyr

View Course

Exercise instructions

  • 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.

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# 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")
Edit and Run Code