R scientific notation in plots

Yang picture Yang · Jun 30, 2013 · Viewed 12.3k times · Source

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

Answer

Mike T picture Mike T · Jan 23, 2014

A similar technique is to use eaxis (extended / engineering axis) from the sfsmisc package.

It works like this:

library(sfsmisc)

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

plot(x, y, xaxt="n", yaxt="n")

eaxis(1)  # x-axis
eaxis(2)  # y-axis

enter image description here