How can I format axis labels with exponents with ggplot2 and scales?

后端 未结 5 1093
醉梦人生
醉梦人生 2020-11-28 08:06

With the new version ggplot2 and scales, I can\'t figure out how to get axis label in scientific notation. For example:

x <- 1:4
y <- c(0, 0.0001, 0.00         


        
5条回答
  •  自闭症患者
    2020-11-28 08:32

    Riffing off of Tom's answer above, the following removes + signs, and handles 0 better (the function is anonymously inlined as well):

    scale_y_continuous(label= function(x) {ifelse(x==0, "0", parse(text=gsub("[+]", "", gsub("e", " %*% 10^", scientific_format()(x)))))} ) +
    

提交回复
热议问题