File: scores.boxplot.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 (55 lines) | stat: -rw-r--r-- 2,104 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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# 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/
#
scores.boxplot <- function(corr_matrix_list, name_list, filepathroot, elite=25, high=275){
  if (is.null(filepathroot)) {
    filename <- paste(tempdir(), "/BOXPLOT.png", sep = "")
  }else{
    filename <- paste(filepathroot, "_BOXPLOT.png", sep = "")
  }
  corr_tab <- sapply(corr_matrix_list, function(x){as.vector(x)})
  nb_objects <- length(corr_matrix_list)
  

  message(paste("Boxplot elements :", nb_objects))
  
  png(filename, width = 600, height = 400, units = "px", pointsize = 12)
    oldpar <- par(no.readonly = TRUE) 
	on.exit(par(oldpar)) 
	boxplot(corr_tab, names = name_list, xlab="Z-score", cex.lab=1.5, cex.axis=0.90, col = "grey", outcol = "grey", horizontal=T, las=1)
    for(i in 1:nb_objects){
      matrix <- corr_matrix_list[i]
      X <- upper.tri(matrix,diag=FALSE)             
      increasing_corr <- sort(corr_tab[,i])
      decreasing_corr <- sort(corr_tab[,i], decreasing= TRUE)
      
      top_high <- decreasing_corr[1:high*2]
      points(top_high, rep(i,length(top_high)), pch=16, col="dodgerblue")
      
      top_elite <- decreasing_corr[1:elite*2]
      points(top_elite, rep(i,length(top_elite)), pch=16, col="blue")
      
      bottom_high <- increasing_corr[1:high*2]
      points(bottom_high, rep(i,length(bottom_high)), pch=16, col="pink")
      
      bottom_elite <- increasing_corr[1:elite*2]
      points(bottom_elite, rep(i,length(bottom_elite)), pch=16, col="red")
    }
    
    #Draw a line at position v
    abline(v=4, lty=2)			
    
    #Box with special line width
    box(lwd = 3)
  dev.off()
}