ggplot2中的scale_x_date

时间:2013-02-27 01:48:01

标签: r ggplot2

我对R很新,但我正在尝试在scale_x_date包中使用ggplot2为我的论文创建一个水文图。水文图由预测值和实际值组成,这些值是我正在研究的河流的深度。我希望能够更改日期标签和休息时间。这就是我所拥有的。

library(ggplot2)
library(scales)
LowerHydro<-data.frame(LowerHydrology)
LowerHydro$date <- as.Date(LowerHydro$Date, format = "%m/%d/%y")
attach(LowerHydro)
p<-ggplot(data=LowerHydro,aes(x=date,y=Depth,group=Group,color=Group))
p+geom_line()+scale_x_date(labels=date_format("%b-%y"),breaks=date_breaks("3 months"))

但在最后一行代码之后,我收到以下错误:

Error in get(x, envir = this, inherits = inh)(this, ...) : 
unused argument(s) (labels = function (x) 

如果我只运行最后一行代码而不使用labels =,只需使用breaks =,我仍然会收到错误:

p+geom_line()+scale_x_date(breaks=date_breaks("3 months"))
Error in cut.default(days, c(0, 10, 56, 365, 730, 5000, Inf), labels = FALSE) :
'x' must be numeric

这是我的str(LowerHydro)

data.frame':    712 obs. of  3 variables:
$ Depth: num  5.24 5.14 5.42 5.27 5.27 ...
$ Group: Factor w/ 2 levels "Actual","Predicted": 2 2 2 2 2 2 2 2 2 2 ...
$ date : Date, format: "2010-10-01" "2010-10-02" ...

sessionInfo()

R version 2.13.0 (2011-04-13)
Platform: x86_64-pc-mingw32/x64 (64-bit)

locale:
[1] LC_COLLATE=English_United States.1252  LC_CTYPE=English_United States.1252   
[3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C                          
[5] LC_TIME=English_United States.1252    

attached base packages:
[1] grid      stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] ggplot2_0.8.9 proto_0.3-9.2 reshape_0.8.4 plyr_1.5.2    scales_0.2.0 

loaded via a namespace (and not attached):
[1] colorspace_1.1-0   dichromat_1.2-4    digest_0.5.0       munsell_0.3       
[5] RColorBrewer_1.0-5 stringr_0.4        tools_2.13.0

感谢。

0 个答案:

没有答案