用ggplot2上的已知x截距拟合三阶多项式

问题描述

我正在尝试使用stat_smoth在ggplot2上拟合三阶多项式,但想强制回归线通过已知的x截距(以下可重现示例为35)。

示例:

x<-c(1,2,3,5,10,12,15,20,22,25,30,33,37)
y<-c(1000,800,100,1,0.3,0.25,0.2,0.1,0.03,0.05,0.03)
myformula<-y ~ poly(x,3)
ggplot(df,aes(x,y)) + stat_smooth(method = lm,formula = myformula) + geom_point() + 
stat_smooth(method = lm,formula = myformula) +
stat_poly_eq(formula = myformula,eq.with.lhs = "italic(psi)~`=`~",eq.x.rhs = "~italic(theta)",aes(label = paste(..eq.label..,..rr.label..,sep = "~~~~")),label.x=0.15,parse = TRUE)+ 
xlim(0,40)+  ylim(0,2000)+ 
scale_y_log10(breaks = c(0,1000),labels= c(0,1000))

enter image description here

当x截距为35时,如何获得最佳拟合回归线和方程式? 另外,如何使线接触x轴?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...