Take the code below:
from plotnine import *
import polars as pl
(
ggplot(
data=pl.DataFrame(
{
"X": ["x", "x", "y", "y"],
"GROUP": ["A", "B", "A", "B"],
"COUNT": [42, 24, 32, 18],
"TOTAL": [74, 74, 50, 50],
}
)
) +
aes(x="X", y="COUNT") +
scale_y_continuous(expand=(0, 0, 0.05, 0)) +
scale_x_discrete(expand=(0, 0, 0.05, 0)) +
theme(axis_line=element_line()) +
geom_bar(stat="identity") +
geom_text(mapping=aes(label="TOTAL", y="TOTAL+1")) +
geom_bar(mapping=aes(fill="GROUP"), position="dodge", stat="identity")
)
See how the dodged bars from the last geom overlaps both x/y-axis?

Now, if you remove one of the geom_ (any), there are no issues, e.g., removing geom_text:

Take the code below:
See how the dodged bars from the last
geomoverlaps both x/y-axis?Now, if you remove one of the
geom_(any), there are no issues, e.g., removinggeom_text: