Labeling points in a biplot

ε祈祈猫儿з 提交于 2021-01-27 04:54:34

问题


I have performed a PCA and drawn a biplot in R.

pca1= princomp (~ data$X250 + data$X500 + data$shear, scores=TRUE, cor=TRUE, rownames=data[,1])
biplot(pca1, xlab="PC 1", ylab="PC 2", pch=20)

Currently the labels on the biplot are the row numbers, but I would like the point labels to be the plot names of my data. My data has 81 rows.

I have tried:

text (pca1[1:81], pca1[1:81], labels = row.names(data))
text (1:81, 1:81, labels = row.names(data))
text (pca1$comp.1[1:81], pca1$comp.2[1:81], labels = row.names(data))

回答1:


Try giving

rownames(data)<-data[,1] 

before using princomp




回答2:


If you don't want to set the rownames on your original data set ("df", below), you can also do it by passing the xlabs argument to biplot:

p<-princomp(df) 
biplot(p,xlabs=df[,1])


来源:https://stackoverflow.com/questions/20194526/labeling-points-in-a-biplot

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!