【发布时间】:2017-05-09 18:46:19
【问题描述】:
我试图在我的密度图上为seq(-3, 3) [即 7 个数字] 获取一些 points。我得到了 7 个相应的密度值,但是当我尝试执行 points 时,我得到:
Error in xy.coords(x, y) : 'x' and 'y' lengths differ
由于确实没有长度差异,我假设在 x 和 y 之间存在 class() 差异问题 points()。
我很欣赏解决方案?
这里是 R 代码:
positions = rnorm(1e4)
DENS = density(positions, adjust = 2, n = 1e4)
x.DENS = DENS$x
y.DENS = DENS$y
plot( DENS, col = "red", lwd = 3, xlab = "Positions",
ylab = "Density", xlim = c(-6, 6), main =
NA, bty = 'n', zero.line = F)
x.DENS.2 = seq(-3, 3)
y.DENS.2 = approx(x.DENS, y.DENS, xout = x.DENS.2 ) ## get the x.DENS.2 density values
points(x.DENS.2, y.DENS.2) ## Error
【问题讨论】:
标签: r class kernel-density probability-density density-plot