Measure “ink” of a plot

情到浓时终转凉″ 提交于 2019-12-23 09:04:53

问题


I am reading on Tufte's data-ink ratio and I was wondering if it is possible to measure the amount of "ink" a plot uses?

If not possible in R perhaps with another tool such as GIMP or imagemagick?


回答1:


I'd suggest using grid.cap() to convert the contents of the graphics device to a raster, after which it's a simple matter to compute the proportion of non-white pixels (aka "ink"). In the following example, to focus the computations on ink in the plotting area, I've set par(mar=c(0,0,0,0)), but you can drop that line if you want to also examine the amount of ink in the axes, ticks, axis labels, title, etc.

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)                    


来源:https://stackoverflow.com/questions/21073587/measure-ink-of-a-plot

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!