79567328

Date: 2025-04-10 18:22:31
Score: 0.5
Natty:
Report link

Adding bigger and bigger offsets will bring the values closer together in the absolute scale, but if you similarly scale your axis then counterintuitively the lower values will be bunched together more the larger you make the offset.

x <- c(100, 150, 200, 250, 1500)

par(mfrow=c(1,3), mar=rep(2, 4))
lapply(1:3, \(e) plot(log(x+10^e), x, ann=FALSE))

increasing offsets bunch lower values closer together

The solution isn't so much the offset -- the smaller the better but that'll only get you so far. What you want is a log-log(-log? -log?) transform:

## Stack those logs! (more works too)
my_transform <- function(x) log(log(x + 1E-3))
my_inverse <- function(x) exp(exp(x)) - 1E-3

my_trans <-  scales::trans_new("yes_mate", transform = my_transform, inverse = my_inverse)

ggplot(mtcars, aes(x = disp, y = 1, color = disp)) +
  geom_point(size = 5) +
  scale_x_continuous(
    trans = my_trans,
    limits=c(100, 1500),
    breaks = c(100, 500, 1000, 1500)
  )

log-log brings all values closer together

Reasons:
  • Probably link only (1):
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Contains question mark (0.5):
Posted by: PBulls