david-barnett / microViz

R package for microbiome data visualization and statistics. Uses phyloseq, vegan and the tidyverse. Docker image available.
https://david-barnett.github.io/microViz/
GNU General Public License v3.0
99 stars 10 forks source link

Error in if (!all(x >= 0)) stop("Negative distances not supported!") : missing value where TRUE/FALSE needed #37

Closed Leran10 closed 1 year ago

Leran10 commented 2 years ago

Hi,

I used a subset of phyloseq object in comp_barplot(), but got error:

Error in if (!all(x >= 0)) stop("Negative distances not supported!") : missing value where TRUE/FALSE needed

I'm not sure which step of comp_barplot generated this error. Is there any way to fix this?

Thanks! Leran

david-barnett commented 2 years ago

Hi Leran, this would be thrown after the calculation of distances between samples when ordering them. I think it's failed to calculate any distances. Be sure to inspect the phyloseq that resulted from your subsetting step. How many samples and taxa does it have?

If you post an example of your code that generates this error, it might be possible to guess what happened. And/or set the sample_order argument to "asis" or "default", and inspect the output, this won't sort the samples, but viewing their composition likely gives an idea why distances couldn't be calculated.

Leran10 commented 2 years ago

Thanks for the reply!

If I set sample_order to "euclidean", this error is gone. It might be related to the similarity calculation?

My code is basically the example code in the tutorial, I changed the sample_order parameter only:

ps0 %>%
                  comp_barplot(
                    tax_level = taxa, n_taxa = 12,
                    bar_outline_colour = "white",
                     sample_order = "euclidean"
                  ) +
                   facet_grid(
                    rows = vars(Treatment), 
                    scales = "free", space = "free" # these options are critically important!
                  ) +
                  coord_flip() 
david-barnett commented 2 years ago

It will be related to the dissimilarity calculation. Are your data counts? or are they transformed in some way? Precisely which sample_order option(s) is/are giving the error? "bray" ?

You could also try re-ordering your samples with ps_seriate , this is done inside the comp_barplot function, but it may be more informative to play with it separately.