Home > Net >  Plot TukeyHSD as Heatmap
Plot TukeyHSD as Heatmap

Time:11-28

Can I present the result of TukeyHSD as a heatmap? And how would the code look like concerning the example below?

#Daten erstellen
set.seed (0)
data <- data.frame(group = rep(c("A", "B", "C"), each = 30),
               values = c(runif(30, 0, 3),
                          runif(30, 0, 5),
                          runif(30, 1, 7)))

#Die ersten sechs Zeilen anzeigen
head(data)

#einfaktorielles ANOVA-Modell anpassen
model <- aov(values~group, data=data)

#Sehen Sie sich die Modellausgabe an
summary(model)

#Tukey Test durchführen
TukeyHSD(model, conf.level=.95) 

#Konfidenzintervalle plotten
plot(TukeyHSD(model, conf.level=.95), las = 2)

Thank you so much!!

I actually get the right results, but can't display them as a heatmap.

CodePudding user response:

Here a way to do it with a tidyverse approach

library(dplyr)
library(lubridate)
library(tidyr)

data <- data.frame(group = rep(c("A", "B", "C"), each = 30),
                   values = c(runif(30, 0, 3),
                              runif(30, 0, 5),
                              runif(30, 1, 7)))

#einfaktorielles ANOVA-Modell anpassen
model <- aov(values~group, data=data)

#Tukey Test durchführen
test_list <- TukeyHSD(model, conf.level=.95) 

test_data <- test_list$group

test_data %>%
  as_tibble() %>% 
  bind_cols(data.frame(rw = rownames(test_data))) %>% 
  separate(rw,into = c("var1","var2")) %>% 
  ggplot(aes(x = var1,y = var2, fill = `p adj`)) 
  geom_tile() 
  geom_text(aes(label = p.adjust(`p adj`)), color = "white")

enter image description here

  • Related