Reputation: 23
Here I have another 'graphical' problem:
I have obtained from MOTHUR the following distance matrix (coming from a weighted unifrac analysis):
20
F3D0
F3D1 0.222664
F3D141 0.157368 0.293308
F3D142 0.180278 0.319198 0.0944511
F3D143 0.157659 0.290975 0.0545202 0.0761392
F3D144 0.199909 0.34045 0.104358 0.086418 0.089473
F3D145 0.207946 0.348532 0.107841 0.076302 0.0940067 0.051632
F3D146 0.117877 0.253996 0.0891617 0.130867 0.0882064 0.134407 0.138415
F3D147 0.197256 0.336583 0.102114 0.0764106 0.0890669 0.0514887 0.0479297 0.135324
F3D148 0.173824 0.311951 0.0606815 0.0648557 0.056463 0.074914 0.0811015 0.111996 0.0709027
F3D149 0.145614 0.276632 0.0462779 0.105512 0.0628737 0.10902 0.114584 0.0739466 0.107123 0.0690412
F3D150 0.129557 0.277624 0.0840909 0.128305 0.0863231 0.140256 0.145381 0.0744572 0.13672 0.113564 0.0659831
F3D2 0.133531 0.216587 0.160832 0.186833 0.176061 0.214934 0.215261 0.152591 0.205629 0.188325 0.156313 0.153841
F3D3 0.213102 0.305651 0.123818 0.113021 0.139376 0.148558 0.13853 0.174377 0.139851 0.126329 0.131294 0.166738 0.137784
F3D5 0.128668 0.185235 0.167733 0.205183 0.176585 0.224806 0.230984 0.14497 0.223492 0.18933 0.153624 0.148617 0.127574 0.192433
F3D6 0.139411 0.236633 0.135418 0.124848 0.134198 0.175098 0.166205 0.118905 0.166144 0.151842 0.120964 0.12724 0.0950943 0.119852 0.129523
F3D7 0.198884 0.315888 0.130385 0.0989168 0.131945 0.14625 0.126203 0.173689 0.128993 0.121373 0.140199 0.152123 0.152893 0.0906675 0.186674 0.111134
F3D8 0.178656 0.18783 0.205737 0.22104 0.219858 0.268701 0.2644 0.184943 0.268051 0.229503 0.1979 0.20035 0.164427 0.203089 0.119084 0.142398 0.185551
F3D9 0.153265 0.186706 0.196143 0.21504 0.20728 0.262127 0.255558 0.174563 0.2607 0.221969 0.192437 0.185154 0.13976 0.195538 0.0973901 0.127619 0.177605 0.0558726
Mock 0.653789 0.645344 0.633297 0.623553 0.633903 0.633135 0.63394 0.635815 0.645332 0.636453 0.629143 0.646918 0.663222 0.639517 0.649722 0.64073 0.654882 0.63988 0.646155
As this distance matrix come from a PCoA, what I want to do is to plot these distances in an ordination plot with R.
Any idea on how to doing this?
Thanks a lot
Upvotes: 1
Views: 2237
Reputation: 23
Thanks to @R18, finally I could manage with this issue.
For the distance table I uploaded, the solution that I reached was to use the following code:
library(phyloseq)
library(vegan)
M <- import_mothur_dist("pcoa_UFdistance_matrix.dist")
unifrac <- metaMDS(M, distance = M, k = 2, trymax=100)
plot(unifrac$points[,1], unifrac$points[,2], main="Principal Coordinates Analysis", col.main="red", font.main=4, xlab="PCoA 1", ylab="PCoA 2")
text(unifrac, pos=3)
Hope it will help someone!!
Upvotes: 0
Reputation: 1560
You have the vegan
library with metaMDS
function that generates coordinates for each sample using such a distance matrix as the input.
Let's call M
to your matrix, you need to run this code:
# Load the library
library(vegan)
# Use metaMDS function for 2D - plot
NMDS <- metaMDS(distance = M, k = 2)
# Plot your individuals
plot(NMDS$points[,1], NMDS$points[,2])
In NMDS$points
you have the coordinates for each of the samples. I suggest to colour the individuals according to a factor of interest such as cases and controls for example in biomedical analyses.
Upvotes: 0