I have a barplot for which the second half should fit to this formula:
y~a*x*exp(-b*x^2)
. Now I want to plot the entire barplot and display the fitted model over the last part of the barplot as it only holds for that part. However, I cannot find a way to display the line-graph only over the second half. If I just do something like
submitted=c(1L, 1L, 1L, 1L, 1L, 1L, 2L, 1L, 2L, 2L, 3L, 2L, 1L, 1L, 4L,
3L, 2L, 11L, 6L, 2L, 16L, 7L, 17L, 36L, 27L, 39L, 41L, 33L, 42L,
66L, 92L, 138L, 189L, 249L, 665L, 224L, 309L, 247L, 641L, 777L,
671L, 532L, 749L, 506L, 315L, 292L, 281L, 130L, 137L, 91L, 40L,
27L, 34L, 19L, 1L)
x=seq(0:(length(submitted)-1))
y1=rs$submitted[30:(length(submitted)-1)]
x1=seq(0:(length(y1)-1))
fit1=nls(y1~a*x1*exp(-b*x1^2),start=list(a=500,b=.01),trace=TRUE)
barplot(submitted,names.arg=x, las=2, cex.axis=0.8, cex=0.8)
lines(predict(fit1))
The line is displayed, but in the wrong position. So how can I control where the line is drawn?