In the following code, the only difference between the two plots is the order the variables are plotted. In this case, the plot of "cdata.den" in plot #1 is different from its plot in #2. Specifically, "cdata.den" spans the x-axis from -5 to 30 in plot #1 and from 0 to 20 in plot #2. Does anyone understand why these two plots do not yield the same result? #Make density objects pre.den<- density( preclaims[preclaims[,7]>cc1 & preclaims[,7]<cc2,7], from = cc1, to = cc2) cdata.den<-density(cdata,from=cc1,to=cc2) #Plot No. 1 x11() plot(cdata.den,col=1) lines(pre.den,col=2) #Plot No. 2 plot(pre.den,col=2) lines(cdata.den,col = 1) Regards, Stephen Collins, MPP | Analyst Health & Benefits | Aon Consulting 200 East Randolph, Suite 900, Chicago, IL Tel: 312-381-2578 | Fax: 312-381-0136 Email: stephen_collins@aon.com [[alternative HTML version deleted]]
Since you did not specify plotting limits (xlim, ylim) the plot-function automatically sets them to the range of your data, extended by some factor (depending on your axis style). If you draw another object afterwards with "line" this limits are not altered. So depending on the data range of the first object to be drawn your final result will be clipped to that actual range. So plot(pre.den, xlim=c(-5,30)) lines(cdata.den,col = 1) should correct the x-axis. You may notice, that this automatic process also applies to the y-axis, so yl<-range(pre.den$y,cdata.den$y) plot(pre.den, xlim=c(-5,30),ylim=yl) lines(cdata.den,col = 1) should produce the desired plot. hth. Stephen Collins schrieb:> In the following code, the only difference between the two plots is the > order the variables are plotted. In this case, the plot of "cdata.den" in > plot #1 is different from its plot in #2. Specifically, "cdata.den" spans > the x-axis from -5 to 30 in plot #1 and from 0 to 20 in plot #2. Does > anyone understand why these two plots do not yield the same result? > > #Make density objects > pre.den<- density( > preclaims[preclaims[,7]>cc1 & preclaims[,7]<cc2,7], > from = cc1, > to = cc2) > cdata.den<-density(cdata,from=cc1,to=cc2) > > #Plot No. 1 > x11() > plot(cdata.den,col=1) > lines(pre.den,col=2) > > #Plot No. 2 > plot(pre.den,col=2) > lines(cdata.den,col = 1) > > Regards, > > Stephen Collins, MPP | Analyst > Health & Benefits | Aon Consulting > 200 East Randolph, Suite 900, Chicago, IL > Tel: 312-381-2578 | Fax: 312-381-0136 > Email: stephen_collins at aon.com > > > [[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. >-- Eik Vettorazzi Institut f?r Medizinische Biometrie und Epidemiologie Universit?tsklinikum Hamburg-Eppendorf Martinistr. 52 20246 Hamburg T ++49/40/42803-8243 F ++49/40/42803-7790
this is not reproducible, but this may be the answer-- R graphic devices are like a pen and paper when you plot something it is there on the piece of paper then when you plot something else on top of that then if there are any points that intersect with the first plot then they will be plotted on top of the points from the old graph plot(1,1) plot(1,1, col="blue") On Thu, Sep 25, 2008 at 11:54 AM, Stephen Collins <Stephen_Collins at aon.com> wrote:> In the following code, the only difference between the two plots is the > order the variables are plotted. In this case, the plot of "cdata.den" in > plot #1 is different from its plot in #2. Specifically, "cdata.den" spans > the x-axis from -5 to 30 in plot #1 and from 0 to 20 in plot #2. Does > anyone understand why these two plots do not yield the same result? > > #Make density objects > pre.den<- density( > preclaims[preclaims[,7]>cc1 & preclaims[,7]<cc2,7], > from = cc1, > to = cc2) > cdata.den<-density(cdata,from=cc1,to=cc2) > > #Plot No. 1 > x11() > plot(cdata.den,col=1) > lines(pre.den,col=2) > > #Plot No. 2 > plot(pre.den,col=2) > lines(cdata.den,col = 1) > > Regards, > > Stephen Collins, MPP | Analyst > Health & Benefits | Aon Consulting > 200 East Randolph, Suite 900, Chicago, IL > Tel: 312-381-2578 | Fax: 312-381-0136 > Email: stephen_collins at aon.com > > > [[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. >-- Stephen Sefick Research Scientist Southeastern Natural Sciences Academy Let's not spend our time and resources thinking about things that are so little or so large that all they really do for us is puff us up and make us feel like gods. We are mammals, and have not exhausted the annoying little problems of being mammals. -K. Mullis