phyloseq icon indicating copy to clipboard operation
phyloseq copied to clipboard

plot_ordination color and shape variables were not found

Open sentausa opened this issue 9 years ago • 15 comments

Dear Joey,

I am trying to make some ordination plots on my data, but I always encounter errors when I use type = "samples" using plot_ordination.

> mydata phyloseq-class experiment-level object otu_table() OTU Table: [ 9930 taxa and 260 samples ] sample_data() Sample Data: [ 260 samples by 1 sample variables ] tax_table() Taxonomy Table: [ 9930 taxa by 6 taxonomic ranks ] > colnames(sample_data(mydata)) [1] "Set" > class(sample_data(mydata)$Set) [1] "factor"

> my.PCoA <- ordinate(mydata, "PCoA", "bray") > plot_ordination(mydata, my.PCoA, type = "taxa", color = "phylum")

beautiful colorful plot appears

> plot_ordination(mydata, my.PCoA, type = "samples", color = "Set", shape = "Set") No available covariate data to map on the points for this plot 'type' Warning messages: 1: In plot_ordination(mydata, my.PCoA, type = "samples", color = "Set", : Color variable was not found in the available data you provided.No color mapped. 2: In plot_ordination(mydata, my.PCoA, type = "samples", color = "Set", : Shape variable was not found in the available data you provided.No shape mapped.

a plot appears but only in black

Do I have perhaps too many taxa and samples? I saw a similar issue #416, but it does not seem to have clear solutions for me.

So, could you please help me on this? Thanks very much in advance.

sentausa avatar Oct 19 '15 16:10 sentausa

hmm this is strange. I don't think your error has to do with whether the type is "samples" or "taxa", but rather the variable you're passing to color and shape and the formatting of your sample_data. Btw, the default behavior or plot_ordination is to plot samples, so you could try removing that parameter from your command.

Did you import your sample data with a biom file? It seemed like from the previous post that importing it manually as a data frame and then using the merge_phyloseq command to add it to the phyloseq object would work. I also wonder if this problem is due to your sample_data only being 1 column. I don't have a lot of time right now to look through this, but maybe these tips will be useful.

michberr avatar Oct 21 '15 16:10 michberr

Thank you Michelle. I imported it manually from a tab-delimited OTU table resulting from our pipeline and added it using merge_phyloseq. I also suspected the problem might come from my sample_data being only 1 column. I'm trying to put more column(s) and we'll see if it'll work. Thanks again!

sentausa avatar Oct 21 '15 16:10 sentausa

@sentausa ,

@michberr is correct. you do not have any sample variables in your data object. Did you expect otherwise? Since you haven't provided a MRE, there's no further debugging we can help with here. Very unlikely this is a phyloseq problem. Please see the tutorials that explain "manually importing" sample data into phyloseq. There are lots of examples of this floating around online, and in the vignettes.

If you have a following issue that is not the same as the one posted here, please post a new issue.

Thanks for your feedback and interest in phyloseq. Good luck!

joey

joey711 avatar Oct 23 '15 17:10 joey711

Yes, it turned out that after I added more columns in my sample_data, everything works just as expected. I thought that at least one sample variable was enough to produce an ordination plot :-p Thank you!

sentausa avatar Oct 23 '15 17:10 sentausa

I would like to reopen this issue as it represents a true bug. plot_ordination fails to map variables from the sample_data when there is only one column.

Example with 1 column

data(GlobalPatterns) gp1 <- GlobalPatterns sample_data(gp1) <- sample_data(gp1)[ ,c("SampleType") ] my.PCoA1 <- ordinate(gp1, "PCoA", "bray") plot_ordination(gp2, my.PCoA1, type = "samples", color = "SampleType")

Output:

No available covariate data to map on the points for this plot type Warning message: In plot_ordination(gp1, my.PCoA1, type = "samples", color = "SampleType") : Color variable was not found in the available data you provided.No color mapped.

rplot1

Example with two columns

gp2 <- GlobalPatterns sample_data(gp2) <- sample_data(GlobalPatterns)[ ,c("SampleType","Description") ] my.PCoA2 <- ordinate(gp2, "PCoA", "bray") plot_ordination(gp2, my.PCoA2, type = "samples", color = "SampleType")

rplot2

michberr avatar Oct 23 '15 22:10 michberr

you make a good point :)

joey711 avatar Oct 23 '15 23:10 joey711

My temporary fix is to add a "dummy variable" in sample_data: sample_data(phyloseq_object)[ , 2] <- sample_data(phyloseq_object)[ ,1] #########

sessionInfo() R version 3.3.1 (2016-06-21) Platform: x86_64-apple-darwin13.4.0 (64-bit) Running under: OS X 10.10.5 (Yosemite)

other attached packages: [1] randomForest_4.6-12 phyloseq_1.16.2 vegan_2.4-0 lattice_0.20-33
[5] permute_0.9-0

husenzhang avatar Aug 02 '16 15:08 husenzhang

Is there a fix for this already?

adityabandla avatar Nov 04 '17 19:11 adityabandla

So glad I found this bug report, it was driving me nuts!

The dummy variable thing fixed it.

wschierd avatar Dec 06 '17 03:12 wschierd

ncol(sample_data) must be >1, it help me.

wangzhichao1990 avatar Mar 16 '19 07:03 wangzhichao1990

So this bug was never fixed? 6 years later? I'm not that familiar with ggplot yet and I lost a lot of time thinking it was an error on my part...

silvtal avatar Jul 21 '21 09:07 silvtal

I have the same problem these days that driving me nuts.. then I finally find the solution, thank you.. To add a "dummy_variable" in sample_data, it works.

biomaker52 avatar Mar 20 '22 17:03 biomaker52

I never knew this bug existed until I used sample_data with one column. Thank you guys for suggesting adding an extra dummy column six years ago.

abdimicro avatar Jan 16 '23 05:01 abdimicro

This is very helpful. Thank you all.

akshaymalwade avatar Sep 08 '23 14:09 akshaymalwade

So this bug was never fixed? 6 years later? I'm not that familiar with ggplot yet and I lost a lot of time thinking it was an error on my part...

I just lost half an hour because of this bug again.

silvtal avatar Apr 09 '24 06:04 silvtal