ggpubr:在标签中显示显着性水平(*** 或 n.s。)而不是 p-value

ggpubr: Show significance levels (*** or n.s.) instead of p-value in the label

我想在我的线性回归中使用 R 中的 ggpubr 显示显着性水平(***n.s.)作为标签。这似乎是通过使用 aes(label = ..p.signif..) 发布于此:https://www.r-bloggers.com/add-p-values-and-significance-levels-to-ggplots/

但是,当我在 stat_cor(aes(label = paste(..rr.label.., ..p.label.., sep = "~ 中将 ..p.label.. 替换为 ..p.signif.. 时,~")) 即。 stat_cor(aes(label = paste(..rr.label.., ..p.signif.., sep = "~,~"))` 我的情节什么都没有改变,只是我得到一个错误:

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

请问,我该如何绘制星星 (*, , *) 或 n.s。我的地块上的值而不是精确的 p-values?非常感谢。

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


library(ggpubr)
data("mtcars")
df <- mtcars
df$cyl <- as.factor(df$cyl)

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.., ..p.label.., sep = "~`,`~")), # HOW TO CHANGE p.label to show stars???
           label.x = 3)           # Add correlation coefficient

您可以使用 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)   

不用说,显示 p 值(或者更好的是,显示置信区间)要好得多。