# Plot TukeyHSD as Heatmap

Hi there,

how can I present the result of TukeyHSD as a heatmap?

``````set.seed (0)

#Daten erstellen
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

#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)
``````
1 Like

It can be done, but this doesn't appear to be a suitable object for that presentation.

``````# set.seed (0)
#
# #Daten erstellen
# 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
#
#
# #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)
#
# o <- TukeyHSD(model, conf.level=.95)\$group[,1:3]
#
# o <- data.frame(o)

# libraries
library(ggplot2)
library(reshape2)
# data (derived from TukeyHSD result)

o <- data.frame(
diff =
c(0.977741408697329, 2.54540241018403, 1.5676610014867),
lwr =
c(0.197946591105422, 1.76560759259213, 0.787866183894797),
upr =
c(1.75753622628924, 3.32519722777594, 2.34745581907861),
group =
c("B-A", "C-A", "C-B"))

cor(o[1:3])
#>      diff lwr upr
#> diff    1   1   1
#> lwr     1   1   1
#> upr     1   1   1
pairs(o[,1:3])
``````

``````
o <- o[,1:3]
h <- as.matrix(o)
heatmap(h)
``````

Created on 2022-11-27 by the reprex package (v2.0.1)

1 Like

Thank you so much!!!!

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.