使用ggplot2的权力关系

时间:2016-08-24 18:11:09

标签: 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)

因此,我编写了我的脚本,其中包含用于绘制幂关系的其他答案的代码并显示等式

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, method.args=list(start = c(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 in nls(Qmodelo ~ a * Hmodelo^b, start = start, data = df2) : 
number of iterations exceeded maximum of 50 

如何增加迭代次数?或者脚本中有错误

0 个答案:

没有答案