Skip to content

Two overlaid density plots - Does order matter?

3 messages · Stephen Collins, Eik Vettorazzi, stephen sefick

#
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:

  
    
#
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: