简体   繁体   中英

How to change loadings.label in PCA plot using ggplot2?

I am plotting a PCA analysis in ggplot2 and loadings.label overlap with the arrows. I want to move the labels a little to make more accessible the reading of the plot, but I can't find a way to do it. I am attaching the plot below. here is part of the data:

Linfoprolif CORT Testo  FDL Ac.GRO ifn.g il.4 Profile
1        23.76 0.27  0.96 2.41      6   307   69       1
2           NA 2.59  0.07 0.39      4   117   58        
3        25.53 0.16  0.71 2.17      5   273   54       1
4        31.67 0.88  0.07 0.55      5   211   48       1
5         6.15 0.24  0.23 1.07      5   224   48       1
6        26.19 0.74  0.04 0.60      4   308   59       1
7        10.31 0.34  0.75 2.29      7   295   49       1
8        22.30 0.42  0.07 0.63      5   271   52       1
9        24.74 0.29  1.18 2.91      4   236   56       1
10        9.51 2.19  0.07 0.40      5    54   62       2
11       22.59 0.19  0.40 3.28      4   272   58       1
12       22.01 0.28  0.04 0.54      4    67   64       1
13       39.21 0.21  0.82 1.91      4   235   56       1
14       42.07 0.32  0.16 0.70      5   362   54       3
15       13.45 0.30  0.24 2.21      6   146   68       1
16       15.08 2.19  0.08 0.34      5    58   63       2
17       20.48 0.38  1.27 2.40      4   278   52       1
18       12.10 0.83  0.11 0.53      2   146   41       1
19       61.56 0.07  0.09 1.09      9   305   52       3
20       35.06 0.59  0.05 0.67      4   220   54       1
21       33.48 0.68  0.99 1.24      3   102   58       1
22       20.56 0.94  0.06 1.71      3    58   45       2
23       26.46 0.12  0.29 1.60      3   210   55       1
24       24.91 0.56  0.11 0.55      5   108   56       1
25       29.22 0.42  2.60 1.55      3    84   69       1
26       19.30 1.63  0.02 0.78      3    62   69       2
27       14.45 0.22  0.79 1.89      4   245   59       1
28       20.89 0.72  0.04 0.57      4    85   53       1
29       26.70 0.36  1.02 2.05      3   309   45       1
30       27.83 2.66  0.04 0.54      3    52   65       2
31       34.70 0.46  0.83 1.39      5   120   65       1

and the code

library(ggfortify)
p_pca<-d_e_b[c(1,2,3,4,5,6,7)]

p_pca<-na.omit(p_pca)
pca_res <- prcomp(p_pca, scale. = TRUE)


pca_b<-autoplot(pca_res, data = d_e_b, colour = "Profile",
                loadings = TRUE, loadings.colour = 'gray30',loadings.size = 5,
                loadings.label = TRUE, loadings.label.color='black',
                loadings.label.size = 4) + theme_classic()+
  scale_colour_discrete("Profile")+
  theme(text = element_text(size = 20 ),
        axis.line.x = element_line(color="black", size = 1),
        axis.line.y = element_line(color="black", size = 1),
        axis.text.x=element_text(colour="black",angle = 360,vjust = 0.6),
        axis.text.y=element_text(colour="black"))
pca_b

Any ideas on how to solve it?

PCA 图

You can add loadings.label.repel = T inside autoplot() to offset the labels a bit.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM