简体   繁体   English

PCA plot 和额外的 package。 如何将常规标签更改为示例名称?

[英]PCA plot with factoextra package. How do I change regular labels to sample names?

I've read similar questions about that here, but still didn't work for my problem.我在这里读过类似的问题,但仍然没有解决我的问题。 I have a table with: columns with different kinds of pollutants levels and a column with the name of the samples.我有一个表格:包含不同种类污染物水平的列和一个包含样本名称的列。 However, in no way I can change the name of the labels (now it's numbers) to the samples names.但是,我决不能将标签的名称(现在是数字)更改为样本名称。

Here is my script:这是我的脚本:

read.csv2("PCA_ALL.csv", header=TRUE)->tabela
tabela

pca <- prcomp(~Ter+Hop+UCM+AHS+S_Chain+L_chain+Alkyl+HMW+LMW+TOC, scale = TRUE)

fviz_pca_biplot(pca, geom = c("point","text"), 
                addEllipses = TRUE, ggtheme = theme_gray(), 
                col.var = "black", repel=FALSE, 
                title = "PCA - GB", xlab="PC1 (39%)", ylab="PC2 (22%)") 

Does anyone know what I could do?有谁知道我能做什么? Thanks in advance!提前致谢!

The first column of my table is named "area", where the name of the samples are.我的表的第一列名为“area”,样本的名称所在的位置。

Here is a possibile solution:这是一个可能的解决方案:

tabela <- read.table(text="
         area  Ter  Hop   UCM   AHS S_Chain L_chain Alkyl  HMW   LMW  TOC
1   2010-2004 0.71 3.10 119.4 136.8    0.10    3.48 11.50 7.70 16.70 1.19
2   2004-1999 0.57 2.77  71.0  89.3    0.04    2.61  3.74 3.61  1.30 0.81
3   1999-1993 0.87 3.10 117.7 132.1    0.04    2.77  6.38 3.08  1.94 0.90
4   1993-1988 0.49 2.69  98.4 111.7    0.04    2.64  4.60 3.57  1.81 0.86
5   1988-1982 1.44 4.43  80.0  93.9    0.05    3.10  7.27 3.84  2.92 1.06
6   1982-1977 0.57 4.80  55.1  65.5    0.03    3.80  9.87 5.50  8.80 1.25
7   1977-1971 0.62 3.16 174.7 190.8    0.04    3.15  6.00 3.58  1.51 1.08
8   1971-1966 1.17 5.77 162.3 174.8    0.04    3.39  5.95 5.68  2.65 1.11
9   1966-1960 1.28 8.13 155.4 194.6    0.05    5.61  5.74 5.47  2.45 1.16
10 1960-1954  0.69 6.77  96.0 134.2    0.04    5.51  3.74 4.73  2.41 1.16
11  1954-1949 0.75 4.56  65.8 122.6    0.07    4.91  7.97 5.33  2.48 0.83
12  1949-1943 0.58 4.74  70.2 112.3    0.05    5.38  4.94 7.47  3.19 1.19
13  1943-1938 3.00 6.22  66.9 105.9    0.08    5.78 16.20 8.40  3.79 1.19
14  1938-1932 0.77 3.44  96.4 141.7    0.06    4.93  8.48 3.60  4.12 1.06
15  1932-1927 0.40 4.37  84.7 126.3    0.04    4.36  3.73 3.67  1.66 0.90
16  1927-1921 1.95 5.06  51.8  92.5    0.07    5.08 11.74 4.36  5.29 1.01
", header=T)

pca <- prcomp(~Ter+Hop+UCM+AHS+S_Chain+L_chain+Alkyl+HMW+LMW+TOC, scale = TRUE, data=tabela)
# Set row names for the matrix with rotated data
dimnames(pca$x)[[1]] <- tabela$area

library(factoextra)
fviz_pca_biplot(pca, geom = c("point","text"), 
                addEllipses = TRUE, ggtheme = theme_gray(), 
                col.var = "black", repel=FALSE, 
                title = "PCA - GB", xlab="PC1 (39%)", ylab="PC2 (22%)") 

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用 R 中的“factoextra”package 中的 fviz_dend function 更改树状图的标签? - How do I change the labels of a dendogram using the fviz_dend function from the “factoextra” package in R? factoextra包:如何使用可变轴而不是PCA组件轴绘制我的簇? - factoextra package: How can I plot my clusters using variable axes not PCA component axes? 如何使用PRcomp从PCA更改标签到样品名称 - How to change labels from PCA using PRcomp to sample names 如何在 factoextra 包中更改列元素图贡献的 y 标签 - How to change the y label of contributions of column elements plot in factoextra package 在 Factoextra 中创建 PCA 图后,如何过滤掉图中的个人? - How do you filter out individuals on a figure after creating a PCA plot in Factoextra? 如何将R中PCA中的一些样本名称更改为点或星等符号? - How to change the some sample names into symbols such as dots or stars in PCA in R? 如何更改 interact_plot() 中的 mod2 标签? - How do I change the mod2 labels in interact_plot()? R rugarch 包。 错误:参数名称与规范不匹配 - R rugarch package. Error: parameters names do not match specification 从FactoExtra包中的函数fviz_pca中自定义pointshape - Customization of pointshape within function fviz_pca from FactoExtra package 无法将 PCA prcomp 中的标签从行号更改为站点名称 - unable to change labels in PCA prcomp from row numbers to site names
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM