lets-plot
lets-plot copied to clipboard
geom_text, geom_label: 'label' aesthetic shouldn't produce grouping
Example:
data = {
'x': [0, 0, 0, 0],
'y': [1, 1, 1, 1],
'l': ["a", "b", "c", "d"],
}
ggplot(data, aes('x', 'y')) + \
geom_point(position=position_stack(mode='groups'), size=15) + \
geom_label(aes(label='l'), position=position_stack(mode='groups'))

It means that aes(label='l') adds additional implicit grouping to labels. But it shouldn't.
Expected behaviour:

It seems that grouping by label aes is necessary. Consider an example:
data3 = {
"g": ["X", "X", "X", "X", "X", "Y", "Y", "Y", "Y", "Y"],
"f": ["A", "B", "C", "D", "E", "E", "D", "C", "B", "A"],
"z": ['Q', 'Q', 'Q', 'E', 'E', 'W', 'W', 'W', 'Q', 'E'],
"x": ['L', 'L', 'L', "L", "R", "L", "L", "L", "R", "R"],
}
ggplot(data3) + geom_bar(aes(x='x', fill='f', color='z'), size = 5) + \
geom_label(aes(x='x', label='f', group='z'), position=position_stack(vjust=0.5), stat='count') + \
facet_grid(x='g')
In this example, bars are grouped by two variables - f , z.
In order to get correct labels stacking we have to group labels by exactly the same variables: aes(x='x', label='f', group='z').
If geom_label didn't group by the label aesthetic, we wouldn't be able to achieve such a grouping.
On the other hand, ggplot R supports grouping by multiple columns:
group = interaction(dir, grp)
https://stackoverflow.com/questions/50604055/ggplot2-geom-bar-position-failure
