首页 > 解决方案 > 在 ggplot 中显示 y~log(x) 函数的 R2 和 p 值

问题描述

我想ggplot用对数回归做一个,并想显示 R2 和 p 值。我试过stat_cor了,但它只显示线性回归的 R2 和 p 值。我试图将 "formula=y~log(x)" 合并到stat_cor,但 sais 未知参数:公式。我是否必须使用不同的功能才能做到这一点?

ggplot(data = Data,aes(x=Carbon_per,y=Pyrite_per,col=Ecosystem,shape=Ecosystem)) +
  geom_smooth(method='lm', formula=y~log(x))+
  geom_point() +
  stat_cor(aes(label = paste(..rr.label.., ..p.label.., sep = "~`,`~")))

干杯,格洛丽亚

标签: rggplot2non-linear-regressionp-value

解决方案


你在寻找这样的东西吗?

library(ggpubr)
library(ggplot2)
ggplot(data = mtcars, aes(x = log(wt), y = mpg)) +
                   geom_smooth(method = "lm", 
                               formula = y ~ x) +
                   geom_point() +
                   stat_cor(label.y = 40)+ 
                   stat_regline_equation(label.y = 45) 

在此处输入图像描述


推荐阅读