Hi, I don't quite understand what you want. But perhaps, you would like to try this
hist(datobs) lines(density(datobs)) and get some ideas Best, Ruihong On 05/07/2010 02:42 AM, Roslina Zakaria wrote: > Hi r-users, > > I would like to overlap a smooth line on the histogram. I tried using spline > but it does not work. > > sq<- seq(0,900,by=50) > sq.50<- as.character(sq) > datobs<- sum_pos > ## first, plot histogram > histo<- hist(datobs,breaks=sq,freq=F) > ## extract counts from histogram and calculate the probability in > ## each specified interval. Also check the length of the interval is > ## the same with the length of the fitted model. > hct<- c(0,histo$counts)/length(datobs) > ## use barplot and lines to overlap the observed and fitted data > > >> y<- pdf_formula.2*50 >> > [1] 0.000000e+00 2.422196e-01 2.445114e-01 1.826918e-01 1.236800e-01 > 7.965830e-02 4.978001e-02 3.048459e-02 1.839873e-02 > [10] 1.098342e-02 6.500920e-03 3.821499e-03 2.233833e-03 1.299656e-03 > 7.531443e-04 4.349116e-04 2.494558e-04 1.365303e-04 > [19] 6.142313e-05 > > barplot.x.location<- > barplot(hct, ylim=c(0,0.25),col="yellowgreen", > main="Observed data and fitted gamma sum", > xlab="Rainfall (mm)", ylab="Relative frequency", > names.arg = sq.50, axisnames = TRUE, axis.lty=1, > cex.axis= 0.8,cex.names= 0.8, xaxs='i', yaxs='i') > lines(x = barplot.x.location, y = pdf_formula.2*50, > col = "red", pch = 7, lwd=3, cex.axis= 0.7) > > Thank you for any help given. > > > > > > [[alternative HTML version deleted]] > > > > > ______________________________________________ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > [[alternative HTML version deleted]] ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.