0

This is my data

 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)

So I make my scritp for ploting the power relation and show the equation

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

But this error show

Error: Unknown parameters: start

I guess that is because the range of coefficients is not correct. My question is if there is a way to get the correct range.

AnesG
  • 275
  • 2
  • 17

0 Answers0