Closed AlFontal closed 6 months ago
You are doing a rather complicated dodge that overwhelms position_dodge
. It does not throwaway any values, rather it just doesn't do enough dodging so the taller columns may overlap the shorter ones depending on the order. You can add
geom_text(aes(label="counts"), position=position_dodge(width=0.9))
to see that everything is there.
When you have more than a single group at the same x
location, the width of the bars is being split between the groups. This increases the appearance of position_dodge
being confused!
The solution is to use the more capable position_dodge2
and tell it (preserve="single"
) to preserve the width of a single element in a group.
geom_col(position=position_dodge2(preserve="single"))
I've been scratching my head quite a bit with this one. I've finally achieved to make a reproducible minimal example.
The context is the following:
I am using plotnine 0.12.1 here. I have a discrete variable in the x-axis, and a continuous variable in the y-axis. I have a second discrete variable that I use for the fill aesthetic, and a third discrete variable that I use as the group aesthetic. In some cases, for a single value of x I have multiple values of this third variable, yet I am interested in the total height of the individual columns so I use
position='dodge'
.The problem is then that the plot generated seems to completely throw away several of the values of the fill aesthetic variable, reproducing a completely erroneous plot. Here the example:
If we were to now plot this data with the default position, the representation seems correct:
However, since we want to have the total height of each individual sample, we use
position='dodge'
and the values are completely off:The issue doesn't simply arise because of the differing width of the columns, as if we keep a one to one ratio between the x axis variable and the group variable but use the 'dodge' position, the representation is also wrong:
Any ideas on what might be causing this? I will take a look later at the actual code in
position_dodge.py
but as of now I am quite clueless...