2017-12-15 75 views
1

私はggplot2とggpubrで次のプロットを作成しました。私はVaD +とHCとの間の有意性を示したいと思います。私はp値をアスタリスクに変更したいと思います。私はsymnum.argsを使うべきだと思いますが、私が試してみると変わりません。複数のグループを持つボックスプロットのggplot2で有意性を示す

myplot <- ggplot(my.data, aes(x = DX, y = CC, fill=DX)) + geom_boxplot() + ggtitle("Corpus Collasum") + theme(text=element_text(size = 16), panel.grid.major = element_blank(), panel.grid.minor = element_blank(),panel.background = element_blank(), axis.line = element_line(colour = "black"), plot.title = element_text(lineheight=.8, face="bold", hjust=0.5)) + scale_y_continuous(name = bquote('Volume in'~mm^3)) + scale_x_discrete(name = "Diagnosis", labels = c("AD","HC","VaD-","VaD+")) + scale_fill_brewer(palette="OrRd", name="Diagnosis", labels=c("AD","HC","VaD-","VaD+")) + geom_jitter(width = 0) 
cmpr <- list(c("VaDD","HC"), c("AD","VaDD")) 
myplot + stat_compare_means(comparisons = cmpr, tip.length=0.01, symnum <- list(cutpoints = c(0, 0.0001, 0.001, 0.01, 0.05, 1), symbols = c("****", "***", "**", "*", "ns"))) 

基本的に、数字のp値を記号で置き換えたいと思います。

Hereはデータです。

this plot

+0

したがって、0.31は「*」、0.0051は「***」と表示されますか? – Heikki

+0

実際にggpubrに詳しいことはありませんが、いくつかの例を見ると 'label =" p.signif "'が必要ですか? – dww

答えて

2

@dwwことにより、上記所定の溶液(label = "p.signif"を使用)正しいものである:

cmpr <- list(c("VaD+","HC"), c("AD","HC")) 
myplot + stat_compare_means(comparisons = cmpr, tip.length=0.01, 
     label = "p.signif", 
     symnum.args = list(cutpoints = c(0, 0.0001, 0.001, 0.01, 0.05, 1), 
     symbols = c("****", "***", "**", "*", "ns"))) 

enter image description here

EDIT:この関数は無視するように見えるので、私はstat_compare_means修飾symnum.args

my_stat_compare_means <- function (mapping = NULL, data = NULL, method = NULL, paired = FALSE, 
    method.args = list(), ref.group = NULL, comparisons = NULL, 
    hide.ns = FALSE, label.sep = ", ", label = NULL, label.x.npc = "left", 
    label.y.npc = "top", label.x = NULL, label.y = NULL, tip.length = 0.03, 
    symnum.args = list(), geom = "text", position = "identity", 
    na.rm = FALSE, show.legend = NA, inherit.aes = TRUE, ...) 
{ 
    if (!is.null(comparisons)) { 
     method.info <- ggpubr:::.method_info(method) 
     method <- method.info$method 
     method.args <- ggpubr:::.add_item(method.args, paired = paired) 
     if (method == "wilcox.test") 
      method.args$exact <- FALSE 
     pms <- list(...) 
     size <- ifelse(is.null(pms$size), 0.3, pms$size) 
     color <- ifelse(is.null(pms$color), "black", pms$color) 
     map_signif_level <- FALSE 
     if (is.null(label)) 
      label <- "p.format" 
     if (ggpubr:::.is_p.signif_in_mapping(mapping) | (label %in% "p.signif")) { 
      if (ggpubr:::.is_empty(symnum.args)) { 
       map_signif_level <- c(`****` = 1e-04, `***` = 0.001, 
        `**` = 0.01, `*` = 0.05, ns = 1) 
      } else { 
       map_signif_level <- symnum.args 
      } 
      if (hide.ns) 
       names(map_signif_level)[5] <- " " 
     } 
     step_increase <- ifelse(is.null(label.y), 0.12, 0) 
     ggsignif::geom_signif(comparisons = comparisons, y_position = label.y, 
      test = method, test.args = method.args, step_increase = step_increase, 
      size = size, color = color, map_signif_level = map_signif_level, 
      tip_length = tip.length, data = data) 
    } else { 
     mapping <- ggpubr:::.update_mapping(mapping, label) 
     layer(stat = StatCompareMeans, data = data, mapping = mapping, 
      geom = geom, position = position, show.legend = show.legend, 
      inherit.aes = inherit.aes, params = list(label.x.npc = label.x.npc, 
       label.y.npc = label.y.npc, label.x = label.x, 
       label.y = label.y, label.sep = label.sep, method = method, 
       method.args = method.args, paired = paired, ref.group = ref.group, 
       symnum.args = symnum.args, hide.ns = hide.ns, 
       na.rm = na.rm, ...)) 
    } 
} 

symnum.args <- c("**"=0.0025,"*"=0.05,ns=1) 
myplot + my_stat_compare_means(comparisons = cmpr, tip.length=0.01, 
      label = "p.signif", symnum.args = symnum.args) 

enter image description here

+0

私はこれが働いていると思ったが、そうではないようだ。 compare_means()でsymnum.args引数を使用すると、テーブルには新しいカットオフポイントが反映されます。しかし、私がstat_compare_means()で同じものを使用すると、ラベルは変更されていないように見えます。 –

+0

'myplot + stat_compare_means(cutpoints = c(0、0.0025、0.05)、myplot + stat_compare_means(比較= cmpr、tip.length = 0.01、ラベル=" p.signif "、p.adjust.method =" bonferroni "、symnum.args < 、1)、symbols = c( "**"、 "*"、 "ns"))) 'は、symnumの引数を反映しない3つのアスタリスクを持つAD - VaD +の比較結果になります。 –

+0

更新された質問 –

関連する問題