Legend ordering #1953
-
When showing a legend, the names are ordered alphabetically. How do I make a custom order? I can't find this info in the docs or anywhere else. I found something about setting The plotting code is essentially:
Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 5 replies
-
Please share a notebook demonstrating the issue. Thanks! |
Beta Was this translation helpful? Give feedback.
-
Per Scales:
The color scale here is ordinal (assuming that the Name column is full of string names), so that’s why you’re getting alphabetical order for the legend. If you want a custom order, you can either use the sort option on the lineY mark, or you can set the domain option on the color scale definition. E.g., Plot.plot({
color: {
legend: true,
domain: ["small", "medium", "large"]
},
marks: [
Plot.lineY(data, {x: "Date", y: "Value", stroke: "Name"}),
]
}); As @Fil said, if you want help, it’s generally best to share a notebook with a minimal reproduction of the problem you’re having. That way we can see exactly the behavior and are more likely to diagnose the problem. |
Beta Was this translation helpful? Give feedback.
Per Scales:
The color scale here is ordinal (assuming that the Name column is full of string names), so that’s why you’re getting alphabetical order for the legend. If you want a custom order, you can either use the sort option on the lineY mark, or you can set the domain option on the color scale definition. E.g.,
As @Fil said, if you want help, it’s gen…