rbokeh icon indicating copy to clipboard operation
rbokeh copied to clipboard

When using custom colours based on attribute with ly_lines, legend shows colour string and not group string

Open sedot42 opened this issue 8 years ago • 3 comments

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:

  1. In Bokeh, I'd use the CategoricalColorMapper (Example). Another way is a ColumnDataSource
  2. Overriding the legend

sedot42 avatar Jan 18 '17 15:01 sedot42

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.

hafen avatar Feb 17 '17 08:02 hafen

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.

dseynaev avatar Apr 10 '17 15:04 dseynaev

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.

sedot42 avatar Nov 21 '17 10:11 sedot42