tz issues with scale_x_datetime with ggplot2 2.0.0?

134 views
Skip to first unread message

E Chu

unread,
Feb 3, 2016, 8:36:56 PM2/3/16
to ggplot2
Hi there,

I am having issues with setting tz properly with the new ggplot2, v2.0.0.

My input data is set to PST, however, the graph outputs in UTC.

  ggplot(data=d, aes(x=TIMEOFDAY, y=USAGE)) + 
    geom_line(aes(group=DATE))  + 
     xlab("Time of Day") +
     ylab("Demand (kW)")  +
     scale_x_datetime(date_labels="%H:%M %Z", date_breaks="2 hours")

In older versions of ggplot2, I did not specifically set tz in the plot function.  As long as the input data had tz set, my plot used the intended timezone.

The scale_x_datetime function does not seem to accept a "tz" argument.

Any ideas how to control tz in the display?

Thanks!
Emily

Sherif Soliman

unread,
Feb 3, 2016, 8:52:13 PM2/3/16
to ggplot2

Hi Emily,

Try replacing

date_labels = "..."

with

labels = date_format("...", tz = "...").

This assumes you are using the scales package. So the result should be:

ggplot(data=d, aes(x=TIMEOFDAY, y=USAGE)) + 
    geom_line(aes(group=DATE))  + 
    xlab("Time of Day") +
    ylab("Demand (kW)")  +
    scale_x_datetime(
        labels = date_format("%H:%M %Z", 
                             tz = "PST"), 
        date_breaks="2 hours"
    )

Does this work for you?

Sherif

--
--
You received this message because you are subscribed to the ggplot2 mailing list.
Please provide a reproducible example: https://github.com/hadley/devtools/wiki/Reproducibility

To post: email ggp...@googlegroups.com
To unsubscribe: email ggplot2+u...@googlegroups.com
More options: http://groups.google.com/group/ggplot2


You received this message because you are subscribed to the Google Groups "ggplot2" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ggplot2+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

E Chu

unread,
Feb 4, 2016, 1:12:19 AM2/4/16
to ggplot2
Hi Sherif,

Yes that works.  Thank you!!

Emily
Reply all
Reply to author
Forward
0 new messages