Skip to content
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

stack and color legend are in reverse order #467

Closed
ssfrr opened this issue Jul 28, 2023 · 1 comment
Closed

stack and color legend are in reverse order #467

ssfrr opened this issue Jul 28, 2023 · 1 comment

Comments

@ssfrr
Copy link

ssfrr commented Jul 28, 2023

Bug description

The colors in the legend end up inverted from the blocks in a stacked bar chart, which makes it a little harder to scan.

Steps to reproduce

using DataFrames
using AlgebraOfGraphics
using CairoMakie

df = DataFrame(x=repeat(1:3, 3), y = rand(9), z=["a", "a", "a", "b", "b", "b", "c", "c", "c"])
draw(data(df) * mapping(:x, :y; stack=:z, color=:z) * visual(BarPlot))

generates the plot:
image

Notice the color ordering in the stacking and legend are reversed.

Version info

AlgebraOfGraphics v0.6.16

@jkrumbiegel
Copy link
Member

You can achieve reverse order now by passing categories = reverse to the Stack scale.

df = DataFrame(x=repeat(1:3, 3), y = rand(9), z=["a", "a", "a", "b", "b", "b", "c", "c", "c"])
draw(
    data(df) * mapping(:x, :y; stack=:z, color=:z) * visual(BarPlot),
    scales(Stack = (; categories = reverse))
)
image

I agree that it makes for a more intuitive reading order, but on the other hand I think the process of stacking makes sense to think of as going bottom-up, also reverse order would work less well for horizontal barplots:

image

So I don't think I'm going to change the default here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants