R ggplot2 geom_density2d,有数百万次观测

R ggplot2 geom_density2d,有数百万次观测,r,ggplot2,R,Ggplot2,我有一个带有1e7观测值的数据框,用于具有x和y坐标的点。显然,使用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 allocat

我有一个带有1e7观测值的数据框,用于具有x和y坐标的点。显然,使用
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\u density2d


编辑:我试图避免六边形和Binu 2d几何体。

您可以使用六边形装箱:

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()

如果您在windows或32位R上运行。
smoothScatter(x=dat$x,y=dat$y)