This is a test version of Biostars. For the public version, visit https://www.biostars.org.
PCoA in ggplot2 and Adonis results

I am trying to check beta diversity with Adonis and comparing the result with a plot in ggplot2. Adonis gives me a significant difference between 2 groups but the plot shows no separation of profiles. I suspect and error in my code for the plot. Would anyone have an idea?

This is my code for the plot:

f <- read_xlsx("dataset.xlsx")
f1 <- f[,-1:-2]    # remove column names

dist <- vegdist(f1, method = "bray")

pcoa <- cmdscale(dist, k=2, eig=TRUE, add=TRUE)   # eig needed for percentage explained, 'add' makes all eig positive
positions <- pcoa$points       #pcoa is a list after line 14, has to be changed to be used in ggplot
colnames(positions) <- c("PCoA1", "PCoA2")

pcoa$eig

percent_explained1 <- 100 * pcoa$eig / sum(pcoa$eig)    #data for axes
percent_explained1[1:2] 

d_mat <- as.data.frame(positions)
fig_f <- f[,1:2]
d_set <- cbind(d_mat, fig_f) 

centroid <- d_set%>%
  group_by(sample_name_lims) %>%
  summarize(PCoA1 = mean(PCoA1),
            PCoA2 = mean(PCoA2))

ggplot(d_set, aes(x=PCoA1, y=PCoA2, color=sample_name_lims)) +     
  geom_point() +
  geom_point(data=centroid,
             mapping=aes(x=PCoA1, y=PCoA2, color=sample_name_lims),
             shape=15, size=3, show.legend = FALSE)+
  stat_ellipse()+
  scale_color_manual(name=NULL,
                     values=c("blue", "red"),
                     breaks=c("CASE", "CONTROL"),
                     labels=c("case", "control")) +
  coord_fixed() +
  labs(x = "PC 1 (14.8%)",
       y = "PC 2 (8.5%)") +
  theme_classic()+
  theme(legend.position = c(0.95, 0.95))

For Adonis,I used this standard code:

#Adonis2 calculation of difference between species
#distance data from above: dist <- vegdist(f1, method = "bray")     

adonis2(dist~sample_name_lims, data = f, method = "bray")
r pcoa

Please provide the stats and the plot. Also, please use markdown to format your posts on here.

I've fixed their formatting.

Here are the numbers I get with Adonis:

                             Df  SumOfSqs      R2         F           Pr(>F)  

sample_name_lims 1 0.2794 0.01231 1.9324 0.035 * Residual 155 22.4107 0.98769

Total 156 22.6901 1.00000

Signif. codes: 0 ‘*’ 0.001 ‘’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

plotted graph

Please do not add answers unless you're answering the top level question. Instead, use Add Comment or Add Reply as appropriate. I've moved your post to the right location this time, please be more careful in the future.

1 answer

Based on the stats you've provided, I think the big takeaway from this exercise is that you should try to understand the rest of the stats output table, rather than focusing on the p-value.

The adonis output shows the variable sample_name_lims has an R2 of 0.012 and an F(1) of 1.932. These suggest the significant effect is very small, equating to around 1% of the observed variance. The PCA you've shown is likely realistic, and the significant effect will be observed in later PCs, when the PCs variance explained is similar to the R2 value.

Yes, that makes a lot of sense. Thank you for pointing that out!

Log in to answer this question.