i am displaying time series data with ggplot2 but the tick-labels show some strange behaviour. probably i am doing something wrong but i could not find any help on the internet. here’s an example:
#just sample data
time <- as.Date(seq(as.Date("2004/1/1"), as.Date("2009/12/1"), by = "1 month"))
data <- rnorm(nrow(test))+c(1:nrow(test))
test <- data.frame(time, data)
i plot with:
q1 <- ggplot(data=test) + geom_line(aes(x=time, y=data))
q1 <- q1 + scale_x_date(major="years", minor="3 months", format="%Y-%m", lim=c(as.Date("2004/1/1"),as.Date("2009/12/1")), name="")
q1
this produces the following graph:

but from my understanding the grid should end 2009/12/1 – right? thanks a lot for your help!
The
limitsparameter toscale_x_dateaffects which data points are plotted, but does not directly change the axis tick labels nor the axis range. This behavior is well illustrated in the help page http://had.co.nz/ggplot2/scale_date.html (towards the bottom of the page.)If you want to eliminate the empty areas to left and right of your data, use
coord_cartesian