2012-08-17 95 views
3

我正在嘗試使用scale_x_datetime來提煉我的x軸。我讀從ggplot2 website的機制的文檔,但在這個網站的例子中產生同樣的錯誤我得到:scale_x_datetime產生錯誤?

> library(ggplot2) 
> start <- ISOdate(2001, 1, 1, tz = "") 
> df <- data.frame( 
+ day30 = start + round(runif(100, max = 30 * 86400)), 
+ day7 = start + round(runif(100, max = 7 * 86400)), 
+ day = start + round(runif(100, max = 86400)), 
+ hour10 = start + round(runif(100, max = 10 * 3600)), 
+ hour5 = start + round(runif(100, max = 5 * 3600)), 
+ hour = start + round(runif(100, max = 3600)), 
+ min10 = start + round(runif(100, max = 10 * 60)), 
+ min5 = start + round(runif(100, max = 5 * 60)), 
+ min = start + round(runif(100, max = 60)), 
+ sec10 = start + round(runif(100, max = 10)), 
+ y = runif(100) 
+) 
> 
> last_plot() + scale_x_datetime(major = "2 weeks", minor = "1 week") 
Error in continuous_scale(aesthetics, "datetime", identity, breaks = breaks, : 
    unused argument(s) (major = "2 weeks", minor = "1 week") 
> 

所以是文檔過期或有什麼問題在這裏?

回答

7

您使用的文檔已過期,該文檔適用於v0.9.0以前版本。正確的是here。您的示例現在應該如下所示:

library(ggplot2) 
library(scales) # for date_breaks() 
start <- ISOdate(2001, 1, 1, tz = "") 
df <- data.frame( 
    day30 = start + round(runif(100, max = 30 * 86400)), 
    day7 = start + round(runif(100, max = 7 * 86400)), 
    day = start + round(runif(100, max = 86400)), 
    hour10 = start + round(runif(100, max = 10 * 3600)), 
    hour5 = start + round(runif(100, max = 5 * 3600)), 
    hour = start + round(runif(100, max = 3600)), 
    min10 = start + round(runif(100, max = 10 * 60)), 
    min5 = start + round(runif(100, max = 5 * 60)), 
    min = start + round(runif(100, max = 60)), 
    sec10 = start + round(runif(100, max = 10)), 
    y = runif(100)) 

qplot(sec10, y, data = df) 
last_plot() + scale_x_datetime(breaks = date_breaks("2 weeks"), 
           minor_breaks = date_breaks("1 week")) 
+0

您包含的鏈接已過期 – 2016-06-13 14:06:22

+0

已更正。什麼阻止你自己修復它? – ROLO 2016-06-14 09:35:55