![](/img/trans.png)
[英]How do I implement a non-default dissimilarity metric with vegan function metaMDS()?
[英]How do I display labels from data on Dissimilarity matrix using Coldiss function rather than default numbers?
我想我已经阅读了互联网上所有提及Coldiss的页面,但仍无法使标签正确显示。 在我插入的图像中,矩阵看起来不错,但是标签是默认数字(因此对于独立图像来说没有用),并且在有序矩阵中矩阵正确排序,但标签没有重新排序,这没有任何意义。
[矩阵输出图像] [1]
我的问题是:1)如何使标签正确地订购有序矩阵? 如果订购后热图中的单元格正在更改颜色,则各个标签也应不同。
2)是否可以编辑Coldiss函数以使用我的隔离标签(可以在第一行或第一列中找到)来标记热图,而不是默认编号?
这是我正在运行的代码。
library(gclus)
library(ape)
source("coldiss.txt")
tree<-read.tree("BP_SNPS_only-BioNJ_tree_100BS")
PatristicDistMatrix100BS<-cophenetic.phylo(tree)
coldiss(D = PatristicDistMatrix100BS, nc = 4, byrank = TRUE, diag = TRUE)
这是coldiss.txt文件:
# coldiss()
# Color plots of a dissimilarity matrix, without and with ordering
#
# License: GPL-2
# Author: Francois Gillet, 23 August 2012
#
"coldiss" <- function(D, nc = 4, byrank = TRUE, diag = FALSE)
{
require(gclus)
if (max(D)>1) D <- D/max(D)
if (byrank) {
spe.color <- dmat.color(1-D, cm.colors(nc))
}
else {
spe.color <- dmat.color(1-D, byrank=FALSE, cm.colors(nc))
}
spe.o <- order.single(1-D)
speo.color <- spe.color[spe.o, spe.o]
op <- par(mfrow=c(1,2), pty="s")
if (diag) {
plotcolors(spe.color, rlabels=attributes(D)$Labels,
main="Dissimilarity Matrix",
dlabels=attributes(D)$Labels)
plotcolors(speo.color, rlabels=attributes(D)$Labels[spe.o],
main="Ordered Dissimilarity Matrix",
dlabels=attributes(D)$Labels[spe.o])
}
else {
plotcolors(spe.color, rlabels=attributes(D)$Labels,
main="Dissimilarity Matrix")
plotcolors(speo.color, rlabels=attributes(D)$Labels[spe.o],
main="Ordered Dissimilarity Matrix")
}
par(op)
}
# Usage:
# coldiss(D = dissimilarity.matrix, nc = 4, byrank = TRUE, diag = FALSE)
# If D is not a dissimilarity matrix (max(D) > 1), then D is divided by max(D)
# nc number of colours (classes)
# byrank= TRUE equal-sized classes
# byrank= FALSE equal-length intervals
# diag = TRUE print object labels also on the diagonal
# Example:
# coldiss(spe.dj, nc=9, byrank=F, diag=T)
这是PatristicDistMatrix100BS的缩写版本: CDC-B043_1995 CDC-A267_1994 CDC-A161_1992 CDC-C931_1998 CDC-B043_1995 0 0.00099 0.00099 0.00166 CDC-A267_1994 0.00099 0 0.00066 0.00133 CDC-A161_1992 0.00099 0.00066 0.00066 0 0.00133 CDC-C931_1998
我希望它能提供所有相关信息,并感谢您提供的任何帮助,即使它是完全不同的功能。
代码没有错。 我认为的主要问题是您已经加载了其他一些软件包。 我也有同样的问题,但是当我单独尝试时,它可以按您的要求很好地工作。 只需删除其他软件包或单独计算即可。 有关更多详细信息,请参阅本文档第三章的代码( http://adn.biol.umontreal.ca/~numericalecology/numecolR/ )。 这是我使用的代码。
(必须在ade4之后加载纯素,以避免发生一些冲突)
library(ade4)
library(vegan)
library(gclus)
library(cluster)
library(FD)
文件必须位于工作目录中。 您可以从Internet通过此链接( https://github.com/JoeyBernhardt/NumericalEcology )搜索此文件。
source("coldiss.R")
source("panelutils.R")
然后计算您的相异矩阵并使用代码进行绘图
BCD <- vegdist(df[-1])
coldiss(BCD, byrank = FALSE, diag = TRUE)
希望它会起作用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.