【问题标题】:How to format data.frame suitable for ggplot from pairwise.t.test output如何从pairwise.t.test输出格式化适合ggplot的data.frame
【发布时间】:2015-03-09 10:00:21
【问题描述】:

我的朋友

    df <- data.frame(
    measurement = runif(120, min=1, max=25),    
    group = rep(c("A","B","C","D"), each=3, times=10)
)

我将结果放入 data.frame

   ttest_results <- as.data.frame(pairwise.t.test(df$measurement, df$group)$p.value)

如何格式化适合绘制 ggplot 矩阵的 df?

【问题讨论】:

    标签: r ggplot2 dataframe


    【解决方案1】:

    这是使用 Hadley Universe 重塑数据的一种方法,即 dplyrtidyr

    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) 
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-08-27
      • 2015-07-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-07-01
      • 1970-01-01
      相关资源
      最近更新 更多