question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`stat = "identity"` doesn't work if combined with `position='stack'`

See original GitHub issue

I’ve noticed that even if I use the flag stat = "identity" in a stacked bar plot, this doesn’t resolve and defaults to the "count" option.

Here is an example of how you can replicate the issue:

import pandas as pd 
from ggplot import *
import numpy as np

df = pd.DataFrame({'device': ['Computers', 'Computers', 'Mobile', 'Mobile', 'Tablets', 'Tablets'],
                  'conversion_type': ['conversions', 'cross-device', 'conversions', 'cross-device', 'conversions', 'cross-device'],
                  'revenue': list(np.random.normal(loc=5000, scale=1000, size=6))})
ggplot(df, aes(x='device', y='revenue', fill='conversion_type')) + \
    geom_bar(stat='identity', position='stack')

Issue Analytics

  • State:open
  • Created 6 years ago
  • Comments:6

github_iconTop GitHub Comments

1reaction
IamGianlucacommented, Mar 28, 2017

I’m not sure how easy is to fix this, but if someone if willing to mentor me, I wouldn’t mind to contribute a fix. I’m not very familiar with the codebase though.

0reactions
simlmxcommented, Apr 12, 2017

Same version of matplotlib, running everything in a jupyter notebook. However while trying to run it again, I got your result (all blue), and then when I killed and restarted my jupyter notebook a few times, sometimes I got my result (proper coloring) and sometimes your result (all blue). I have no idea what’s going on…

Read more comments on GitHub >

github_iconTop Results From Across the Web

ggplot position stack not adding values correctly
Here's a way to solve it, use position = "identity" : library(ggplot2) library(forcats) library(dplyr) gapminder::gapminder ...
Read more >
how to combine position=stack and position=dodge in a single ...
Hi Hadley, I tried to replicate dodging in combination with stacking by facetting as you suggested. In principle this works, but identifying ...
Read more >
`geom_bar` with `stat="identity"` and `position="stack"` broken if ...
When using geom_bar with already computed statistics and stacking them based on some ... and position="stack" broken if some fields missing #141. Open....
Read more >
Bar charts — geom_bar • ggplot2
If you want the heights of the bars to represent values in the data, ... geom_bar( mapping = NULL, data = NULL, stat...
Read more >
Chapter 3 Comparing distributions | Data Visualization ...
3.1.1 Position = stack/dodge/fill/identity ... This doesn't work, because when we are setting a particular feature, R expects a name of a colour, ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found