Skip to content

Horizontal bar graphs: Match default stack order in legend as well #1837

Closed
@dpprdan

Description

@dpprdan

According to the v2.2.0 announcement: "position_stack() and position_fill() now stack values in the reverse order of the grouping, which makes the default stack order match the legend." IMHO this should also be true for horizontal bar graphs.

df <- data.frame(
  x = factor(c(1, 1, 2, 2)),
  y = c(1, 3, 2, 1),
  grp = c("a", "b", "a", "b")
)

ggplot(data = df, aes((x), y, fill = (grp), label = y)) +
  geom_col() +
  geom_text(position = "stack_point") + 
  theme(legend.position = "bottom") +
  coord_flip()

horizontal_bar_graph_order

position = "stack_point" borrowed from #1821.

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