Example time series data? ts.
gnp <- ts(cumsum(1 + round(rnorm(100), 2)), start = c(1954, 7), frequency = 12) new.date <- seq(as.Date(paste(c(start(gnp),1), collapse = "/")), by = "month", length.out = length(gnp))
The seq function can work with date objects. In the above example, the start date is given, the monthly frequency is set and how long the date vector is created.
Hope this is useful in preparing data before using ggplot2 or anything else.
You can combine the above example with data.frame as follows:
dat <- data.frame(date=new.date, value=gnp)
This can be built in ggplot as follows:
ggplot(data=dat) + geom_line(aes(date, gnp))
All the best
Jay
source share