想要繪製density
對象時,我有一個問題。例如,考慮發行繪製`density`當對象
require(grDevices)
set.seed(43)
d0 = density(rexp(1e5,rate=1))
d1 = density(rexp(1e5,rate=1.8))
plot(d1, col="white", xlab = "x", ylab="Density", main = "")
polygon(d1, col=adjustcolor("blue", alpha.f=0.2))
lines(d0, col="white")
polygon(d0, col=adjustcolor("red", alpha.f=0.2))
目前,它看起來如我所料。縮放Y軸的低值時出現問題。考慮例如
plot(d1, col="white", xlim=c(2.5,3), xlab = "x", ylab="Density", main = "",
ylim=c(0,0.02))
polygon(d1, col=adjustcolor("blue", alpha.f=0.2))
lines(d0, col="white", xlim=c(2.5,3), ylim=c(0,0.02))
polygon(d0, col=adjustcolor("red", alpha.f=0.2))
奇怪的是,多邊形的下部未達到密度= 0。此外,一個多邊形結束其中一個比另一個低。設置yaxs="i"
和xaxs="i"
時,問題仍然存在。
這是怎麼回事,如何解決這個問題呢?
有了一些個人資料,我得到的東西像
此解決方案有點「更好地處理原因」有;) – AkselA