specific coloring for bar plots

I’m having issues specifying a color for a labeled bar in a bar plot. Below in the attached photo , I’m able to alter the color of a specific name, but the color does not match what I want. How may I do this such that I can assign a specific label with a color of my choosing in a bar plot?

This confused me too at first! Unlike D3, Plot treats the return value of the function (d) => (d.stuffyName === "Piggy" ? "red" : "black") as a part of the domain, not of the range. It treats the strings "red" and "black" as categories, which are then mapped to the default categorical color scale. To get around this, you can add color: {type: "identity"}. Examples:

1 Like

Well, I don’t get this at all, but I can at least follow the pattern - thanks!

1 Like

Here is a suggestion to address this (recurring) issue:

Let us know what you think!

1 Like

This has now been addressed by automatic color identity scale by mbostock · Pull Request #673 · observablehq/plot · GitHub which will be available in the next release.

3 Likes

Am I correct in thinking that you use it just as before, but that the color: {type: "identity"} option is not necessary since the code automatically detects if it should be used?

1 Like

yes that’s the gist of it; it defaults to identity if the category names are all valid css colors

1 Like