Search code examples
rggplot2number-formattingscientific-notation

Print y-axis title with number raised to power of 10 and real multiplication sign


I am plotting the following data:

library(ggplot2)
library(scales)

data <- data.frame(x = 1:3, y = 1:3)
ggplot(data, aes(x, y)) + 
    geom_point() +
    scale_y_continuous(name = paste("y value (*", math_format()(-4), ")", sep = ""))

Which looks like below: enter image description here

I am not satisfied with the y-axis label. I want * to be changed to multiplicatio sign (real multiplication sign rather than letter x). I also want -4 raised to power of 10. The desired y-axis title is as below: enter image description here

I am not sure how to realized these. Thank you.


Solution

  • Using plotmath:

    ggplot(data, aes(x, y)) + 
      geom_point() + 
      ylab(expression(y~value~(phantom()%*%10^{-4})))
    

    enter image description here