PhanstielLab/plotgardener

More flexible colorby

Opened this issue · 2 comments

Hi, I wonder if there's a feature to let colorby return colors by labels. To be specific, I have a code like this colorby("isSig", palette = colorRampPalette(c("red", "grey"))). isSig is either Yes or No, which is mapped to red or grey, respectively. But if my data in plotRanges only contain "No", they will be plotted as red, because there is no Yes. This is inconvenient when I want to generate a lot of plots by using one piece of code.

It would be great if color can be specific in a "named" fashion, like c("Yes" = "red", "No" = "grey").

Thanks!

Thanks for checking out plotgardener! While there is no way right now to map colorby colors with names, you can utilize factors to get around this issue.

If you convert your isSig column to a factor specifying the levels as c("Yes", "No"), colorby will be aware of the options in this column and obey the order they are put in. The colors in the palette will be assigned to the factors in the order of the levels, so palette = colorRampPalette(c("red", "grey")) would assign "red" to "Yes" and "grey" to "No". If you specified the levels as c("No", "Yes"), the colors would be assigned in the opposite direction.

Thank you for the suggestion for naming these colors. I think that would definitely make this feature more clear. I will keep this issue open and label it as an enhancement until we specifically add this feature, but I hope my above suggestion solves your problem in the meantime.

Best,
Nicole

Thanks, this is really helpful!