Boxplot visualization colours through qurro and songbird

Good morning to everyone,
I’ve used songbird and the visualization tool qurro to analyze the ASVs variability in my samples and highlight the key differences through a differential analysis.
I’m trying to get an individual boxplot for each of the most relevant taxa, at different taxonomic levels. I’m planning to make a ‘summary’ figure showing their behaviour.

My question here is pretty basic…

Look at these two plots, referring to two differentially represented families…

As you can see by the legends on the right , the boxplots colours aren’t homogeneous among the different barplots, but the colour palette is ‘shifted’ if the given family isn’t found in one of the conditions…

In this other example shown below, everything works fine since the family is represented in all the 6 conditions and none of them is missing.

I’d like the boxplots to be always the same colour per condition, among different taxa barplots, to make my summary homogeneous and more readable.

Of course, in an overall figure I can recolour the plot with a different legend by hand, but this would be quite tedious since I’m analyzing a lot of taxa.

Is there any quicker way to make the visualizer qurro perform this?

I’m tagging the songbird developer, @mortonjt

Thanks in advance!

Hi @Sparkle,

This is a good question! Unfortunately, ensuring this sort of "consistency" isn't currently doable in just the Qurro graphical interface -- although I have opened up an issue to allow for manual recoloring of sample groups similar to what Emperor has.

The current workaround for this is editing the specification in the Vega-Lite language -- you can style your chart however you want to in this language, but learning it can take some time. Here's how you'd make sure the colorscheme is consistent with these boxplots using Vega-Lite.

First off, let's start with the moving pictures tutorial dataset: here I've just selected an arbitrary log-ratio and set the sample boxplot to group samples by BodySite, but this should generalize to other datasets.

  1. Click the circle (with the ...) at the top-right of the sample plot, then click Open in Vega Editor.

  2. This will open a new tab/window in the Vega-Editor. The pane on the left contains the Vega-Lite specification of this plot, and the pane on the right shows a preview of what this plot looks like.

(Sidenote: you can change the spacing of the plot (e.g. making the boxes less spaced-out) by messing with the "view" settings at the top of the left pane -- for example, you can set "width" to 100 instead of 400.)

  1. In the left pane, ctrl-F for "encoding". You should see something like:

    "encoding": {
        ... maybe other stuff here ...
        "color": {"field": "BodySite", "type": "nominal"},
        ... maybe other stuff here ...

    (For your plots, instead of BodySite you should see Replicate -- this is just the field by which your samples are grouped in the boxplot.)

  2. The "color" section is the important thing here. To set a specific color for each sample group, you'll need to add on a "scale" section here. Here is an example of doing this for the q2-moving-pictures boxplot:

    "encoding": {
        ... maybe other stuff here ...
        "color": {
            "field": "BodySite",
            "type": "nominal",
            "scale": {
                  "domain": ["gut", "left palm", "right palm", "tongue"],
                  "range": ["#000", "#f00", "#0f0", "#00f"]
        ... maybe other stuff here ...

    And the resulting plot:

These colors are kind of ugly :), but hopefully you get the idea. The main thing to notice is the 4 lines starting with "scale" -- here, you can manually set the color for each sample group (the group names are in domain, and the actual colors are in range). Here I've used Hex triplet notation to set colors, but I think you can also use basic color names (e.g. red) if you want. (sidenote:
if you want to use the exact same colors as in the default categorical color scheme (tableau10), it's just a matter of picking the exact colors to use -- I think this link has the hex colors for tableau10.)

Once you're satisfied with these colors, you can just copy-paste that block into the Vega-Lite spec for other boxplots. The same colors should be used across sample groups, even if some sample groups are missing:

(this is the log-ratio of variabile to Bacteroides -- I just tried to pick a log-ratio that purposefully doesn't cover all samples.)

One side effect is that all samples are included in the color legend (so in the above figure, left palm and tongue still show up in the legend). I don't know of a good way around this besides manually removing stuff from the scale, sorry -- but of course you could always just crop this out if you're showing multiple boxplots with the same colorscheme side-by-side in a paper.

Anyway! Sorry for the long post, but hopefully this all helps.


Hello, thanks for your answer!
It worked! However, it still requires me to edit the Vega-Lite code by hand, and work on each plot one-by-one, rather than having a default palette.

This is a good question! Unfortunately, ensuring this sort of “consistency” isn’t currently doable in just the Qurro graphical interface – although I have opened up an issue to allow for manual recoloring of sample groups similar to what Emperor has.

I really hope this will be supported soon!

1 Like

Glad it worked! Yes, this solution is a little cumbersome, sorry… making this easier is on my radar :slight_smile:

One workaround is – once you’ve got a palette you know you like for a set of boxplots – downloading the specification for each boxplot, and then using a script to automatically apply that palette to each of the boxplots’ specifications. This reduces some of the hands-on work, hopefully (esp if you have like 10 boxplots of the same data but different log-ratios).

If you’re not comfortable with programming that may be more work than it’s worth, but if you feel like giving it a shot we did something similar for our paper here (see for an example of auto-modifying Vega-Lite specs).


This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.