0

Forgive me if this is already answered, but I cannot find the question in the archives.

I am trying to plot some data with times on x axis. The problem is that it plots the times with an extra hour added. E.g. 7pm becomes 8pm in the plot. I think this might be due to the fact that the dates are in daylight saving time period (april-october). When I change the dates to for example November, ggplot2 plots it fine. How can I fix this? As the time in the dataframe is the correct time (no need for +1 hour). I know I can just create a new column where it is time -1 hour but it seems that ggplot2 should just plot it at the right time from the start.

Thanks!

the code with some random data:

library(lubridate)
library(ggplot2)
ee = read.table(textConnection('Timestamp Temp.Diff
  "5/14/2011 19:00" -0.385
  "5/14/2011 19:10" -0.535
  "5/14/2011 19:20" -0.484
  "5/14/2011 19:30" -0.409
  "5/14/2011 19:40" -0.385
  "5/14/2011 19:50" -0.215'), header=TRUE)
ee$Timestamp <- mdy_hm(ee$Timestamp)
ggplot(data=ee, aes(x=Timestamp, y=Temp.Diff)) + geom_point()

plot showing added hour

Mieke Zwart
  • 99
  • 1
  • 1
  • 3
  • Weird, your code works fine for me - i.e. plots hours as it should after parsing. Maybe check your packages versions? – Geek On Acid Nov 05 '12 at 23:29
  • Ditto above on R version 2.15.1, ggplot2_0.9.2.1 – metasequoia Nov 05 '12 at 23:38
  • Have you tried fiddling with arguments `tz` of function `mdy_hm`? It defaults to UTC timezone. – plannapus Nov 06 '12 at 08:06
  • I applied a package update (ggplot2_0.9.2.1) and still had the same resulting graph (previously installed version was ggplot2_0.9.0). Putting the tz(ee$Timestamp) to "Europe/London" fixed it as recommended by plannapus – Mieke Zwart Nov 06 '12 at 10:31

0 Answers0