rbokeh
rbokeh copied to clipboard
When using custom colours based on attribute with ly_lines, legend shows colour string and not group string
Hi and thanks for your work. I need to have consistent appearance of variable's colours in my plots. That's why I assigned every data entry a custom colour ("#AABBCC") based on the respective variable. Then I plot the data using ly_lines(color = colour_variable), mapping the colour property to the colour_variable. Unfortunately then, the legend then shows the raw colour strings and not the variable names. I could not override the legend nor did the 'group'-parameter work.
First of all: Am I having the wrong approach?
I see two ways of solving this:
- In Bokeh, I'd use the CategoricalColorMapper (Example). Another way is a ColumnDataSource
- Overriding the legend
Thanks. This is indeed an issue that's been bugging me for a while and I'm actively working on it. It's a major refactor dealing with color mappers as you suggest. While I'm at it I'm going to support using factors so that color mappings can stay consistent across plots. I'll post back when it's complete.
As a (ugly) workaround for now, you can iteratively use ly_lines(..., color = "#AABBCC", legend = "my label")
with each unique color, but that's not fun. I hope to get this fixed soon.
The suggested workaround does not seem to work and produces several warnings:
Warning messages: 1: In if (!is.na(ns_glyph_attrs[[ii]]$value)) ns_glyph_attrs[[ii]]$value <- "#e1e1e1" : the condition has length > 1 and only the first element will be used
I was able to achieve to achieve the desired effect using set_palette
instead, but of course this then applies to the other layers as well, which may not be desirable.
The suggested workaround does not seem to work and produces several warnings:
Warning
messages: 1: In if (!is.na(ns_glyph_attrs[[ii]]$value)) ns_glyph_attrs[[ii]]$value <- "#e1e1e1" : the condition has length > 1 and only the first element will be used`
This seems to be related to #132 (closed although unfixed), I am still struggling with this issue.