[R] trying to superimpose a line plot onto a histogram

Edwin Lei unlucky24 at hotmail.com
Sun Jul 6 07:07:15 CEST 2008


I tried that, but for some reason the scale is wrong? So the density doesn't show up on the histogram.  Also, I'd prefer not to use the density because I don't want the line plot to begin at a value of 0. I'm trying to emulate an exponential decay.

Thanks for the help.

> -----Original Message-----
> From: markleeds at verizon.net [mailto:markleeds at verizon.net]
> Sent: July 5, 2008 8:43 PM
> To: Edwin Lei
> Subject: Re: [R] trying to superimpose a line plot onto a histogram
> 
> 
> hi: you can do the same thing as below but just replace density(x) with
> whatever you want to plot ?
> 
> 
> On Sat, Jul 5, 2008 at  4:29 PM, Edwin Lei wrote:
> 
> > Thanks for the quick response. But the points I'm trying to
> > superimpose
> > isn't exactly the density of the data. Is there any other way to do
> > it?
> >
> >
> > From: milton ruser [mailto:milton.ruser at gmail.com] Sent: July 5, 2008
> > 6:56 AM
> > To: Edwin Lei
> > Cc: r-help at r-project.org
> > Subject: Re: [R] trying to superimpose a line plot onto a histogram
> >
> >
> > How about the answer by Demitris?
> >
> >
> > Regards a lot,
> >
> >
> > miltinho
> >
> > ----
> >
> > From: Dimitris Rizopoulos <dimitris.rizopoulos at med.kuleuven.be>
> > Date: Jun 16, 2008 4:05 AM
> > Subject: Re: [R] Superimposing Line over Histogram in Density Plot
> > To: Gundala Viswanath <gundalav at gmail.com>
> > Cc: r-help at stat.math.ethz.ch
> >
> > try something like this:
> >
> > x <- rnorm(200)
> > hist(x, col = "blue", freq = FALSE)
> > lines(density(x), col = "red", lwd = 2)
> >
> >
> >
> >
> >
> > On 7/5/08, Edwin Lei <unlucky24 at hotmail.com> wrote:
> > Hello,
> >
> > I'm trying to superimpose a line plot onto a histogram but I'm not
> > having
> > any luck. I've attached the dataset. What I did was:
> >
> >> hist(data,freq=F)
> >
> > Now I'm trying to superimpose the following points with a line
> > connecting
> > them onto the histogram:
> >
> > x            y
> > 100  0.535665393824959
> > 200  0.212744329736556
> > 300  0.0844933242968584
> > 400  0.0335572838043417
> > 500  0.0133275771274986
> > 600  0.00529316714442912
> > 700  0.0021022289461042
> > 800  0.000834919136549392
> > 900  0.000331595645597124
> > 1000 0.000131696193518099
> > 1100 5.2304327929049e-05
> > 1200 2.07731343406939e-05
> >
> > Basically, the x values correspond to the break points in the
> > histogram.
> > Next I used the command
> >
> >> points(x,y,type="l")
> >
> > But for some reason, the line plot is shifted to the right and
> doesn't
> > line
> > up with the histogram.
> >
> > Thanks for the help!
> >
> > Edwin Lei
> >
> > ______________________________________________
> > R-help at r-project.org mailing list
> >
> > 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 at 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.



More information about the R-help mailing list