簡體   English   中英

如何 label 在 PCA Plot 中的單個數據點

[英]how to label an individual data point in PCA Plot

我使用 R 中的 prcomp 創建了一個 PCA plot 使用:

> input <- read_excel("input.xlsx")                                                          
> data<-input[,!names(input) %in% "gene"]
> data1<-t(as.matrix(data[-1])) %*% as.matrix(data[-1]) / ncol(data)
> res.pca <- prcomp(data1, scale = TRUE)
> par(cex=0.5)
> plot(res.pca$x[,1],res.pca$x[,2], xlab="PC1", ylab = "PC2", main = "PC1 / PC2 - plot") 

input.xlsx文件如下所示:

gene    Sample1 Sample2     Sample3
A   13.932431   5.366284    6.93992
B   21.111017   0.662061    1.563687
C   26.471751   0.932416    1.673144
D   27.597507   36.591138   28.371248
E   35.324703   0           1.462438

我想將 label 添加到代表此 PCA Sample1中 Sample1 的數據點,並將其塗成紅色。 謝謝你的幫助。

下面是一個使用 R 自帶的iris數據集的例子:

iris <- iris[, -5]   # Delete column with species
iris.pca <- prcomp(iris)
plot(iris.pca$x[, 1], iris.pca$x[, 2], xlab="PC1", ylab = "PC2", main = "PC1 / PC2 - plot")
text(iris.pca$x[1, 1], iris.pca$x[1, 2], "First Row", pos=4)

這假設要標記的行包含在 pca 中。 主成分分析圖

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM