-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcalculate_PCA.R
31 lines (31 loc) · 1.09 KB
/
calculate_PCA.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
library(factoextra)
# for dataset before batch correction
before <- as.data.frame(t(qntl_fpkm_merged))
# pca
before.pca <- prcomp(before)
# screeplot
fviz_eig(before.pca)
# plot the PCA
fviz_pca_ind(before.pca,
col.ind = "cos2", # Color by the quality of representation
gradient.cols = c("#00AFBB", "#E7B800", "#FC4E07"),
repel = TRUE # Avoid text overlapping
)+ggtitle("samples-PCA")
# plot correlation of genes
fviz_pca_var(before.pca,
col.var = "contrib", # Color by contributions to the PC
gradient.cols = c("#00AFBB", "#E7B800", "#FC4E07"),
repel = TRUE # Avoid text overlapping
)+ggtitle("genes")
# for dataset after batch correction
after <- as.data.frame(t(corrected_df))
#pca
after.pca <- prcomp(after)
# screeplot
fviz_eig(after.pca)
# plot the PCA
fviz_pca_ind(after.pca,
col.ind = "cos2", # Color by the quality of representation
gradient.cols = c("#00AFBB", "#E7B800", "#FC4E07"),
repel = TRUE # Avoid text overlapping
)+ggtitle("samples-PCA")