2017-12-15 49 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은 데이터입니다. @dww (label = "p.signif" 사용)에 의해 상기 주어진

this plot

+0

그래서 0.31는 '*'로 표시 될뿐만 0.0051 '***'? – Heikki

+0

ggpubr에 익숙하지 않지만, 몇 가지 예를 살펴보면 아마도'label = "p.signif"'가 필요합니까? – dww

답변

2

용액 올바른이다

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 (비교 = cmpr, 팁. 길이 = 0.01, 레이블 = "p.signif", p.adjust.method = "bonferroni", symnum.args <--list (cutpoints = c (0, 0.0025, 0.05 , 1), symbols = c ("**", "*", "ns"))) 결과는 AD-VaD + 비교에서 symnum 인수를 반영하지 않는 세 개의 별표가 표시됩니다. –

+0

updated questions –