R/RC_PCA.R

Defines functions RC_PCA

Documented in RC_PCA

###############################################################################
# PCA
###############################################################################
RC_PCA = function(Data, Design, Project_Name, ColorVar = NULL){
  tmp = ColorVar
  # PCA run
  res.pca = PCA(Data,  graph = FALSE)

  # PCA plot
  if(is.null(tmp)) {
    p = fviz_pca_ind(res.pca, label = "none") # hide individual labels)
  }else{
    p = fviz_pca_ind(res.pca,
                     label = "none", # hide individual labels
                     col.ind = Design[, tmp], # color by groups
                     palette = Design[, tmp] %>% unique %>% length %>% viridis,
                     addEllipses = TRUE # Concentration ellipses
    )
  }

  # The function will return:
  return(p)
}
bvittrant/RCommon documentation built on May 4, 2020, 3:04 p.m.