Log-Histogram bins in R: hist(log(x)) vs hist(x, log = "x)

Viewed 141

My question is how to properly implement logarithmic bins for histograms in R? The following test case highlights my issue. Given some lognormally distributed data that has been left-truncated, we try and plot the histogram. Depending on if you plot the histogram directly of the log-transformed data, versus you use a log-axis, you can have 2 drastically different interpretations of the data. Method 1 seems to be wrong, as you actually have a linear axis from ~3 to ~ 8, but Method 2 seems to erase the lognormal that is obviously there. Without truncation, Method 1 also seems to be preferrable.

sln <- rlnorm(5e3, 10.12, 1.93)
sln <- sln[sln>5e3]
brks<- hist(log10(sln), breaks = "FD", prob = T, plot = T, main = "method 1")$breaks
hist(sln, breaks = 10^brks, prob = T, log = "x", main = 'Method 2')

enter image description here enter image description here

EDIT I'll add that stepping away from histograms and using the kernel density estimates has a similar problem:

plot(density(log(sln)), main = 'Method 1')
plot(density(sln), log = "x", main = 'Method 2')

enter image description here enter image description here

0 Answers
Related