File: pca_screeplot.R

package info (click to toggle)
r-cran-bios2cor 2.2.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,520 kB
  • sloc: makefile: 5
file content (36 lines) | stat: -rw-r--r-- 1,165 bytes parent folder | download
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
32
33
34
35
36
# Bios2cor is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# See the GNU General Public License at:
# http://www.gnu.org/licenses/
#
pca_screeplot <- function(pca_struct, filepathroot){
  pca_coord <- pca_struct$coord
  
  nb_component <- length(pca_coord[1,])
  pca_positions <- rownames(pca_coord)

  components <- 1:nb_component
  
  variances <- unlist(lapply(1:nb_component, function(x){var(pca_coord[,x])}))

  if(is.null(filepathroot)) {
    filename <- paste(tempdir(), "/SCREEPLOT.png", sep="")
  } else {
    filename <- paste(filepathroot, "_SCREEPLOT.png", sep="")
  }  
  
  png(filename, width = 600, height = 600, units = "px")
    plot(components, variances, main= basename(filename))
    lines(components, variances)
  dev.off()
}