[R] plot centered line on barplot
Uwe Ligges
ligges at statistik.uni-dortmund.de
Fri Jul 20 13:09:45 CEST 2007
claudio.is at libero.it wrote:
> Dear R user,
>
> I need plot an histogram for the occurrence of a dataset, and then add a line corresponding to the freuqnecy of another similar dataset. in order to do this i used the function
>> hist_data1=hist(data1, breaks= seq(0,50,5), plot=FALSE)
>> hist_data2=hist(data2, breaks= seq(0,50,5), plot=FALSE)
>
> then I plotted the frequency
>
>> barplot(hist_data1$density)
>> lines(hist_data1$density)
barplot() returns the positions on x-axis (these may be non-integers)
where it draws the plots, hence you can say:
bp <- barplot(hist_data1$density)
lines(bp, hist_data1$density)
> but the line is shifted in respect to the center of the bars. how can I properly plot the line? another question. this is easy, how can I smooth the curve (not fit with loess of spline)?
If you do not tell us which kind of smoother you prefer ....
Uwe Ligges
>
> tnx
>
> --
> Claudio
> ______________________________________________
> R-help at stat.math.ethz.ch 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.
More information about the R-help
mailing list