r - 如何在R中的hexbin图上绘制点?

标签 r plot scatter-plot points

我有两组数据需要绘制在同一张图上。一组非常大(~ 10⁶),我想用 hexbin 绘图,而另一组非常小(~ 10),我想绘制点。如何在 hexbin 上绘制点?
我离成功更近的是:

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

enter image description here

关于r - 如何在R中的hexbin图上绘制点?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29958561/

相关文章:

r - 如何在我的 knitr 文档中包含外部图形?

r - 错误:未安装ID为 'R'的语言。已安装的语言为:[]

R write(append = TRUE)覆盖文件内容

r - 在 R 中的情节图例中有小节?

r - 在 heatmap.2 中将行标签设为斜体

python - 如何刷新 Matplotlib 中的文本?

MATLAB - 在散点图上绘制多个数据集

python - 使用索引进行散点图图例

r - 使用 R 中的 GGplot2 更改 CGPfunctions::Plot2WayANOVA 图中图例和点形状的大小

python - 根据 matplotlib 中线图中的密度(存储在数组中)更改图的颜色