How do I change the formatting of numbers on an axis with ggplot?

后端 未结 5 992
独厮守ぢ
独厮守ぢ 2020-11-28 01:07

I\'m using R and ggplot to draw a scatterplot of some data, all is fine except that the numbers on the y-axis are coming out with computer style exponent formatting, i.e. 4e

5条回答
  •  夕颜
    夕颜 (楼主)
    2020-11-28 02:07

    I find Jack Aidley's suggested answer a useful one.

    I wanted to throw out another option. Suppose you have a series with many small numbers, and you want to ensure the axis labels write out the full decimal point (e.g. 5e-05 -> 0.0005), then:

    NotFancy <- function(l) {
     l <- format(l, scientific = FALSE)
     parse(text=l)
    }
    
    ggplot(data = data.frame(x = 1:100, 
                             y = seq(from=0.00005,to = 0.0000000000001,length.out=100) + runif(n=100,-0.0000005,0.0000005)), 
           aes(x=x, y=y)) +
         geom_point() +
         scale_y_continuous(labels=NotFancy) 
    

提交回复
热议问题