我正在为我的主人生成NMDS,现在我想用ggplot为自己的论文制作漂亮的图形。我正在研究物种如何分布在我的3个区域(我的环境( env )数据集的第1列)中。当我使用绘图功能时,请快速浏览一下NMDS:
MNDS <- metaMDS(spe, distance = "bray")
NMDS <- data.frame(NMDS1 = nmds$points[,1], NMDS2 = nmds$points[,2], Region=env$REGION)
NMDS$Lake <- rownames(NMDS)
spps <- data.frame(scores(nmds, display = "species"))
spps$species <- row.names(spps)
spps$Taxa <- trait$Taxa
spps$Trophic <- trait$Trophic.group
plot(MNDS, type = "t", main = paste("Region"))
ordiellipse(MNDS, as.factor(env[,1]), display = "sites", kind ="sd", conf = 0.95, label = T)
很好。我的问题是当我尝试使用veganCovEllipse函数在ggplot中重现NMDS时。现在,椭圆形比我使用ordiellipse时小很多。我还注意到,如果更改veganCovEllipse函数的比例值,则会得到更大的椭圆。
veganCovEllipse<-function (cov, center = c(0, 0), scale = 1, npoints = 100)
{
theta <- (0:npoints) * 2 * pi/npoints
Circle <- cbind(cos(theta), sin(theta))
t(center + scale * t(Circle %*% chol(cov)))
}
df_ell <- data.frame()
for(g in levels(NMDS$Region)){
df_ell <- rbind(df_ell, cbind(as.data.frame(with(NMDS[NMDS$Region==g,],
veganCovEllipse(cov.wt(cbind(NMDS1,NMDS2),wt=rep(1/length(NMDS1),
length(NMDS1)))$cov,center=c(mean(NMDS1),mean(NMDS2)))))
,Region=g))
}
graph.nmds <- ggplot(data = NMDS, aes(y = NMDS2, x = NMDS1))+
geom_path(data = df_ell, aes(x = NMDS1, y = NMDS2, group = Region))+
geom_text(data=NMDS,aes(x=NMDS1,y=NMDS2,label=Lake),size=2.5,
hjust= -0.25, vjust= 0.5, colour = "#666666") +
geom_point(aes(shape = Region), size = 3) +
geom_text(data=spps, aes(x=spps$NMDS1, y=spps$NMDS2, label=species, colour = Trophic), size = 3, alpha = 0.75) +
scale_shape_manual(values=c(15, 17, 16), limits=c("YUKON", "ALASKA", "NWT"),labels=c("Yukon", "Alaska", "NWT"))+
coord_cartesian(xlim = c(-1.5,2))+
scale_colour_manual(values = c("#CC0033", "#339900", "#990099", "#666600", "#FF9900", "#0000FF"),
limits=c("carnivore", "herbivore", "immature", "omniherb", "omnivore", "parasitic"))+
theme_bw()+
theme(panel.background = element_blank(),
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
plot.background = element_blank())
graph.nmds
与使用ordiellipse相比,为什么使用veganCovEllipse时椭圆形这么小?
而且,正如我所说的,当我在veganCovEllipse函数中将比例尺更改为2时,我得到了更大的椭圆。为什么?标尺在此功能中代表什么?
谢谢:)