R图中的科学记数法

Yan*_*ang 7 plot r scientific-notation

我有一个简单的情节:

#!/usr/bin/Rscript                                                                                    

png('plot.png')

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

plot(x,y)
dev.off()
Run Code Online (Sandbox Code Playgroud)

R对y轴使用500,1000,1500等.有没有办法可以使用科学记数法表示y轴并放在轴* 10^3的顶部,如下图所示?

在此输入图像描述

Mik*_*e T 10

类似的技术是使用sfsmisc包中的eaxis(扩展/工程轴).

它的工作原理如下:

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
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述


Dav*_*arx 3

这是一种 hacky 方式,但没有任何问题:

plot(x,y/1e3, ylab="y /10^3")
Run Code Online (Sandbox Code Playgroud)