Search code examples
rplotscientific-notation

R scientific notation in plots


I have a simple plot:

#!/usr/bin/Rscript                                                                                    

png('plot.png')

y <- c(102, 258, 2314)                                                                         
x <- c(482563, 922167, 4462665)

plot(x,y)
dev.off()

R uses 500, 1000, 1500, etc for the y axis. Is there a way I can use scientific notation for the y axis and put * 10^3 on the top of the axis like the figure below?

enter image description here


Solution

  • This is sort of a hacky way, but there's nothing wrong with it:

    plot(x,y/1e3, ylab="y /10^3")