Skip to content

Should discrete scales be expanded from the continuous range? #5582

Closed
@teunbrand

Description

@teunbrand

In the plot below, there are 2 things that are somewhat bothersome:

  1. The geom_vline() doesn't show up if I leave out geom_segment(), due to the fact that xintercept is a valid aesthetic for a continuous scale, but not a discrete scale.
  2. The geom_vline() is right at the edge of the panel, because the discrete limits are expanded from the discrete range, not the continuous range.

The first thing is due to #3342, which I think might be worth fixing at some point. The second thing is the purpose of this issue. Should we change the limit expansion so that discrete scales are expanded from their continuous limits?

library(ggplot2)

ggplot() +
  geom_col(aes(x = "foo", y = 2)) +
  geom_segment(aes(x = 0, xend = 2, y = 1, yend = 1)) +
  geom_vline(xintercept = c(0, 2), colour = "red")

Created on 2023-12-14 with reprex v2.0.2

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions