Series Hack
Sometimes you have several sources of data, and you want to visualize them by displaying color mapping from a group (i.e., color of plot objects corresponds to their group).
Let's assume we have three samples with different y-values and the same x-values
So you can try something like that:
But unfortunately, "lets-plot" doesn't support it — legend is not displayed (because of Lets-Plot limitations). So you need to gather them into one layer. You need to change your data - add grouping variable (so now each point has exactly three parameters: x and y coordinates and its group).
DataFrame solution
In case a similar situation occurred with a dataframe, it is even easier to solve it with the gather
function
xs | ysA | ysB | ysC |
---|---|---|---|
1 | 1 | 0.5 | 3 |
2 | 2.5 | 1.5 | 5 |
3 | 3 | 3 | 2 |
4 | 3.5 | 1.5 | 3 |
5 | 5 | 0 | 5 |
For example, we cant to build several bars:
xs | group | ys |
---|---|---|
1 | A | 1 |
1 | B | 0.5 |
1 | C | 3 |
2 | A | 2.5 |
2 | B | 1.5 |