{"action":"created","issue":{"url":"https://api.github.com/repos/hadley/ggplot2/issues/1721","repository_url":"https://api.github.com/repos/hadley/ggplot2","labels_url":"https://api.github.com/repos/hadley/ggplot2/issues/1721/labels{/name}","comments_url":"https://api.github.com/repos/hadley/ggplot2/issues/1721/comments","events_url":"https://api.github.com/repos/hadley/ggplot2/issues/1721/events","html_url":"https://github.com/hadley/ggplot2/pull/1721","id":172055700,"number":1721,"title":"Added support for timezones in scale_datetime","user":{"login":"bogdanstate","id":3690985,"avatar_url":"https://avatars.githubusercontent.com/u/3690985?v=3","gravatar_id":"","url":"https://api.github.com/users/bogdanstate","html_url":"https://github.com/bogdanstate","followers_url":"https://api.github.com/users/bogdanstate/followers","following_url":"https://api.github.com/users/bogdanstate/following{/other_user}","gists_url":"https://api.github.com/users/bogdanstate/gists{/gist_id}","starred_url":"https://api.github.com/users/bogdanstate/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bogdanstate/subscriptions","organizations_url":"https://api.github.com/users/bogdanstate/orgs","repos_url":"https://api.github.com/users/bogdanstate/repos","events_url":"https://api.github.com/users/bogdanstate/events{/privacy}","received_events_url":"https://api.github.com/users/bogdanstate/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2016-08-19T05:11:21Z","updated_at":"2016-08-19T13:18:54Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/hadley/ggplot2/pulls/1721","html_url":"https://github.com/hadley/ggplot2/pull/1721","diff_url":"https://github.com/hadley/ggplot2/pull/1721.diff","patch_url":"https://github.com/hadley/ggplot2/pull/1721.patch"},"body":"Fixes #1718\r\n\r\nThis is a bit of a tricky issue: at the time the `date_format` function is passed as a label formatter in `scale_datetime`, the timezone is not known, as this is an attribute of the input data.\r\n\r\nMy solution is to define a special behavior when it comes to the `labels` argument passed to `scale_continuous`. If this argument is a function, it is evaluated once on `breaks`, as before. BUT, if it so happens that the return value of this evaluation is another function, then we evaluate this returned function on `breaks` one more time. The rationale for this is simple: there might be some formatting context that is only evident from the data, and this may have consequences on how formatting is done. For continuous scales timezone is a clear example, but the same logic could be used to implement some sort of locale-based formatting for discrete scales.\r\n\r\nI have tested this fix using the following code:\r\n\r\n```\r\nlibrary(ggplot2)\r\nlibrary(gridExtra)\r\n\r\ndf <- data.frame(\r\n  time = as.POSIXct(as.Date(\"2010-01-01\"), tz = \"America/Chicago\") + 1:10 * 3600,\r\n  y = 1:10\r\n)\r\n\r\np1 <- ggplot(df, aes(time, y)) + geom_point()\r\np2 <- ggplot(df, aes(time, y)) + geom_point() + scale_x_datetime(date_labels = \"%H:%M %Z\")\r\ngrid.arrange(p1, p2)\r\n```\r\n\r\n![image](https://cloud.githubusercontent.com/assets/3690985/17799560/7bf6b89c-6590-11e6-8c4b-8d4ac1e400fa.png)\r\n\r\nP.S.: This is my first contribution to ggplot2, thanks for creating this amazing package!"},"comment":{"url":"https://api.github.com/repos/hadley/ggplot2/issues/comments/241015918","html_url":"https://github.com/hadley/ggplot2/pull/1721#issuecomment-241015918","issue_url":"https://api.github.com/repos/hadley/ggplot2/issues/1721","id":241015918,"user":{"login":"hadley","id":4196,"avatar_url":"https://avatars.githubusercontent.com/u/4196?v=3","gravatar_id":"","url":"https://api.github.com/users/hadley","html_url":"https://github.com/hadley","followers_url":"https://api.github.com/users/hadley/followers","following_url":"https://api.github.com/users/hadley/following{/other_user}","gists_url":"https://api.github.com/users/hadley/gists{/gist_id}","starred_url":"https://api.github.com/users/hadley/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hadley/subscriptions","organizations_url":"https://api.github.com/users/hadley/orgs","repos_url":"https://api.github.com/users/hadley/repos","events_url":"https://api.github.com/users/hadley/events{/privacy}","received_events_url":"https://api.github.com/users/hadley/received_events","type":"User","site_admin":false},"created_at":"2016-08-19T13:18:54Z","updated_at":"2016-08-19T13:18:54Z","body":"I wonder if it would be better to adjust `train()` to save the first non-NULL `tzone` that it encounters"}}
{"actor":{"display_login":"hadley"}}