d <- density(x)
pdf(“density.pdf”, 10, 10)
plot(d, xlim=c(-2,2), ylim=c(0,6), xlab=’RDD’)
I tried to use sm.density.compare() to plot multiple density plots together, but the densities shown did not correspond to those that I obtained when plotting separately.
A work around to this problem is to generate separate density plots using the code above and control xlim and ylim, making them equal in all plots.
xlim: receives a vector with min and max X axis values
ylim: receives a vector with min and max Y axis values
Then it’s possible to overlay them by opening the PDF files with Inkscape and using “paste in place”. It’s dirty, but does the trick when R doesn’t want to behave…