我建议使用grid.cap()将图形设备的内容转换为光栅,之后计算非白色像素(也就是"墨水")的比例是一件简单的事情.在下面的示例中,为了将计算集中在绘图区域中的墨水上,我已设置par(mar=c(0,0,0,0)),但如果您还要检查轴,刻度,轴标签,标题等中的墨水量,则可以删除该行.
library(grid)
## Plot to R's default graphical device
opar <- par(mar=c(0,0,0,0))
plot(rnorm(1e4), rnorm(1e4), pch=16)
## Capture contents of the graphics device as a raster (bitmap) image
p <- grid.cap()
## Compute the proportion of pixels that are not white (i.e. are inked in)
sum(p!="white")/length(p)
# [1] 0.2414888
## Restore pre-existing graphical parameters
par(opar)
Run Code Online (Sandbox Code Playgroud)