Skip to content
Prev 157157 / 398506 Next

Two overlaid density plots - Does order matter?

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: