2017-02-19 90 views
3

我有以下代碼:如何強制軸值以科學記數法中ggplot

library(ggplot2) 
df <- data.frame(y=seq(1, 1e5, length.out=100), x=sample(100)) 
p <- ggplot(data = df, aes(x=x, y=y)) + geom_line() + geom_point() 
p 

產生本圖片:

enter image description here

由於圖像在上面提到我如何改變y軸座標值爲科學記數法?

+0

另外http://stackoverflow.com/questions/20529252/changing-x- axis-values-tick-labels-in -r-using-ggplot2 – tatxif

+0

加載'scales'包,然後在你的圖上加上'scale_y_continuous(labels = scientific)'。 –

回答

5

您可以通過一個format功能與科學記數法開啓以scale_y_continuous標籤參數:

p + scale_y_continuous(labels = function(x) format(x, scientific = TRUE)) 

enter image description here

+9

或'scale_y_continuous(labels = scales :: scientific)' – alistaire

+1

@alistaire非常不錯的選擇。感謝您的評論。 – Psidom