ANCOMBC Barplot Colors

Hi qiime2 team,

Is there any way to change the colors of the bars in vega editor for ANCOMBC results? I have several of these graphs that have both "enriched" and "depleted" which are colored in blue and orange respectively (see photo below). This graph however, only has depleted taxa, but it's in blue. I'd like to make it consistent with the other graphs in terms of color scheme for clarity.

Thanks in advance!

3 Likes

This is a great idea!

I've opened an issue here:

I'm not sure the best way to edit the graph while we work on this fix...

Let's see what other folks recommend!

1 Like

If that sounds good to @colinbrislawn I'm happy to step in!

If you look at the top right corner of your DA barplot QZV you'll see this drop-down menu:

Here you can download as SVG and edit it directly. If you don't have experience with SVG you can do the following:

  1. Click on "Open in Vega Editor".

  2. Locate the Layer -> Encoding -> Color section of the code (in my case, lines 11-16):

  3. You will see 4 parameters: "field", "sort", "title" and "type". We will add another parameter called "scale", with two sub-parameters: "domain" and "range". Parameter "domain" will be a list containing the possible tags, ["depleted", "enriched"]. Parameter "type" will contain the colors for the tags, e.g. ["red", "green"] (you can use HTML codes too, like ["#ff00ef", "#00ff8b"])¹. My new code looks like this (I added lines 13-16):

Code block for you to copy:

"scale": {
  "domain": ["depleted", "enriched"],
  "range": ["red", "green"]
},
  1. On the top menu, click on Export -> PNG / SVG / the format you like.

Before :frowning:

After :cowboy_hat_face:

Best,

Sergio

--

Footnotes

¹ I just realized the order of the list matters regarding the plot legend. I assume switching the order of the lists (["enriched", "depleted"] and also switch colors) would result in the plot legend with the original order.

6 Likes

Hi @salias,

Thank you for the quick and thorough explanation as well as code. It worked! The footnote solution also worked perfectly.

Really appreciate your help and @colinbrislawn adding this to the list of improvements.

4 Likes

Alternatively you read the qza file in R using qiime2R and create a plot in ggplot. You can manipulate graph here with larger freedom.

1 Like

Hi @Bish ,

Yes, that would be another really useful way to proceed. In this regard, unfortunately qiime2R cannot read ANCOM-BC results (the format is not supported so only a list of internal files and provenance is imported). I opened a PR addressing this some months ago (thanks to your post I remembered that I need to lint the code I added):

In the meantime, you can always use these custom functions I coded that essentially do the same as the code I put in the PR:

Best,

Sergio

Edit: PR was accepted so you can use the last version of qiiime2R directly!

1 Like