Advertisement
Guest User

Untitled

a guest
Nov 30th, 2015
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. # load required library
  2. # if you don't have igraph installed, remove the `#` from line 3
  3. # install.packages("igraph")
  4. library(igraph)
  5.  
  6. # first set your "working directory", this is where R will try to load/save files by default, I wanted my files on the desktop, which for my computer is "C:/Users/Remi-Work/Desktop/" and YOURS WILL BE DIFFERENT.
  7. #Please change to the directory of your choice. The code will not work unless you have downloaded the CHONeII.csv to that chosen directory
  8. setwd("C:/Users/Remi-Work/Desktop/")
  9. CHONeII <- read.csv("CHONeII.csv", row.names=1,header = F, skip=1)
  10.  
  11. # re-format the data
  12. CHONeII[is.na(CHONeII)] <- 0 # change na's to 0's
  13. colnames(CHONeII) <- rownames(CHONeII) # make sensible column names
  14. CHONeII <- as.matrix(CHONeII) # make the dataframe into a matrix
  15.  
  16. g <- graph_from_adjacency_matrix(as.matrix(CHONeII)) #create graph
  17. png("CHONeII.png",height=600,width=600) # open .png file
  18. # plot the graph, the first 11 projects/nodes (1.x.x) will be light blue and the last 8 will be blue (2.x.x)
  19. plot.igraph(g,vertex.color=c(rep("lightblue",11),rep("yellow",8)),edge.arrow.size=.6)
  20. dev.off() # close .png file
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement