geom_bar with stat='identity' does not stack values when only one group present
d = {
'name': ['foo', 'foo', 'bar', 'bar'],
'g': ['A', 'B', 'A', 'B'],
'value': [80, 90, 15, 35]
}
ggplot(d) + geom_bar(aes(x='name', y='value', group='name'), stat='identity')
Actual result:
When values are assigned to their own group, everything works as expected (note the mapping group='g'):
The workaround (and IMO a proper way to build this bar plot) is to use count and weight aes:
d2 = {
'name': ['foo', 'foo', 'bar', 'bar'],
'value': [80, 90, 15, 35]
}
ggplot(d2) + geom_bar(aes(x='name', weight='value'), stat='count')
@IKupriyanov-HORIS , could it help to fix https://github.com/JetBrains/lets-plot-vega-lite/issues/2 ?
However, the following code should stack bars (currently it doesn't):
d3 = {
'name': ['foo', 'foo', 'bar', 'bar'],
'value': [80, 90, 15, 35]
}
ggplot(d3) + geom_bar(aes(x='name', y='value'), stat='identity')
This is an issue in 'stack' position adjustment I guess.
The workaround (and IMO a proper way to build this bar plot) is to use count and weight aes: ... could it help to fix https://github.com/JetBrains/lets-plot-vega-lite/issues/2 ?
It could, but this will require some effort - the simplest obvious fix I made caused few Variable not found: '..count..' exceptions in tests.
Variable not found: '..count..'
Impossible:) stat count (default) computes var ..count..
However, the following code should stack bars (currently it doesn't):
d3 = { 'name': ['foo', 'foo', 'bar', 'bar'], 'value': [80, 90, 15, 35] }
ggplot(d3) + geom_bar(aes(x='name', y='value'), stat='identity') This is an issue in 'stack' position adjustment I guess.
I think, stacking require groups.
d = {
'name': ['foo', 'foo', 'bar', 'bar'],
'g': ['A', 'B', 'A', 'B'],
'value': [80, 90, 15, 35]
}
ggplot(d) + geom_bar(aes(x='name', y='value', group='name'), stat='identity')
Here bars in each x-position are in the same group and will not stack.
However, position_stack has mode parameter which I don't fully understand :) , but which could help in one of these cases (or maybe both).