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.

ordering of legend labels

See original GitHub issue

Hi Jake,

Can we change around the order of the legend entries?

Say, put Google at the top in this example from the docs:

import altair as alt
from vega_datasets import data

stocks = data.stocks()

alt.Chart(stocks).mark_line().encode(
    x='date',
    y='price',
    color='symbol'
)

visualization 12

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:12 (6 by maintainers)

github_iconTop GitHub Comments

5reactions
jakevdpcommented, Jul 30, 2018

You can specify the order using the sort property of the channel. Categories will appear in the specified order, and any remaining categories will be appended in arbitrary order. So if all you care is that GOOG is first, you can do this:

import altair as alt
from vega_datasets import data

stocks = data.stocks()

alt.Chart(stocks).mark_line().encode(
    x='date',
    y='price',
    color=alt.Color('symbol', sort=['GOOG'])
)

visualization 29

0reactions
jakevdpcommented, Jan 31, 2020

This should be fixed as of Altair 4.0

Read more comments on GitHub >

github_iconTop Results From Across the Web

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 >
10.3 Changing the Order of Items in a Legend
You want to change the order of the items in a legend. 10.3.2 Solution. Set the limits in the scale to the desired...
Read more >
How to Change Order of Items in ggplot2 Legend - Statology
This tutorial explains how to change the order of the items in a ggplot2 legend, including an example.
Read more >
How to Change Order of Items in Matplotlib Legend?
Legend is a method present in the Matplotlib package which represents the area to describe the elements in a plot/graph. The order of...
Read more >
Change Display Order of ggplot2 Plot Legend in R (Example)
How to switch the ordering of legend items of a ggplot2 graph in R - R programming example code - Reproducible info -...
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