使用stat_smooth和错误的权力关系:“未知参数:开始”

时间:2016-08-23 17:22:10

标签: r ggplot2

这是我的数据

 Qmodelo <- c(10,25,50,75,100,125,150,175,200,225,250,275,300,325,350,375,400,425,450,475,500)
 Hmodelo <- c(73.57,111.39,152.31,181.50,204.73,225.42,243.94,259.77,273.95,287.90,299.20,309.62,319.15,328.17, 336.72, 344.84, 352.63, 360.11, 367.34, 374.31, 382.25)
 df2 <- data.frame(Qmodelo,Hmodelo)

所以我制作了我的scritp用于绘制幂关系并显示等式

power_eqn = function(df2, start = list(a =1,b=1)){
m = nls(Qmodelo ~ a*Hmodelo^b, start = start, data = df2);
eq <- substitute(italic(y) == a  ~italic(x)^b, 
               list(a = format(coef(m)[1], digits = 2), 
                    b = format(coef(m)[2], digits = 2)))
as.character(as.expression(eq));                 
}

lm_r <- function(df2){
m <- lm(Qmodelo ~ Hmodelo, df2);
eq2 <- substitute(italic(r)^2~"="~r2,list(r2=format(summary(m)$r.squared,digits = 4)))
as.character(as.expression(eq2)); 
}

RPotencial <- ggplot(df2,aes(x=Hmodelo,y=Qmodelo)) +
geom_point() + 
stat_smooth(method = 'nls', formula = Qmodelo ~ a*Hmodelo^b, se = FALSE, start = list(a =1,b=1)) +
geom_text(x = 130, y = 400, label = power_eqn(df2), parse = TRUE)+
geom_text(x = 140, y = 350, label = lm_r(df2), parse = TRUE)+
ylab(bquote('Gasto liquido ('*m^3~s^-1*')'))+
xlab(bquote("Altura (cm)"))+
ggtitle("Curva de gasto liquido Est. La Coja")

RPotencial

但是这个错误显示

Error: Unknown parameters: start

我猜这是因为系数范围不正确。我的问题是,是否有办法获得正确的范围。

0 个答案:

没有答案