我正在阅读Tufte的data-ink ratio,我想知道是否有可能测量某样地使用的“墨水”量?

如果在R中无法实现,也许可以使用诸如GIMP或imagemagick之类的其他工具?

最佳答案

我建议使用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)

10-05 21:00
查看更多