gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 19:25:55 24 4
gpt4 key购买 nike

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

但是,当我简单地替换..p.label..时通过..p.signif..在我的stat_cor(aes(label = paste(..rr.label.., ..p.label.., sep = "~ , ~")) IE。 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 值?非常感谢。

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

enter image description here

最佳答案

您可以使用剪切:

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 值(或者更好的是,显示置信区间)要好得多。

关于r - ggpubr:在标签中显示显着性水平(*** 或 n.s.)而不是 p 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53611916/

24 4 0