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.

How order the "color legend"

See original GitHub issue

Hello, is it possible to reorder the legend ? The current order is alphabetic but “values” are numbers, so I want an ascending order. In the dataframe, the column “values” have to be strings to use the color parameter, I can’t use integers.

The code : ggplot(data=df) + aes(x='algo', y='hv', color='values')

The figure : image

Thank you

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
TyberiusPrimecommented, Mar 23, 2020

It is ‘exactly’ like factors and levels in R.

You can access the categorical attributes with df.column.cat. See https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.Categorical.html

1reaction
TyberiusPrimecommented, Oct 18, 2019

You have to turn your data into a pandas.Categorical

df2 = df.assign(values = pd.Categorical(df['values'], [optional ordered, unique list showing value order])

Don’t think you need to provide the optional list when dealing with integers.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to change the order of the color legend?
Have you tried changing the order of your original dimension ? (e.g. V-Colour) r/click it and select Default Properties > Sort then select...
Read more >
How to Change GGPlot Legend Order: The Best Reference
Changing the order of legend labels can be achieved by reordering the factor levels of the Species variable mapped to the color aesthetic....
Read more >
Seaborn Boxplot Legend colors mismatched after setting ...
This fixed the order issue. I did a quick search after that because my bars were not aligned with the xtick labels. I...
Read more >
10.3 Changing the Order of Items in a Legend
You want to change the order of the items in a legend. ... which maps the factor levels to colors that are equally...
Read more >
How to Change Order of Items in Matplotlib Legend - Statology
The first item in the legend should be the label that was originally in index position 1 of the old legend (“Assists”); The...
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