Choosing Colors and Legend in AlgebraOfGraphics

I’m trying to create a plot comparing two parameters I calculated in Turing.jl. I’ve kind of managed this with the following code:

data(avg_vote) * aog.density() * mapping(
    :avg_vote=>"House Popular Vote: Average Democratic Share"; 
    color=:post_1994=>"Before and After 1994"
) |> draw

Hoever, I can’t figure out how to make edits to this. I’d prefer it if “Before” showed up first in the legend, and I’d like the two groups to be colored red and blue. How would I go about this?


  1. Make the layer and assign to an object:

    plt = data(...) * mapping(...) * density() ....
  2. Call draw on that layer with the palettes keyword argument:

    draw(plt; palettes=(; color=ColorSchemes.Set1_3.colors))
1 Like

That fixed the colors problem, thank you! Now I just need to figure out how to switch the order in the legend.

EDIT: Found the answer here!

1 Like

Great, it was a busy week. I was planning to get to your answer later. Glad you managed to find it!

1 Like