6

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?

ECII
  • 10,297
  • 18
  • 80
  • 121
  • I imagine the complexity lies in whether the solution should automatically determine which "ink" corresponds to data and which doesn't. Is it as simple as saying: "background 'ink' is not data, the rest is?" – Jon Jan 12 '14 at 10:31
  • Not exactly. I am not trying to measure data-ink ratio but the just amount of ink of a plot (somehow resolution independent). If you know the "ink" of 2 plots plotting the same information (thus the "data ink" being the same) you can derive the data ink ratio yourself. – ECII Jan 12 '14 at 10:34
  • see https://github.com/ceteri/dataink as a starting point – Roman Pickl Jan 12 '14 at 10:35
  • 2
    If you rasterize (see `raster` package) two plots, you can measure the amount of "non white" points. This would get you close, especially if the two plots have the same amount of "background" ink in labels, axes, legend... – Roman Luštrik Jan 12 '14 at 10:36
  • See also: `http://stackoverflow.com/a/16788397/1412059` – Roland Jan 12 '14 at 10:38
  • I wonder if one of the packages from bioconductor would be of use? For example, EBImage? – DarrenRhodes Jan 12 '14 at 10:44
  • I'd do something like what @RomanLuštrik suggests, though might instead use `grid::grid.cap()` to create the bitmap raster. – Josh O'Brien Jan 12 '14 at 19:35

1 Answers1

6

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)                    
Josh O'Brien
  • 159,210
  • 26
  • 366
  • 455