How to generate an ordination plot from a distance matrix in R?
2
0
Entering edit mode
7.4 years ago

down vote favorite

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

R mothur plot PCoA ordination • 4.7k views
ADD COMMENT
1
Entering edit mode
5.8 years ago
roman.spanek ▴ 10

I was having the same issue and the following code to visualize Mothur distance matrix:

col.names <- unlist(read.table("dist.dist", nrow = 1, as.is = TRUE))
df <- as.matrix(read.table("dist.dist", fill = TRUE, skip = 1, 
                           row.names = 1))
dist = read.dist("dist.dist",diag=1)
x1 <- as.dist(as(dist, "matrix"))
X11()
hc = hclust(x1 )
plot(hc)
heatmap(as.matrix(x1))
dst <- data.matrix(x1)
library(MASS)
library(ggplot2)
library(ggrepel)

NMDS=metaMDS(dst, # Our distance matrix
                     k=2) # The number of reduced dimensions
stressplot(NMDS)
plot(NMDS)
ordiplot(NMDS,type="n")
orditorp(NMDS,display="sites",col="red",air=0.01)

Once you have NMDS result object (or CCA etc,.) it is quite straight forward

ADD COMMENT
0
Entering edit mode
7.4 years ago

Look at the plot_ordination() function (examples) in the Bioconductor package phyloseq.

ADD COMMENT
0
Entering edit mode

Thanks a lot.

However, as I do not have more than the distance matrix I copy-pasted to the post, I cannot generate a 'phyloseq' object to be used with the 'plot_ordination()' command.

Or, at least, I do not know how to do it.

Is there a way to do so without any 'otu_table' or 'taxa' files??

ADD REPLY

Login before adding your answer.

Traffic: 1980 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6