我正在阅读 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)
关于r - 测量绘图的 "ink",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21073587/