How to assign one specific color to a specific taxa in a phyloseq object after using colorRampPalette

483 views Asked by At

I have difficulties on R for creating the color palette i'd like to get... I simply want to plot distributions of the different phyla of my phyloseq object (called physeq) in barplots. In order to assign a color to each phylum (so the color doesn't change after subsetting the phyloseq object), I used these lines :

See how many phyla are in the whole dataset:

length(table(tax_table(physeq)[,"Phylum"])) #I have 28 different phyla

Create a random color palette with 28 different colors:

color = grDevices::colors()[grep('gr(a|e)y', grDevices::colors(), invert = T)]

getPalette = colorRampPalette(sample(color, 28,replace=F))

Assign one color to one phylum:

PhylumList = unique(tax_table(physeq)[,"Phylum"])

PhylumPalette = getPalette(length(PhylumList))

names(PhylumPalette) = PhylumList

However, I have a phylum called "undetermined_Eukaryota" that I would like it to have the color black.

Do you have a solution to get in a same palette :

  1. a random color palette for 27 phyla

and

  1. a color fixed as black for the phylum "undetermined_Eukaryota"

Thank you very very much for you help!

0

There are 0 answers