New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
order bar charts #94
Comments
If the from plydata import *
from plotnine import *
from plotnine.data import mpg
# count the manufacturer and sort by the count (see, plydata documentation
# or find out how to do the same thing using raw pandas)
m_categories = (
mpg
>> count('manufacturer', sort=True)
>> pull('manufacturer')
)
df = mpg.copy()
df['manufacturer'] = pd.Categorical(df['manufacturer'], categories=m_categories, ordered=True)
(ggplot(df) +
aes(x='manufacturer') +
geom_bar(size=20) +
coord_flip() +
ggtitle('Number of Cars by Make')
) |
I spent an embarrassing amount of time trying to find the solution to this today. Also based from reading around some of the other plotting packages this seems a common problem. Is there anywhere in the docs this could be highlighted a bit more clearly? Also as a newcomer to Plotnine, this is an awesome tool you have put together! Thanks! |
@Steve-Fry, what parts of the docs did you reach for? |
In fairness it is probably mostly about me being inexperienced in pandas/plotnine, rather than a deficiency. I checked; If it would be helpful I could look at writing a demo for the examples repo? |
I thought of putting a note at aes but a demo would be more illustrative. Just follow the conventions used at https://github.com/has2k1/plotnine-examples/tree/master/plotnine_examples/tutorials. i.e
Then it will be picked up when the documentation is built. Thanks. |
I added a new notebook and created a PR. I'm hoping I went about it in the right way, lemme know what I'm missing. Thanks 👍 |
Hello, I would like to reopen this issue, I don't think it's really user friendly to not include automatic sorting in geom_bar function. If I understand correctly we need to make a pandas.Categorical each time we want to define the order of our graph. That's something I find really painful. Can't we implement a keyword_argument sort_by="xxxx" in geom_bar? I can do the MR if it's not too much complicated, I don't know plotnine code as of now :) Thanks for the answer |
Hi!
I have a question on ordering bar plots. For example:
http://pythonplot.com/#bar-counts
(ggplot(mpg) +
aes(x='manufacturer') +
geom_bar(size=20) +
coord_flip() +
ggtitle('Number of Cars by Make')
)
how to order by "mpg" ?
Thanks!
The text was updated successfully, but these errors were encountered: