2

我有一个数据框,其中包含 x 和 y 坐标点的 1e7 个观测值。显然这会有点难以想象geom_point,所以我正在尝试使用geom_density_2d. 但这会遇到错误:

Warning messages:
1: Computation failed in `stat_density2d()`:
cannot allocate vector of size 2.6 Gb 
2: Computation failed in `stat_density2d()`:
cannot allocate vector of size 2.6 Gb 

我有哪些选择?我可以对重叠点进行分组并对它们进行计数,从而产生一个大约 1e5 次观察的数据框,但随后我丢失了很多密度信息(我无法找到一种方法让它识别每个点的计数)重叠点)。

如何geom_density2d在这种大小的数据框中使用?

编辑:我试图避免使用 hex 和 bin_2d 几何形状。

4

1 回答 1

2

您可以使用六边形分箱:

e <- runif(n = 10000000, -10, 10)
x <- rnorm(n = 10000000, 0, 10)
y <- 1+0.2*x+e
dat <- data.frame(y,x)
ggplot(dat,aes(x=x,y=y)) + stat_binhex()

在此处输入图像描述

或平滑图:

smoothScatter(x=dat$x,y=dat$y)

在此处输入图像描述

于 2018-08-20T17:59:39.337 回答