The thing I did try was adding fake datapoints at ...
# datascience
c
The thing I did try was adding fake datapoints at the beginning of the plot, one for each label. By controlling the order, I hoped to control the colors. But it didn’t seem to have the effect I wanted.
i
Hi @Carter! You can try to control the order using
asDiscrete()
function (see Python equivalent
as_discrete
: https://lets-plot.org/pages/api/lets_plot.mapping.as_discrete.html?highlight=order) In the simplest case your labels will be ordered alphabetically. You can also add some numeric variable to your dataframe and use it for ordering instead (see
orderBy
parameter).
c
Ok, let me give that a try and I'll report back. Thank you for the suggestion!
👍 1
Thanks for the suggestion. I tried it like this:
Copy code
geomLine(showLegend = true) {
            x = X
            y = Y
            group = GROUPS
            color = asDiscrete(LABELS, order = 1)
        }
For my sleep data, it does make the visualizations more stable if each graph has the same set of labels. However, I have another situation where all the labels may not always occur in a given set of data. (E.g. imagine a night where the user never has a moment of awake during sleep) As far as I can tell, there’s not a good way to make the automatic color selection deterministic when the set of labels change unless there’s an explicit mapping of label to a specific color.
i
I see, the
scaleColorManual
is the way to go then. Try to pass a list of all labels via the
breaks
parameter and a list of matching colors via the
values
parameter. You can specify colors by their names or hex codes (i.e. strings like "#FF0000" for "red") or RGB strings : "rgb(255, 0, 0)" or instances of java.awt.Color.
c
I think I’ve hit two independent bugs in the setting scaleColorManual: • If there’s only a single color/label explicitly set, it’ll crash with a divide by zero. I filed an issue https://github.com/JetBrains/lets-plot/issues/506 • If there are multiple label colors set, but the dataframe only contains a single label, then sometimes the graph chooses the wrong color. I filed an issue https://github.com/JetBrains/lets-plot/issues/507
i
👍