小编Lew*_*Lew的帖子

将椭圆添加到主成分分析(PCA)图中

我无法在单个站点PCA因子图上添加分组变量省略号,其中还包括PCA可变因子箭头.

我的代码:

prin_comp<-rda(data[,2:9], scale=TRUE)
pca_scores<-scores(prin_comp)

#sites=individual site PC1 & PC2 scores, Waterbody=Row Grouping Variable.
#site scores in the PCA plot are stratified by Waterbody type.

plot(pca_scores$sites[,1],
     pca_scores$sites[,2],
     pch=21,
     bg=point_colors[data$Waterbody],
     xlim=c(-2,2), 
     ylim=c(-2,2),
     xlab=x_axis_text,
     ylab=y_axis_text)

#species=column PCA1 & PCA2 Response variables
arrows(0,0,pca_scores$species[,1],pca_scores$species[,2],lwd=1,length=0.2)

#I want to draw 'Waterbody' Grouping Variable ellipses that encompass completely, 
# their appropriate individual site scores (this is to visualise total error/variance).
Run Code Online (Sandbox Code Playgroud)

我试图使用dataellipse,plotellipses和ellipse函数,但无济于事.无知就是赢得了这一点.如果我没有提供足够的信息,请告诉我.

数据(log10转换):

dput(data)

structure(list(Waterbody = structure(c(4L, 4L, 4L, 4L, 4L, 4L, 
4L, 4L, 4L, 4L, 4L, 4L, …
Run Code Online (Sandbox Code Playgroud)

plot r pca ggbiplot

20
推荐指数
2
解决办法
2万
查看次数

标签 统计

ggbiplot ×1

pca ×1

plot ×1

r ×1