burger
burger

Reputation: 5883

annotation_logticks with log1p transformation

Is there a to way to adjust annotation_logticks() in ggplot2 to work with log1p transformation?

Example:

library("ggplot2")
df <- data.frame(trt = c("a", "b", "c"), outcome = c(5, 10, 30))
p <- ggplot(df, aes(trt, outcome)) + geom_col()

This produces the desired results:

p + scale_y_continuous(trans = "log") +
  annotation_logticks(base = exp(1), sides = "l")

enter image description here

This does not (notice the two sets of ticks do not line up):

p + scale_y_continuous(trans = "log1p") +
  annotation_logticks(base = exp(1), sides = "l")

enter image description here

Upvotes: 2

Views: 1353

Answers (1)

Melissa Key
Melissa Key

Reputation: 4551

Use breaks within scale_y_continuous:

p  + scale_y_continuous(trans = "log1p", breaks = c(1, 5, 10, 20))

Upvotes: 2

Related Questions