SpiecEasi icon indicating copy to clipboard operation
SpiecEasi copied to clipboard

Coloring plot_network

Open gastronaut82 opened this issue 1 year ago • 3 comments

Hi there, I constructed a network at the family level for my microbial data set, but I want to color the dots by Phylum. I'm having a lot of trouble doing this.

Here's my code:

**xt<-microbiome::transform(ex1, 'clr') mb<-spiec.easi(xt, method='mb', lambda.min.ratio=1e-2, nlambda=20, pulsar.params=list(rep.num=50))

ig2.mb <-adj2igraph(getRefit(mb), vertex.attr = list(name=as.vector(tax_table(xt)[,"Family'])))

plot_network(ig2.mb, xt, type='taxa')**

My code successfully creates the network at the family level, but I can't color by phylum. I have tried:

plot_network(ig2.mb, xt, type='taxa', color="Phylum") which gives me

Error: Must request at least one colour from a hue palette.

Then I've tried,

plot_network(ig2.mb, xt, type='taxa', color=tax_table(xt)[,"Phylum"])

which gives me

Error in parse_expr(): ! x must contain exactly 1 expression, not 26.

Help!

Thanks

gastronaut82 avatar Oct 05 '23 14:10 gastronaut82

xt<-microbiome::transform(ex1, 'clr')

First of all, don't do this ⬆️ . spiec.easi applies a clr transformation with a pseudocount addition so the data you are supplying is incorrect.

plot_network is a phyloseq function, so I'm not entire sure what's going on. If I had to guess, the Phylum column contains all missing values or something. Without the looking at your data, I can't be sure.

zdk123 avatar Oct 05 '23 15:10 zdk123

I see thank you - I thought you had to CLR transform first. Okay, I will try to work with igraph directly to color accordingly

gastronaut82 avatar Oct 05 '23 15:10 gastronaut82

Relatedly - do you recommend rarefaction prior to applying Spiec-Easi?

gastronaut82 avatar Oct 12 '23 02:10 gastronaut82