我有两组数据需要在同一张图上绘制。一组非常大(〜10⁶),我想用六边形绘制,而另一组非常小(〜10 and),我想绘制点。如何在六边形上绘制点?
我最接近成功的是:
bin = hexbin(x, y)
plot(bin)
pushViewport(dataViewport(x, y))
grid.points(x, y)
感谢您的帮助:)
最佳答案
假设您正在使用 hexbin
软件包...
library(hexbin)
library(grid)
# some data from the ?hexbin help
set.seed(101)
x <- rnorm(10000)
y <- rnorm(10000)
z <- w <- -3:3
# hexbin
bin <- hexbin(x, y)
# plot - look at str(p)
p <- plot(bin)
# push plot viewport
pushHexport(p$plot.vp)
# add points
grid.points(z, w, pch=16, gp=gpar(col="red"))
upViewport()