File: network.plot.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 (38 lines) | stat: -rw-r--r-- 1,224 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
# 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/
#
network.plot <- function(top_pairs, filepathroot){
  pairs_i <- top_pairs$pairs_i
  pairs_j <- top_pairs$pairs_j

   if (is.null(filepathroot)) {
      filename <- paste(tempdir(), "/NETWORK.pdf", sep="")
   } else {
      filename <- paste(filepathroot, "_NETWORK.pdf", sep="")
   }

  pdf(filename)
    # create data:
    links <- data.frame(source= pairs_i, target= pairs_j)
    
    # Turn it into igraph object
    network <- graph_from_data_frame(d= links, directed= F) 
    
    # Count the number of degree for each node:
    deg <- degree(network, mode= "all")
    
    # Plot
    plot(network, vertex.size= deg*6, vertex.color= rgb(0.1,0.7,0.8,0.5))
  
  dev.off()
}