Make ggplot2 write the order of magnitude of the axis label only once at the top

I would like to ggplot2write down only the first part of the scientific notation on the axis, and then add $ x 10 ^ n $ over the axis by an order of magnitude. Is there a function for this?

Here's a hacked MWE to show what I mean:

ggplot(data = data.frame(x = 1:10, y = seq(1, 2, l = 10)*1000), aes(x,y)) + geom_line()

unscaled y axis

while I would like to:

ggplot(data = data.frame(x = 1:10, y = seq(1, 2, l = 10)*1000), aes(x,y)) + geom_line() +
  scale_y_continuous(breaks = c(1, 1.25, 1.5, 1.75, 2, 2.05)*1000, label = c(1, 1.25, 1.5, 1.75, 2, "x 10^3"))

scaled y axis

As a side issue, I noticed that the axis label quickly approaches label labels when they are large. Is there a way to set the automatic spacing between them?

+4
source share

All Articles