平滑密度图,使其不会出现锯齿状

Smooth a density plot so that it doesn't appear saw toothed

我在 R 中绘制了密度图。我想去掉锯齿状图案,让它完全平滑。之所以会出现锯齿,是因为x$PLCO2的值都是整数。但出于审美原因,我想平滑情节。知道怎么做吗?

plot(density(x$PLCO2))

您可以通过增加 带宽 (bw)

使密度图更平滑
plot(density(x$PLCO2, bw = bw_bigger))

或者,您可以使用 adjust

plot(density(x$PLCO2, adjust = 2))

docs 说:

adjust: the bandwidth used is actually adjust*bw. This makes it easy to specify values like ‘half the default’ bandwidth.