lets-plot icon indicating copy to clipboard operation
lets-plot copied to clipboard

geom_text, geom_label: 'label' aesthetic shouldn't produce grouping

Open ASmirnov-HORIS opened this issue 2 years ago • 2 comments

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:

ASmirnov-HORIS avatar Feb 23 '23 11:02 ASmirnov-HORIS

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')

image

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.

alshan avatar Apr 19 '23 20:04 alshan

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

alshan avatar Apr 20 '23 20:04 alshan