2012-03-11 242 views
2

我正在嘗試使用ggplot2創建一個座標圖圖表,但我無法獲得標記,因爲它在ggplot2 webiste的示例中顯示。ggplot2 y軸座標不顯示在對數座標上

這裏是水果的鮮味的一些假數據:

apples <- data.frame(fruit=c(rep("apple", 30)), taste=runif(30, 30, 50) 
banana <- data.frame(fruit=c(rep("banana", 30)), taste=runif(30, 300, 500)) 
orange <- data.frame(fruit=c(rep("orange", 30)), taste=runif(30, 3000, 5000)) 
fruits <- rbind(apples,banana,orange) 

如果我繪製作爲ggplot2 website example y軸的規模應該看起來像:

enter image description here

相反,我得到軸如:

ggplot(fruits, aes(fruit, taste)) + geom_boxplot() + scale_y_log10() 

enter image description here

我如何得到科學記數法的y軸比例?

回答

3

我假設您正在使用ggplot2的新0.9.0版本,該版本經歷了大量更改。我相信這恰好是其中之一。

如果我記得正確的話,足夠的人抱怨指數格式是默認的,這是改變了。根據transition guide,您可以通過以下方法達到相同的效果:

library(ggplot2) 
library(scales) 
ggplot(fruits, aes(fruit, taste)) + 
    geom_boxplot() + 
    scale_y_log10(breaks = trans_breaks('log10', function(x) 10^x), 
        labels = trans_format('log10', math_format(10^.x))) 
+0

現在似乎不適合我。如果有一段時間,我將不得不周遊世界。最重要的部分不是科學記數法,而是y軸上0到1000之間缺失的巨大差距。當我更新我的操作系統時,我必須錯誤地更新到0.8.9。 – Kevin 2012-03-11 04:08:36

+0

得到它的工作,需要附加秤包。 – Kevin 2012-03-11 04:12:45

+0

@Kev很高興幫助。當尺度需要明確加載並且還沒有時,我還沒有完全包裹我的頭。 – joran 2012-03-11 04:41:28