我正在尝试为使用PCA数据创建的配对图添加标签。有两个问题,第一个是当我添加标签时,它们似乎在不同的地方重复,并且不遵循正确的数据分布。第二个是当我添加标签时,我的点消失了。
我的代码如下:
#the data
project.pca <- prcomp(t(isometh))
minids =c("Sh3.2","Sh3.3","Sh11.1","Sh7.1","Sh7.2","Sh7.3","SNI10.1","SNI10.2","SNI20.2","SNI4.3","SNI6.1","SNI6.2")
#Pairs Plot
par(cex=1.0, cex.axis=0.8, cex.main=0.8)
pairs(project.pca$x[,1:6],
col = "black",
main = "Principal components analysis pairs-plot\nPCs 1-6",
pch = 16,
panel = function(x,...) {
text(project.pca$x,
labels = minids,
cex= 0.5, pos=3)
}
)
project.pca
str(project.pca)
List of 5
$ sdev : num [1:12] 22.3 21.8 21.7 21.4 21.3 ...
$ rotation: num [1:1072923, 1:12] 0.000324 -0.000354 0.000399 -0.000328 -0.001728 ...
..- attr(*, "dimnames")=List of 2
.. ..$ : NULL
.. ..$ : chr [1:12] "PC1" "PC2" "PC3" "PC4" ...
$ center : num [1:1072923] 0.978 0.967 0.937 0.834 0.873 ...
$ scale : logi FALSE
$ x : num [1:12, 1:12] -32.323 -7.952 -4.466 -5.436 0.188 ...
..- attr(*, "dimnames")=List of 2
.. ..$ : chr [1:12] "M6-Sham-3.2" "M6-Sham-3.3" "M6-Sham11.1" "M6-Sham7.1" ...
.. ..$ : chr [1:12] "PC1" "PC2" "PC3" "PC4" ...
- attr(*, "class")= chr "prcomp"
编辑:将点和文本添加为单独的参数会产生以下内容:
par(cex=1.0, cex.axis=0.5, cex.main=0.5)
pairs(project.pca$x[,7:12], col="black", main="Principal components analysis pairs-plot\nPCs 7-12", pch=20)
points(project.pca$x, col="black", pch=20, cex=1)
text(project.pca$x, labels=ids, cex= 0.7, pos=3)