虽然@bill_080 的回答直接回答了您的问题,但这真的是您想要的吗?如果你想在上面绘制,你必须仔细对齐你的坐标系。参见例如Houston Crime Map ggplot2 如何做到这一点。
对于您的问题,在我看来,可能有一个更简单的解决方案:分箱,即 ceating 2d histograms。
> df <- data.frame (x = rnorm (1e6), y = rnorm (1e6))
> system.time (plot (df))
User System verstrichen
54.468 0.044 54.658
> library (hexbin)
> system.time (binned <- hexbin (df, xbins=200))
User System verstrichen
0.252 0.012 0.266
> system.time (plot (binned))
User System verstrichen
0.704 0.040 0.784
hexbin 直接使用 lattice 和 ggplot2,但 bin 的中心坐标位于 binned@xcm 和 binned@ycm,因此您也可以在基本图形中绘制结果。通过大量的 bin,您可以获得原始绘图的快速版本:
> system.time (plot (binned@xcm, binned@ycm, pch = 20, cex=0.4))
User System verstrichen
0.780 0.004 0.786
但是你可以很容易地用颜色来编码密度:
> plot (binned@xcm, binned@ycm, pch = 20, cex=0.4, col = as.character (col))
> col <- cut (binned@count, 20)
> levels (col) <- grey.colors (20, start=0.9, end = 0)
> plot (binned@xcm, binned@ycm, pch = 20, cex=0.4, col = as.character (col))