[R] Help in Overlaying of 2 Plots on the same Device.

Romain François francoisromain at free.fr
Fri Jan 14 23:43:02 CET 2005


Hello, it would be nice (as it is asked in the posting guide) to post 
something i can actually run on my machine, since i have no idea what 
are xvals, fr, .. i can only assume what you want.

1) if you want the second plot to overlay the first one (generated by 
hist) you might want to use ?points instead of plot.

2) Second, please look at the dimension of ds$y (usually 512) and the 
dimension of xvals[1:fr] (once more i can only assume), that's not the same.

3) It's not because you demand the density with values that lies in the 
interval [a,b] that the support of the density is [a,b], so it's not a 
problem to have that line. you may try

points(ds$x[someSubset],ds$y[someSubset],type="l")


Good luck with your problem (which is not perfectly clear for me, i'm 
not sure i got you clear)

Romain.

Jagarlamudi, Choudary a écrit :

> Thank you very much for your time and response.
> Idid the following:
> x1<-range(xvals)
> hist(xvals,xlim=x1,ylim=NULL)
> #now i'd like to plot a density plot only for the 1st 2 bars of the 
> histogram by passing xvals in that range.
> ds<-density(xvals[1:fr],bw=30,n=fr)
> plot(ds$y ~ xvals[1:fr])
>  
> My second plot creates its own axis and gives a line going across the 
> histogram(~10bars), when it should
> only extend upto the second bar coz i passed only values upto bar 2 
> range. I need to use the histogram axis for my second plot as well. 
> Please let me know if i can provide more detail.
> Thanks in advance.
>  
>  
> *Choudary Jagarlamudi*
> *Instructor*
> *Southwestern Oklahoma State University*
> *STF 254*
> *100 campus Drive*
> *Weatherford OK 73096*
> *Tel 580-774-7136*
>
> ------------------------------------------------------------------------
> *From:* Romain François [mailto:francoisromain at free.fr]
> *Sent:* Fri 1/14/2005 10:39 AM
> *To:* Jagarlamudi, Choudary
> *Subject:* Re: [R] Help in Overlaying of 2 Plots on the same Device.
>
> Is that what you are looking for ?
>
> x <- rnorm(50)
>
> hist(x,freq=F)
>
> points(density(x),type="l")
>
>
> PLEASE do read the posting guide! 
> http://www.R-project.org/posting-guide.html
>
> It will tell you to post some code of what you tried.
>
> Regards.
>
> Romain.
>
>
> Jagarlamudi, Choudary a écrit :
>
> >I'm trying to overlay a density plot on a previously plotted 
> histogram. However, i need to use the same axis as of the 
> 1st(histogram) plot to plot the second. My second plot is creating its 
> own axis and causing my plot to extend the entire histogram instead of 
> getting a subplot on a portion of the histogram. I tried 'fig' and 
> 'new' parameters with no luck.
> >Thanks in advance.
> >
> >Choudary Jagarlamudi
> >Instructor
> >Southwestern Oklahoma State University
> >STF 254
> >100 campus Drive
> >Weatherford OK 73096
> >Tel 580-774-7136
> > 
> >
>
> --
> Romain FRANCOIS : francoisromain at free.fr
> page web : http://addictedtor.free.fr/  (en construction)
> 06 18 39 14 69 / 01 46 80 65 60
> _______________________________________________________
> Etudiant en 3eme année
> Institut de Statistique de l'Université de Paris (ISUP)
> Filière Industrie et Services
> http://www.isup.cicrp.jussieu.fr/
> _______________________________________________________
>
>

-- 
Romain FRANCOIS : francoisromain at free.fr
page web : http://addictedtor.free.fr/  (en construction)
06 18 39 14 69 / 01 46 80 65 60
_______________________________________________________
Etudiant en 3eme année
Institut de Statistique de l'Université de Paris (ISUP)
Filière Industrie et Services
http://www.isup.cicrp.jussieu.fr/




More information about the R-help mailing list