[R] plot(): I want to display dates on X-axis.
Michael Toews
mwtoews at sfu.ca
Thu Mar 8 06:03:42 CET 2007
>
> e.g. dat
>
> [,1] dat[,2]
>
> [1,] 300 20060101
> [2,] 257 20060102
> [3,] 320 20060103
> [4,] 311 20060104
> [5,] 297 20060105
> [6,] 454 20060106
> [7,] 360 20060107
> [8,] 307 20060108
> ....
>
This looks like a matrix ... not a data frame. You defiantly want a data
frame. So lets say you have:
dat <- matrix(c(round(rnorm(8)*100+400),20060101:20060108),ncol=2)
#convert it:
dat <- as.data.frame(dat)
#determine the dates:
dat$date <- as.Date(as.character(dat$V2),"%Y%m%d")
#plot it:
plot(V1 ~ date, dat)
More information about the R-help
mailing list