我不能在我的NMD图上制作两个多边形和envfit。我可以单独做。
1 /多边形:
ggplot(pts, aes(x=MDS1,y=MDS2,colur=as.factor(V3),fill=as.factor(V3))) +
geom_polygon(data=hulls,alpha=0.5) +
geom_point(size=0) +
geom_text(aes(label=sp$Site, color=factor(sp$Site)),size=4)
(见下图1)
2 / envfit:
ggplot(pts, aes(x=MDS1,y=MDS2)) +
geom_point(size=0) +
geom_text(aes(label=sp$Site, color=factor(sp$Site)),size=4) +
geom_segment(data=envector.df,
aes(x=0,xend=NMDS1*3,y=0,yend=NMDS2*3),
arrow = arrow(length = unit(0.2,"cm")),
colour="black", inherit_aes=FALSE) +
geom_text(data=envector.df,
aes(x=NMDS1*3,y=NMDS2*3,label=species),
size=5)+
coord_fixed()
(见下图2)
但是,当我合并两个代码时,我收到如下错误消息。
df <- pts
find_hull <- function(df) df[chull(df$MDS1,df$MDS2),]
library(plyr)
hulls <- ddply(df,"V3", find_hull)
ggplot(pts, aes(x=MDS1, y=MDS2, color=as.factor(V3),
fill=as.factor(V3))) +
geom_polygon(data=hulls,alpha=0.5) +
geom_point(size=0) +
geom_text(aes(label=sp$Site, color=factor(sp$Site)),size=4) +
geom_segment(data=envector.df,aes(x=0,xend=NMDS1*3,y=0,yend=NMDS2*3),
arrow = arrow(length = unit(0.2, "cm")), colour="black",
inherit_aes=FALSE) +
geom_text(data=envector.df, aes(x=NMDS1*3,y=NMDS2*3,label=species),
size=5) +
coord_fixed()
is.factor(x)中的错误:object&#39; V3&#39;找不到
V3是我的数据中的网站pts或df
names(df)
[1] "MDS1" "MDS2" "V3"
names(pts)
[1] "MDS1" "MDS2" "V3"
感谢有人能给我一些帮助!谢谢!
[]