Skip to content

Simplify alignment for column geoms #4899

Closed
@wurli

Description

@wurli

Currently the alignment of columns is always centre, which may not always be desired. E.g. in the following case, values of date always give the first of the month, but are used to indicate the whole month (as is fairly common practice):

library(ggplot2)
library(dplyr, warn.conflicts = FALSE)
library(lubridate, warn.conflicts = FALSE)

df <- tibble(
  month = as_date(c("2020-01-01", "2020-02-01", "2020-03-01")),
  value = 1:3
)

ggplot(df, aes(month, value)) +
  geom_col() +
  scale_x_date(date_labels = "%b %d")

image

In this case an align argument to geom_col() would be really useful to align the columns with the first of each month. align could accept values "centre" (the default), "right" and "left", which would be the option used here. The current alternatives are to use position = position_nudge(), which is fairly esoteric for such a simple task (and wouldn't always work that well, e.g. since February only has 28 days), or to instead use geom_rect(), which again seems much too complex for such a simple task.

If you agree that this sounds like a useful feature I'd be happy to submit a PR.

As always, thanks for the hard work on this beautiful package!

(N.B, this example is a bit contrived due to the use of scale_x_date() but it's the simplest example I could think of)

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