Skip to content

Adding scale_*_discrete() to date variable can crash R #1542

Closed
@cpsievert

Description

@cpsievert

With scales 0.3, this code will error:

x <- c(Sys.Date(), Sys.Date() - 1e4)
y <- c(3, 4)
d <- data.frame(x, y)
library(ggplot2)
ggplot(d, aes(x, y)) + geom_line() + scale_x_discrete()
#> Error: Discrete value supplied to continuous scale

Running this code using the latest dev version of scales doesn't result in error, and ggplot tries to draw a plot with 1e4 ticks. I know this is a cornercase, but I would prefer an error since it can easily wreak havoc on an R session, especially with date-times.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions