我正在尝试使用 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,10,1,0.3,0.25,0.2,0.1,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, 0.1,10,1000), labels= c(0,0.1, 10,1000))
当 x 截距为 35 时,如何获得最佳拟合回归线和方程?另外,我怎样才能让线接触x轴?