Unexpected behavior of scale_x_datetime in ggplot2

I have the following data set with daily data collected.

R> toydata date group coef 1 2011-11-04 23:59:59 1 2.32 2 2011-11-05 23:59:59 1 2.34 3 2011-11-06 23:59:59 1 2.46 4 2011-11-07 23:59:59 1 2.68 5 2011-11-04 23:59:59 2 2.17 6 2011-11-05 23:59:59 2 1.90 7 2011-11-06 23:59:59 2 2.13 8 2011-11-07 23:59:59 2 2.52 

Everything seems to be working fine:

 R> toydata$date [1] "2011-11-04 23:59:59 EST" "2011-11-05 23:59:59 EST" [3] "2011-11-06 23:59:59 EST" "2011-11-07 23:59:59 EST" [5] "2011-11-04 23:59:59 EST" "2011-11-05 23:59:59 EST" [7] "2011-11-06 23:59:59 EST" "2011-11-07 23:59:59 EST" 

and

 R> format(toydata$date, "%d-%b") [1] "04-Nov" "05-Nov" "06-Nov" "07-Nov" "04-Nov" "05-Nov" "06-Nov" "07-Nov" 

However, when I try to build it using ggplot2 using the following code

 R> p <- ggplot(toydata, aes(x = date, y = coef, group = group)) R> pq <- p + geom_line(aes(colour = group)) + + scale_x_datetime(major = "1 day", format = "%d-%b") 

I get an unexpected result:

enter image description here

As you can see, November 6th is duplicated. I can get around this problem by simply treating the labels in x as strings and not as dates, but I wonder why this is happening. Am I missing something?

+7
source share
1 answer

Just specify tz='EST' and it works for me. No matter what the default is November 6th repetition due to daylight saving time.

+4
source

All Articles