Skip to content

How should users reorder the x axis bins in a bar chart? #315

@briandk

Description

@briandk

This is a classic question in ggplot2 for R.

Here's a simple reproducible example in python. This code:

from ggplot import *
p = ggplot(aes(x = 'cut', y = 'carat'), data=diamonds)
p = p + geom_bar()
p

Produces this bar chart:

barchartofdiamondcuts

If I wanted to reorder the bins (by count, in this example)

diamonds.groupby('cut').count().sort(columns=['carat'], ascending=False)['carat']

so that they appeared in this order from left-to-right in the plot

cut
Ideal        21551
Premium      13791
Very Good    12082
Good          4906
Fair          1610
Name: carat, dtype: int64

how would I do that?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions