2017-10-20 258 views
1

嗨,所以我想绘制我在r中的bray-curtis不相似矩阵中的组合数据的nmds。我已经能够应用ordielipse() ,ordihull()和甚至改变基于由cutree()创建一个hclst的)使用来自纯素包沙丘数据如何使用基于SIMPROF的彩色/符号点绘制nmds

data(dune) 
Dune.dis <- vegdist(Dune, method = "bray) 
Dune.mds <- metaMDS(Dune, distance = "bray", k=2) 

#hierarchical cluster 
clua <- hclust(Dune.dis, "average") 
plot(clua, hang = -1) 
# set groupings 
rect.hclust(clua, 4) 
grp <- cutree(clua, 4) 

#plot mds 
plot(Dune.mds, display = "sites", type = "text", cex = 1.5) 

#show groupings 
ordielipse(Dune.mds, group = grp, border =1, col ="red", lwd = 3) 

甚至着色点只是由组因子(

例如颜色cutree

colvec <- c("red2", "cyan", "deeppink3", "green3") 
colvec[grp] 
plot(Dune.mds, display = "sites", type = "text", cex = 1.5) #or use type = "points" 
points(P4.mds, col = colvec[c2], bg =colvec[c2], pch=21) 

但是我真正想要做的是使用SIMPROF函数使用包“clustsig”,然后根据重要的分组对颜色点进行着色 - 这更像是一种技术编码语言 - 我确信有一种方法可以创建因素串,但我相信有一种更有效的方式来做到这一点

继承人到目前为止我的代码为:

simp <- simprof(Dune.dis, num.expected = 1000, num.simulated = 999, method.cluster = "average", method.distance = "braycurtis", alpha = 0.05, sample.orientation = "row") 
#plot dendrogram  
simprof.plot(simp, plot = TRUE) 

现在,我只是不知道如何做下一步绘制NMDS使用由SIMPROF定义的分组 - 我如何使SIMPROF结果成为一个因子字符串,而不用直接输入它我自己它自己?

在此先感谢。

回答

1

你写过你知道如何从hclust对象获得颜色cutree。然后阅读clustsig::simprof的文档。这表示simprof在其结果对象中返回一个hclust对象。它还返回numgroups这是建议的群集数量。现在,您已掌握了使用您已知的 hclust所需的全部信息。如果您的simprof结果被称为simp,请使用cutree(simp$hclust, simp$numgroups)来提取对应于clustsig::simprof结果的整数向量,并将其用于颜色。

我从来没有用过simprofclustsig,但我从文档中收集了所有这些信息。

+0

非常感谢!我很轻松地工作 - 非常明确的回应!我仍在编写代码并理解R软件包的文档 - 但我还有一段路要走,所以感谢您的帮助。 – Lmm