data <- read.csv("~/data.csv1.csv", row.names = 1)
chooseCRANmirror(ind = 1)
install.packages(c("factoextra", "FactoMineR"))
## Installing packages into 'C:/Users/ifthe/AppData/Local/R/win-library/4.2'
## (as 'lib' is unspecified)
## 
##   There is a binary version available but the source version is later:
##            binary source needs_compilation
## FactoMineR   2.10   2.11              TRUE
## 
##   Binaries will be installed
## package 'factoextra' successfully unpacked and MD5 sums checked
## package 'FactoMineR' successfully unpacked and MD5 sums checked
## Warning: cannot remove prior installation of package 'FactoMineR'
## Warning in file.copy(savedcopy, lib, recursive = TRUE): problem copying
## C:\Users\ifthe\AppData\Local\R\win-library\4.2\00LOCK\FactoMineR\libs\x64\FactoMineR.dll
## to
## C:\Users\ifthe\AppData\Local\R\win-library\4.2\FactoMineR\libs\x64\FactoMineR.dll:
## Permission denied
## Warning: restored 'FactoMineR'
## 
## The downloaded binary packages are in
##  C:\Users\ifthe\AppData\Local\Temp\RtmpMR79AJ\downloaded_packages
library("factoextra")
## Warning: package 'factoextra' was built under R version 4.2.3
## Loading required package: ggplot2
## Warning: package 'ggplot2' was built under R version 4.2.3
## Welcome! Want to learn more? See two factoextra-related books at https://goo.gl/ve3WBa
library("FactoMineR")
## Warning: package 'FactoMineR' was built under R version 4.2.3
pca.data <- PCA(data[,-1], scale.unit = TRUE, graph = FALSE)
fviz_eig(pca.data, addlabels = TRUE, ylim = c(0, 70))

fviz_pca_var(pca.data, col.var = "cos2",
             gradient.cols = c("#FFCC00", "#CC9933", "#660033", "#330033"),
             repel = TRUE) 

pca.data <- PCA(t(data[,-1]), scale.unit = TRUE, graph = FALSE)
fviz_pca_ind(pca.data, col.ind = "cos2", 
                  gradient.cols = c("#FFCC00", "#CC9933", "#660033", "#330033"), 
                  repel = TRUE)

install.packages("devtools")
## Installing package into 'C:/Users/ifthe/AppData/Local/R/win-library/4.2'
## (as 'lib' is unspecified)
## package 'devtools' successfully unpacked and MD5 sums checked
## 
## The downloaded binary packages are in
##  C:\Users\ifthe\AppData\Local\Temp\RtmpMR79AJ\downloaded_packages
devtools::install_github("kassambara/ggpubr")
## WARNING: Rtools is required to build R packages, but is not currently installed.
## 
## Please download and install Rtools 4.2 from https://cran.r-project.org/bin/windows/Rtools/.
## Skipping install of 'ggpubr' from a github remote, the SHA1 (6aeb4f70) has not changed since last install.
##   Use `force = TRUE` to force installation
library(ggpubr)
a <- fviz_pca_ind(pca.data, col.ind = "cos2", 
                  gradient.cols = c("#FFCC00", "#CC9933", "#660033", "#330033"), 
                  repel = TRUE)
ggpar(a,
      title = "Principal Component Analysis",
      xlab = "PC1", ylab = "PC2",
      legend.title = "Cos2", legend.position = "top",
      ggtheme = theme_minimal())

pca.data <- PCA(data[,-1], scale.unit = TRUE,ncp = 2, graph = FALSE)
data$Lineage <- as.factor(data$Lineage)
install.packages("RColorBrewer")
## Installing package into 'C:/Users/ifthe/AppData/Local/R/win-library/4.2'
## (as 'lib' is unspecified)
## package 'RColorBrewer' successfully unpacked and MD5 sums checked
## 
## The downloaded binary packages are in
##  C:\Users\ifthe\AppData\Local\Temp\RtmpMR79AJ\downloaded_packages
library(RColorBrewer)
nb.cols <- 3
mycolors <- colorRampPalette(brewer.pal(3, "Set1"))(nb.cols)
a <- fviz_pca_ind(pca.data, col.ind = data$Lineage,
                  palette = mycolors, addEllipses = TRUE)
ggpar(a,
      title = "Principal Component Analysis",
      xlab = "PC1", ylab = "PC2",
      legend.title = "Cell type", legend.position = "top",
      ggtheme = theme_minimal())