What is the appropriate timezone argument argument syntax for scale_datetime () in ggplot 0.9.0

I can not find information on ggplot2 0.9.0 documentation, 0.9.0 migration guide or search.

I assume that in earlier versions you added the tz argument to scale_x_datetime . I tried to place the tz argument in different places of scale_x_datetime , but keep getting errors. See below.

My datetime data is in POSIXct format with GMT time zone. When I draw this, the axis ticks and breaks, showing my local time zone (EST). I would like the midnight on the axis to be midnight in the GMT time zone. What is the correct way to do this in ggplot2 0.9.0?

 attributes(data$date) # $class # [1] "POSIXct" "POSIXt" # $tzone # [1] "GMT" ggplot(data, aes(x = date)) + geom_line(aes(y = count)) + scale_x_datetime(breaks = date_breaks("1 day"), labels = date_format("%d", tz = "UTC")) # Error in date_format("%d", tz = "UTC") : unused argument(s) (tz = "UTC") ggplot(data, aes(x = date)) + geom_line(aes(y = count)) + scale_x_datetime(breaks = date_breaks("1 day", tz = "UTC"), labels = date_format("%d")) # Error in date_breaks("1 day", tz = "UTC") : # unused argument(s) (tz = "UTC") ggplot(data, aes(x = date)) + geom_line(aes(y = count)) + scale_x_datetime(breaks = date_breaks("1 day"), labels = date_format("%d"), tz = "UTC") # Error in continuous_scale(aesthetics, "datetime", identity, breaks = breaks, : # unused argument(s) (tz = "UTC") 
+3
source share
2 answers

Since the scales are 2.2 (~ jul 2012), we can pass the tz argument to time_trans .

For example, it formats timestamps in UTC and does not require additional encoding:

 +scale_x_continuous(trans = time_trans(tz = "UTC")) 
+4
source

@joran is on the right track, but additional arguments cannot be passed through the format function, so they must be passed to the generator function:

 date_format_tz <- function(format = "%Y-%m-%d", tz = "UTC") { function(x) format(x, format, tz=tz) } 

which could then be called:

 scale_x_datetime(breaks = date_breaks("1 day"), labels = date_format_tz("%d", tz="UTC")) 
+5
source

All Articles