1

我想要的是成对比较,例如成对的 Wilcox 检验。与组:list(c("0.5", "1"),c("1","2"),c("2","3"))。起初非常简单,没有 alpha 校正等等。

代码:

data_summary <- function(data, varname, groupnames){
    require(plyr)
    summary_func <- function(x, col){
        c(mean = mean(x[[col]], na.rm=TRUE),
          sd = sd(x[[col]], na.rm=TRUE))
    }
    data_sum<-ddply(data, groupnames, .fun=summary_func,
                    varname)
    data_sum <- rename(data_sum, c("mean" = varname))
    return(data_sum)
}

    df_long <- rbind(ToothGrowth[,-2],data.frame(len=40:50,dose=3.0))
    df_long$ID <- data.table::rowid(df_long$dose)
    df_aggre<- data_summary(df_long, varname="len", 
                        groupnames=c("dose"))

    p<-
    ggplot(df_aggre, aes(x=dose, y=len)) +
        geom_errorbar(aes(ymin=len-sd, ymax=len+sd), width=.1) +
        geom_line() + geom_point() + theme_minimal()

期望的输出。(我想要红圈里的东西!)

添加了符号的图像

(发明了统计结果(例如 ns, , *))

我的尝试:

library(ggpubr)
p + stat_compare_means(data=df_long,mapping=aes(x=dose, y=len),label = "p.signif", method= "wilcox.test", comparisons=list(c("0.5","1"),c("1","2"),c("2","3")))

    #Error in f(...) : 
    #Can only handle data with groups that are plotted on the x-axis
4

2 回答 2

1

一种简单的方法是手动添加符号:

  p + annotate("text", x = 0.5, y = 23, label = "ns") +
  annotate("text", x = 1.5, y = 30, label = "**") +
  annotate("text", x = 2.5, y = 48, label = "***") 
于 2018-02-27T12:18:27.990 回答
1

根据this github repo issue,这是包的问题。作者的建议是手动计算 p 值并像这样使用它们:

geom_signif(annotations = c(formatC(annot_1, digits=3),formatC(annot_2, digits=3)), y_position = c(150, 180), xmin=c(1.2, 0.8), xmax=c(2.2, 1.8))

其中annot_1annot_2是预先计算的 p 值。

于 2018-02-27T12:24:53.510 回答