Skip to content

Datetime scales don't support out of bounds (oob) arguments #4199

Description

@teunbrand

I've noticed that date/time scales do not support the oob argument that the continuous scales have, while I do think this might be a useful feature.

Let's say I have the following graph, of which I would want the x-axis labelling:

library(ggplot2)

ggplot(economics, aes(date, unemploy)) +
  geom_line() +
  scale_x_date(limits = as.Date(c("1970-01-01", "2010-01-01")))
#> Warning: Removed 93 row(s) containing missing values (geom_path).

But I'd like the line to look like the following:

ggplot(economics, aes(as.numeric(date), unemploy)) +
  geom_line() +
  scale_x_continuous(
    limits = as.numeric(as.Date(c("1970-01-01", "2010-01-01"))),
    oob = scales::oob_squish
  )

Created on 2020-09-11 by the reprex package (v0.3.0)

This does not currently seem possible. However, as the ggplot2:::datetime_scale() function passes the ... to continuous_scale() (which does use oob), it would seem most of the infrastructure for oob arguments is already there.

Thanks for considering!

Activity

  1. yutannihilation commented on Oct 11, 2020

    @yutannihilation
    Member

    This sounds good to me. Datetime scales lost ... on this commit 4870fb0#diff-053b14c802505a7a11aeffaefe971dd4R57, and there seems no intention. Would you mind creating a pull request for this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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