/ jmablog / blog /

Which X-Men Character Had It Worst?

July 8, 2020

(Tidy Tuesday is a project to supply weekly data sets for R users to practice their coding skills on. You can find full details here.)

A little late, but I decided to have a go at Tidy Tuesday with the recent Claremont Run dataset, looking at Chris Claremont’s 16 year run writing for the Uncanny X-men comic.

Looking at the characters dataset provided, that describe some of the events that occur to each character in an issue, it seemed like being an X-Person was a pretty rough gig. I wondered, who got dealt the harshest hand during the entire Claremont run?

Poor Storm.

This also gave me a chance to (very slightly) play with the new across (docs) function in the latest dplyr release. I’ve seen a few blog posts from excited R users around singing it’s praises, so it was good to at least touch it, even if I clearly haven’t made the most of it here.

I also played with adorn_totals from the Janitor package for the first time, as well as adding an image to a plot with Cowplot’s draw_image. Random new functions - always my favourite thing about working with R.



# set theme with ggthemr

# import tidy tuesday data
data <- tt_load(2020, week=27)
characters <- data$characters

# summarise total instances the state occurred on each character across run
char_states_totals <- characters %>%
  select(-issue) %>%
  group_by(character) %>%
  summarise(across(is.numeric, sum)) %>%
  ungroup() %>%
  select(1:4, 6, 8) %>%
  janitor::adorn_totals("col", name = "total") %>%
  janitor::untabyl() %>%
  slice_max(total, n = 10) %>%
  select(character, total, everything()) %>%
  pivot_longer(3:7, names_to="state", values_to = "count") %>%
  separate(character, sep = " = ", into = c("codename", "name")) %>%
  mutate(codename = case_when(codename == "Ariel/Sprite/Shadowcat" ~ "Shadowcat",
                              codename == "Marvel Girl/Phoenix" ~ "Jean Grey",
                              TRUE ~ codename))

# create stacked column plot
plot <- char_states_totals %>%
  mutate(state = str_replace_all(state, "_", " "),
         state = str_replace_all(state, "subject", "subjected"),
         state = str_to_sentence(state)) %>%
  mutate(state = fct_reorder(state, count),
         codename = fct_reorder(codename, total)) %>%
  ggplot(aes(codename, count, fill = state)) +
  geom_col() + 
  coord_flip() +
  labs(title = "Which X-Men character had it worst?",
       subtitle = "During Chris Claremont's 1975-1991 run on Uncanny X-Men",
       x = "",
       y = "No. of Occurrences",
       fill = "")

# add storm image to plot
cowplot::ggdraw(plot) +
  cowplot::draw_image(here("xmen", "storm.jpg"), scale = .3, x = .37, y = .3) 

Previous Next

📎 Tags:

tidy tuesday r coding

📂 Recent posts in Blog: