Skip to content

bug(geom_bar(position="fill")): Single combination groups are not transformed to proportions #6521

Open
@schloerke

Description

@schloerke

I found a problem with geom_bar(position="fill")

I expected the plot's y axis to have a proportion where it ranges from 0 to 1. However, when the color combinations produce single values, the count is provided, not the proportion of 100%.

Here is the code to reproduce the bug:

library(ggplot2)

# Good: Y axis is proportion
ggplot(mtcars, aes(factor(cyl), fill = factor(vs))) + geom_bar(position="fill")

ggplot(GGally::tips, aes(x = smoker, fill = sex)) + geom_bar(position = "fill")

# Bad: Y axis is count, not proportion
ggplot(subset(mtcars, cyl == 8), aes(factor(cyl), fill = factor(vs))) + geom_bar(position="fill")

ggplot(GGally::tips, aes(x = smoker, fill = smoker)) + geom_bar(position = "fill")

Created on 2025-06-19 with reprex v2.1.1

sessioninfo::package_info("ggplot2")
#>  ggplot2      * 3.5.2.9001 2025-06-19 [1] Github (tidyverse/ggplot2@a2d0181)

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions