Skip to content

minor_breaks with Dates #1385

@ptoche

Description

@ptoche

Is the following expected behaviour? (scroll down to the last example, which fails)

    df <- data.frame(
        x_date  = seq(as.Date("1952-01-01"), as.Date("2013-12-01"), by = "1 month"),
        y = runif(12*62)
    )
    library('ggplot2')
    library('scales')
    p <- ggplot(df, aes(x_date, y)) + geom_point()

    # version 1: automatic selection of start/end 'major' breaks
    p + scale_x_date(labels = date_format("%Y"), 
                     breaks = "5 years", 
                     minor_breaks = "1 year")

    # version 2: manual selection of start/end 'major' breaks
    p + scale_x_date(labels = date_format("%Y"), 
                     breaks = seq(as.Date("1950-01-01"), 
                                  as.Date("2015-01-01"), 
                                  by = "5 years"),
                     minor_breaks = "1 year")

    # version 3: manual selection of start/end 'minor' breaks: FAIL
    p + scale_x_date(labels = date_format("%Y"), 
                     breaks = seq(as.Date("1950-01-01"), 
                                  as.Date("2015-01-01"), 
                                  by = "5 years"),
                     minor_breaks = seq(as.Date("1975-01-01"), 
                                  as.Date("1995-01-01"), 
                                  by = "1 year"))
    ## Error in Ops.Date((x - from[1]), diff(from)) : 
    ##  / not defined for "Date" objects

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugan unexpected problem or unintended behavior

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions