Search code examples
rgraphggplot2axes

Force R to stop plotting abbreviated axis labels (scientific notation) - e.g. 1e+00


In ggplot2 how can I stop axis labels being abbreviated - e.g. 1e+00, 1e+01 along the x axis once plotted? Ideally, I want to force R to display the actual values which in this case would be 1,10.

Any help much appreciated.


Solution

  • I think you are looking for this:

    require(ggplot2)
    df <- data.frame(x=seq(1, 1e9, length.out=100), y=sample(100))
    # displays x-axis in scientific notation
    p  <- ggplot(data = df, aes(x=x, y=y)) + geom_line() + geom_point()
    p
    
    # displays as you require
    library(scales)
    p + scale_x_continuous(labels = label_comma())