Adonis anylysis using bray-curtis matrix

Hello everyone,

I want to perform adonis analysis in R using the Bray-curtis matrix that I have. I do not know what the error is that I am getting.
I am using the following codes:

#Adonis analysis


metadata <- read_excel("metadata.xlsx")

distance <- read_excel("bray_curtis.xlsx")
dist_mat <- distance %>% remove_rownames %>% column_to_rownames(var="sample_id")
colnames(dist_mat) <- c("sample_id")
meta_distance <- inner_join(metadata, distance, by="sample_id")

all_dist <- meta_distance %>%
select(all_of(.[["sample_id"]])) %>%

adonis(all_dist~Farm, data = meta_distance)

The bray_curtis matrix:
bray_curtis_dm.txt (16.6 KB)

The metadata:
metadata.txt (14.3 KB)

I would appreciate any help!


Hello Armin,

Can you post the error you are seeing as well?

Just a note, I also do downstream analysis in R with tidyverse and vegan, and they use different data structures. Vegan expects base r data.frames (with row names and column names), while tidyverse uses the tidyverse data structures (like tibbles without row names and column names) and this trips me up all the time...

1 Like

Hello Colin,

Thank you for your comment.
The error that I've got is the following:
Error in contrasts<-(*tmp*, value = contr.funs[1 + isOF[nn]]) :
contrasts can be applied only to factors with 2 or more levels

Exactly. As you said there is something wrong regarding the row names and column names.
When I use "inner_join" function it gives me:
# A tibble: 0 x 62
# ... with 62 variables: sample_id <chr>, Farm <chr>, Variety <chr>, Treat <chr>,

I think " A tibble: 0 x 62" is a problem. Isn't?

Thank you

Yep. That tibble is empty :crying_cat_face:
(inner_join failed successfully)

Step through your process one function at a time, checking the output along the way, and see if everything is where you expect it.

I also got this great reminder about using vegan:

Vegan is very old-school in all the best and worst ways.

Keep investigating and let us know what you find! :mag_right: