How to stop ggplot2 from converting POSIX from GMT to CST?

163 views
Skip to first unread message

Aren Cambre

unread,
Jan 9, 2012, 6:09:28 PM1/9/12
to ggp...@googlegroups.com
Sorry if I wandered too much with my prior emails. Let me rephrase.

Short version:
ggplot is converting my POSIX time values from GMT to CST (GMT-6), which is my time zone. How do I stop this?

Long version:
I have a data frame. It has a column with POSIX time values like this:
3840 6780 36480 7200 46740 13500 64800 44400 46800 42000 14400 39660 5100 36600 33600 79620
(spaces separate different values).

All the values are between 0 and 86399, representing times between 0:00 (midnight) and 23:59:59. Technically the date is 1-1-1970, but I am ignoring the date.

The problem is if I plot them in a histogram. Suppose I use this:
p <- qplot(dallas$offense_posix) + xlab("Offense time") + scale_x_datetime(format = "%H:00")
print(p)

The X axis values start with 18:00 12-31-1969 and end with 17:59 1-1-1970. It's as if ggplot2 is assuming the POSIX times are in GMT and converting them to CST.

How do I tell ggplot2 to ignore time zones? I've looked through the ggplot book and checked other online resources and cannot find a clear answer. I'm sure it's something novice I'm missing, so sorry if this is a stupid question.

Aren

Aren Cambre

unread,
Jan 9, 2012, 7:06:56 PM1/9/12
to ggp...@googlegroups.com
I may have fixed this, but I think there's a bug.

I found the tz parameter on scale_x_datetime.

If I don't specify a tz value, the values run from 18:00 12-31-1969 to 17:59 1-1-1970.
If I use tz="GMT", the values go 06:00:00 1/1/1970 to 05:59:59 01/02/1970.
If I use tz="CST", I get In as.POSIXlt.POSIXct(x, tz) : unknown timezone 'CST'
If I use tz="", I get correct values!

Aren

Hadley Wickham

unread,
Feb 10, 2012, 7:47:04 AM2/10/12
to Aren Cambre, ggp...@googlegroups.com
Could you please file a small reproducible example at
https://github.com/hadley/ggplot2/issues?
Thanks,
Hadley

> --
> You received this message because you are subscribed to the ggplot2 mailing
> list.
> Please provide a reproducible example: http://gist.github.com/270442
>
> To post: email ggp...@googlegroups.com
> To unsubscribe: email ggplot2+u...@googlegroups.com
> More options: http://groups.google.com/group/ggplot2

--
Assistant Professor / Dobelman Family Junior Chair
Department of Statistics / Rice University
http://had.co.nz/

Josh London

unread,
May 3, 2012, 12:12:24 PM5/3/12
to ggp...@googlegroups.com, Aren Cambre
Hello,

I am experiencing a similar problem. In my case, with ggplot 0.9.0, Aren's solution will not work as the tz parameter for scale_x_datetime appears to be unused.

I have opened an issue along with a reproducible example.

cheers
josh


On Friday, February 10, 2012 4:47:04 AM UTC-8, Hadley Wickham wrote:
Could you please file a small reproducible example at
https://github.com/hadley/ggplot2/issues?
Thanks,
Hadley

On Mon, Jan 9, 2012 at 6:06 PM, Aren Cambre wrote:
> I may have fixed this, but I think there's a bug.
>
> I found the tz parameter on scale_x_datetime.
>
> If I don't specify a tz value, the values run from 18:00 12-31-1969 to 17:59
> 1-1-1970.
> If I use tz="GMT", the values go 06:00:00 1/1/1970 to 05:59:59 01/02/1970.
> If I use tz="CST", I get In as.POSIXlt.POSIXct(x, tz) : unknown timezone
> 'CST'
> If I use tz="", I get correct values!
>
> Aren
>

Meredith Atwood

unread,
Dec 4, 2013, 10:02:25 PM12/4/13
to ggp...@googlegroups.com, Aren Cambre
Hello,

I am having the same problem.  My data plots correctly, but then the breaks are incorrect.  I collected the data on EST and am living in PST and trying to run the analysis.  I am using facet_wrap to plot multiple events, and some of the individual plots have correct times and some of them are incorrect.  Is there a bug, or a quick fix?  Would be great to be able to use tz="EST", but says unused.

Thank you so much. Happy to send code and data if need be.

-Meredith
Reply all
Reply to author
Forward
0 new messages