Reputation: 842
My df
df <- data.frame(
measurement = runif(120, min=1, max=25),
group = rep(c("A","B","C","D"), each=3, times=10)
)
I put results into a data.frame
ttest_results <- as.data.frame(pairwise.t.test(df$measurement, df$group)$p.value)
How I can format df suitable for plotting a ggplot matrix?
Upvotes: 1
Views: 223
Reputation: 54247
Here's one way to reshape your data using the Hadley universe, namely dplyr
and tidyr
:
library(dplyr)
library(tidyr)
library(ggplot2)
ttest_results %>%
add_rownames("Group.1") %>%
gather("Group.2", "value", -Group.1) %>%
filter(!is.na(value)) %>%
ggplot(aes(Group.1, Group.2, fill = value)) +
geom_tile(height = .7, width = .7)
Upvotes: 1