Estimate the number of data entries per square inch of a figure. This implements Tufte's data-density measure. It can help you compare how much information different versions of a figure occupy on the page.
Value
An object of class tufte_density: a list with
density (entries per square inch), entries, rows,
variables and area.
Details
Entries are counted as pooled rows times the number of distinct variables
mapped to aesthetics. Constants outside aes() don't count.
Statistical layers and plots that combine data sources need care: the
function doesn't reconstruct a separate data matrix for each layer.
Panel area is estimated from the rendered plot. If that estimate isn't available, the function uses the whole canvas. I'd read the result alongside the entry count and the figure, since a high density doesn't establish that the information is useful.
Examples
library(ggplot2)
data_density(ggplot(mtcars, aes(wt, mpg)) + geom_point())
#>
#> ── Data density
#> 3.1 numbers per square inch of data graphic.
#> • 32 rows x 2 mapped variables = 64 entries
#> • over 20.83 square inches