ggpubr:在标签上显示显着性水平(***或n.s.)而不是p值

时间:2018-12-04 11:25:13

标签: r ggplot2 ggpubr

我想在R中使用***来显示线性回归中的显着性水平(n.s.ggpubr)作为标签。这似乎是通过使用{{1}完成的},发布在这里:https://www.r-bloggers.com/add-p-values-and-significance-levels-to-ggplots/

但是,当我在aes(label = ..p.signif..)中将..p.label..替换为..p.signif..时,stat_cor(aes(label = paste(..rr.label.., ..p.label.., sep = "~即stat_cor(aes(label = paste(.. rr.label ..,..p.signif ..,sep =“〜~"))〜”))'我的图更改没有任何变化,只是出现了一个错误:

,

请,我如何绘制星星(*,,* )或n.s。值而不是我的绘图上的确切p值?非常感谢您。

我的虚拟数据:(从http://www.sthda.com/english/articles/24-ggpubr-publication-ready-plots/78-perfect-scatter-plots-with-correlation-and-marginal-histograms/借来的)


Error in paste(rr.label, p.signif, sep = "~`,`~") : 
  object 'p.signif' not found 

enter image description here

1 个答案:

答案 0 :(得分:2)

您可以使用cut

ggscatter(df, x = "wt", y = "mpg",
          add = "reg.line",                         # Add regression line
          conf.int = TRUE,                          # Add confidence interval
          color = "cyl", palette = "jco",           # Color by groups "cyl"
          shape = "cyl"                             # Change point shape by groups "cyl"
)+
  stat_cor(aes(color = cyl,
               label =paste(..rr.label.., cut(..p.., 
                                              breaks = c(-Inf, 0.0001, 0.001, 0.01, 0.05, Inf),
                                              labels = c("'****'", "'***'", "'**'", "'*'", "'ns'")), 
                            sep = "~")), 
           label.x = 3)   

resulting plot showing significance stars

不用说,显示p值(甚至更好的是置信区间)会更好。