3

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

但是,当我简单地替换my中的..p.label..by时,即。stat_cor(aes(label = paste(..rr.label.., ..p.signif.., sep = "~ ~"))` 我的情节没有任何变化,只是我得到一个错误:..p.signif..stat_cor(aes(label = paste(..rr.label.., ..p.label.., sep = "~~")),

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

请问,我怎样才能在我的情节上绘制星星(*、、*)或 ns 值而不是精确的 p 值?非常感谢您。

我的虚拟数据:(借自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

在此处输入图像描述

4

1 回答 1

3

您可以使用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 值(或者甚至更好的是置信区间)要好得多。

于 2018-12-04T11:36:39.390 回答