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")
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:
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
Please do not add answers unless you're answering the top level question. Instead, use
Add Comment
orAdd Reply
as appropriate. I've moved your post to the right location this time, please be more careful in the future.