-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
ggplot fails with duration objects. #2414
Comments
Curiously, the fix at r-lib/pillar/issues/88 did not resolve the above error messages. Package versions:
I don't know enough about the internals of Edit: Upon further investigation, using df1 <- tibble::tibble(
a = 1:10
b = lubridate::seconds(1:10)
)
p <- ggplot2::ggplot(df1, ggplot2::aes(x = a, y = b)) + ggplot2::geom_point()
p |
So this is genuine bug but I think it may be best solved in Basically what is happening is ggplot2 is trying to check to make sure none of your data is outside the range/limits of the scale, but it's running into issues because duration objects don't maintain their class when library(ggplot2)
df <- data.frame(
a = 1:10,
b = lubridate::duration(1:10)
)
(x <- df$b)
#> [1] "1s" "2s" "3s" "4s" "5s" "6s" "7s" "8s" "9s" "10s"
class(x)
#> [1] "Duration"
#> attr(,"package")
#> [1] "lubridate"
(r <- range(df$b))
#> [1] 1 10
class(r)
#> [1] "numeric"
x < r[2]
#> Error: Incompatible duration classes (Duration, numeric). Please coerce with `as.duration`.
x < as.duration(r[2])
#> [1] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE FALSE For now, an easy way to get around this is to call the numeric
As you note, period objects don't have this problem because they do have a specified |
This is now fixed. The dev version of lubridate now includes a compare method for numeric and duration objects. |
This old issue has been automatically locked. If you believe you have found a related problem, please file a new issue (with reprex) and link to this issue. https://reprex.tidyverse.org/ |
Trying to print a
ggplot
object created using atibble
with aduration
object inside yields the same error.Initially, I thought this might be caused by the bug at r-lib/pillar#88, due to the same error message. Indeed, we encounter the same error message if
df
isprint
ed, and this is caused by thepillar
issue.However, trying to print a
ggplot
object created using adata.frame
with aduration
object inside still yields the error, even though we're not usingtibble
s anymore.Given that
ggplot2
depends ontibble
, this is still likely caused by r-lib/pillar#88, even though we're not actually printing tibbles here. Perhaps thedata.frame
is being coerced to atibble
?The text was updated successfully, but these errors were encountered: