Skip to main content
  • Home
  • Development
  • Documentation
  • Donate
  • Operational login
  • Browse the archive

swh logo
SoftwareHeritage
Software
Heritage
Archive
Features
  • Search

  • Downloads

  • Save code now

  • Add forge now

  • Help

  • de48f4b
  • /
  • PCA.R
Raw File Download

To reference or cite the objects present in the Software Heritage archive, permalinks based on SoftWare Hash IDentifiers (SWHIDs) must be used.
Select below a type of object currently browsed in order to display its associated SWHID and permalink.

  • content
  • directory
content badge
swh:1:cnt:a69d996bdc796fc217f048b544147398d01c634a
directory badge
swh:1:dir:de48f4b3b44890b63710117d534c1001e76424e9

This interface enables to generate software citations, provided that the root directory of browsed objects contains a citation.cff or codemeta.json file.
Select below a type of object currently browsed in order to generate citations for them.

  • content
  • directory
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
PCA.R
### Author: Franck Soubès
### Bioinformatics Master Degree - University of Bordeaux, France
### Link: https://github.com/GeT-TRiX/MA_Trix_App/
### Where: GET-TRiX's facility
### Application: MATRiX is a shiny application for Mining and functional Analysis of TRanscriptomics data
### Licence: GPL-3.0


#' res.pca is a function that computed a PCA of non-normalized data with the FactoMineR package
#'
#' @param workingset A data frame corresponding to the WorkingSet
#' @param scale A boolean value; by default this value is set to False for non-normalized data
#'
#' @return A data frame with PCA attributes
#'
#' @export

res.pca <- function(workingset, scale = F) {

  myt = transpose(workingset)
  row.names(myt) = colnames(workingset)

  PCAres = PCA(myt,
               scale.unit = F,
               graph = F)

  return(PCAres)
}


#' eboulis is a function which aim is to display the eigenvalues of the data with the package factoextra
#'
#' @param PCAres A data frame with PCA attributes
#'
#' @return A ggplot object
#'
#' @export

eboulis <- function(PCAres){

  p <- fviz_eig(PCAres, addlabels=TRUE, hjust = -0.3, barfill="white", barcolor ="darkblue", linecolor ="red")
  p + theme(panel.grid.major = element_blank(),  panel.grid.minor = element_blank(),panel.border = element_blank(),
            panel.background = element_blank())
  p + labs(title = "Variances - PCA", x = "Principal Components", y = "% of variances")

  return(p)
}

#' PCAplot is a function that return a factoextra object of PCA type
#'
#' @param PCAres A data frame with PCA attributes
#' @param myax A numeric vector of length 2 specifying the dimensions to be plotted
#' @param elips A boolean value to add ellipse to the data distribution  for the different groups; default = False
#' @param rep A boolean value to avoid overlaps between the label points
#' @param mylevel A data frame corresponding to the pData
#' @param mylabsize A numeric value representing the police size to display for the different labels
#' @param dispelip A numeric value representing the ellipsoid dispersion
#' @param labeled A character to display labels and/or points
#' @param pal A color object from the RcolorBrewer package
#'
#' @return A ggplot object
#'
#' @export

PCAplot <- function(PCAres, myax = c(1,2), elips = T , rep = T , mylevel = groups$Grp,  mylabsize = 4, dispelip = 0.8 , labeled = 'all', pal = brewer.pal(8, "Dark2")){


  p <- fviz_mca_ind(PCAres, label= labeled , habillage = mylevel, addEllipses= elips ,
                    ellipse.level= 0.8, repel = rep, axes = myax, pointsize = 2 , labelsize = mylabsize)


  return(p + scale_color_manual(values=pal))
}


# res.pca <- function(workingset, restab ,scale = F, variable = F) {
#
#   myt = transpose(workingset)
#   row.names(myt) = colnames(workingset)
#
#   if(variable)
#     colnames(myt) =  make.names(restab$GeneName, unique=TRUE)
#
#   PCAres = PCA(myt,
#                scale.unit = F,
#                graph = F)
#
#   return(PCAres)
# }










back to top

Software Heritage — Copyright (C) 2015–2026, The Software Heritage developers. License: GNU AGPLv3+.
The source code of Software Heritage itself is available on our development forge.
The source code files archived by Software Heritage are available under their own copyright and licenses.
Terms of use: Archive access, API— Content policy— Contact— JavaScript license information— Web API