Skip to content

ggplot breaks when facet variable is POSIXct with tz attribute specified #4175

@edzer

Description

@edzer

This came up here, and I think I can reduce it to the presence of a time zone attribute in a POSIXct vector. Not sure if this is a vctrs issue or ggplot2, but this is where it showed up.

Minimal reprex:

library(ggplot2)
x = data.frame(x = 1:6, y = 6:1, time = strptime("2020-09-14",format="%Y-%m-%d") + 1:6)
ggplot(x) + geom_point(aes(x=x, y=y)) +facet_wrap(~time) # OK
x = data.frame(x = 1:6, y = 6:1, time = strptime("2020-09-14",format="%Y-%m-%d",tz="UTC") + 1:6)
ggplot(x) + geom_point(aes(x=x, y=y)) +facet_wrap(~time)
# Error: `scale_id` must not be `NA`
# Backtrace:
#
#  1. ├─(function (x, ...) ...
#  2. └─ggplot2:::print.ggplot(x)
#  3.   ├─ggplot2::ggplot_build(x)
#  4.   └─ggplot2:::ggplot_build.ggplot(x)
#  5.     └─layout$train_position(data, scale_x(), scale_y())
#  6.       └─ggplot2:::f(..., self = self)
#  7.         └─self$facet$train_scales(...)
#  8.           └─ggplot2:::f(...)
#  9.             └─ggplot2:::scale_apply(layer_data, x_vars, "train", SCALE_X, x_scales)
# Execution halted

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugan unexpected problem or unintended behaviorfacets 💎

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions