Let us simulate \(Y\) that is correlated with \(X\) on the log scale, and the \(Y-X\) relationship takes a asymptotic form (let’s use the Michaelis–Menten function): \[log(y) = \dfrac{ax}{1 + bx}\]
x <- seq(0, 1, length.out = 100)
# setting arbitrary a and b values
a <- 30
b <- 15
# simulate Y with noise
logY <- ((a*x) / (1 + b*x)) + rnorm(length(x), 0, 0.1)
# plot
library(ggplot2)
ggplot() +
geom_point(aes(x, logY))
Say we want to plot Y on its log scale, but want to relabel the Y-axis label ticks with their original scale values. We can directly convert the Y-axis ticks here by taking the exponent. We should also relabel the Y-axis since it’s now on its original scale:
ggplot() +
geom_point(aes(x, logY)) +
scale_y_continuous(breaks = pretty(logY), labels = exp(pretty(logY))) +
labs(y = "y")
But the intervals are usually very ugly. Instead, we could first define the desired tick values on the original scale, then log-transform them. Notice the following is just reversing the procedure in scale_y_continuous:
ggplot() +
geom_point(aes(x, logY)) +
scale_y_continuous(breaks = log(pretty(exp(logY))), labels = pretty(exp(logY))) +
labs(y = "y")
Alternative options to explore:
annotation_logticks()coord_trans()