I'm trying to use the timezone parameter of the scale_x_datetime function in ggplot2. Reprex is below. Basically I have data which includes a timezone, but I can't change the tick labels using the timezone parameter as I understand it to work. I was able to use labels=scales::label_date(tz = "US/Eastern") as a workaround, but just wondering if anyone can help me with understanding the issue. ggplot 3.2.1, lubridate 1.7.4, R 3.6.2
Hi swebs!
It looks like timezone is not an allowed argument for scale_x_datetime, and (unfortunately) it does not warn you when this argument is ignored.
The only allowed arguments are breaks, minor breaks, expand, and the standard arguments for a continuous scale.
However, I think I have a workaround.
Does this achieve your goal?
library(tidyverse)
library(lubridate)
#>
#> Attaching package: 'lubridate'
#> The following objects are masked from 'package:base':
#>
#> date, intersect, setdiff, union
plotdata <- tribble(
~t_stamp, ~value,
"2019-08-17T06:00:00", 1,
"2019-08-17T07:00:00", 2,
"2019-08-17T08:00:00", 3
) %>%
mutate(t_stamp = ymd_hms(t_stamp),
tz = "US/Mountain")
plotdata %>%
ggplot(mapping=aes(x=t_stamp, y=value)) +
geom_point(mapping=aes(x=t_stamp, y=value)) +
scale_x_datetime()