-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
x_scale_datetime: timezone ignored when limits given #3440
Comments
I think you need your library(ggplot2)
df <- data.frame(
x = lubridate::now(tzone = "America/Halifax") + lubridate::dhours(0:10),
y = 0:10
)
limits <- lubridate::now(tzone = "America/Halifax") + lubridate::dhours(c(0.5, 9.5))
p <- ggplot(df, aes(x, y)) + geom_point()
p p + scale_x_datetime(limits = limits)
#> Warning: Removed 2 rows containing missing values (geom_point). Created on 2019-07-14 by the reprex package (v0.2.1) |
Here's an example. In reality I'm using Furthermore, the timestamp values are correct (verified the unix timestamp versions).
If you comment the |
Update: With
Thanks a lot! |
Parsing an ISO8601 date will give you the correct moment in time, but R has no way to know that UTC+2:00 is |
Well, sorry, I'm not sure I understand. For the axis labels it doesn't matter _which +02:00 timezone I'm - the important information is to have the right offset for the given timestamps. So, my first question is if ggplot2 sees "the timestamp data is +02:00, the limits are +02:00, timestamps enclose the limits" why isn't the timezone taken into account? BTW, looking at So thanks a lot for your help - but I still don't understand why I have to repeat my system timezone when specifying limits (but not without them)... I still believe this to be a bug. Thanks a lot! |
I see your point...there is no theoretical reason why limits for a datetime scale have to be in the same timezone as the data (although a quite reasonable workaround is to make sure that this is the case). |
The timezone information is dropped during conversion, so there is no way for ggplot2 to know what timezone the data had originally. Note the 08:00+02:00 becomes 06:00+UTC: parsedate::parse_iso_8601("2019-07-12T08:00:00+02:00")
#> [1] "2019-07-12 06:00:00 UTC" Created on 2024-08-28 with reprex v2.1.1 You could use |
I've got a plot that uses x_scale_datetime.
When using the whole data set, the x-axis has correct labels; but when I specify "limits" to restrict to a subset of the data, the tics get labelled as with a timezone "UTC".
The text was updated successfully, but these errors were encountered: