Pairwise correlation from Dunnett’s rank test

Maybe this is what you are looking for

  1. Making use of dplyr, tidyr and stringr you can split your rownames into episodes and groups
  2. After the data wrangling you can get a heatmap via geom_tile, geom_text and facet_grid
  3. Finally, I made some adjustments to put the facet labels outside and to put the x-axis on the top.

levels <- paste0("Episode", c("One", "Two", "Three", "Four", "Five", "Six"))
labels <- paste("Episode", c("One", "Two", "Three", "Four", "Five", "Six"))
df1 <- df %>% 
  mutate(episodes = row.names(.)) %>% 
  separate(episodes, into = c("episode1", "episode2")) %>% 
  mutate(type1 = stringr::str_extract(episode1, ".$"), 
         type2 = stringr::str_extract(episode1, ".$"),
         across(c(episode1, episode2), ~ stringr::str_remove(., ".$")),
         across(c(episode1, episode2), ~ factor(., levels = levels, labels = labels)),
         across(c(type1, type2), ~ factor(., levels = c("M", "L"))))

ggplot(df1, aes(type1, forcats::fct_rev(type2), fill = pval)) +
  geom_tile() +
  geom_text(aes(label = scales::number(mean.rank.diff, accuracy = .1))) +
  facet_grid(episode1 ~ episode2, switch = "y") +
  scale_x_discrete(position = "top") +
  theme(strip.placement = "outside") +
  labs(x = NULL, y = NULL)

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top