Skip to content

bug: geom_text in middle of stacked bar_plot not in the middle (v2.1.0.9001) #1821

Closed
@dpprdan

Description

@dpprdan

The placement of geom_text in the middle of a stacked bar_plot is off. When I run the example from the help file of geom_text I get:

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

df <- transform(df, mid_y = ave(df$y, df$x, FUN = function(val) cumsum(val) - (0.5 * val)))

ggplot(data = df, aes(x, y, fill = grp, label = y)) +
  geom_col() +
  geom_text(aes(y = mid_y))

stacked_text

I suppose this is due to "position_stack() and position_fill() now stack values in the reverse order of the grouping, which makes the default stack order match the legend."

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions