Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # load required library
- # if you don't have igraph installed, remove the `#` from line 3
- # install.packages("igraph")
- library(igraph)
- # 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.
- #Please change to the directory of your choice. The code will not work unless you have downloaded the CHONeII.csv to that chosen directory
- setwd("C:/Users/Remi-Work/Desktop/")
- CHONeII <- read.csv("CHONeII.csv", row.names=1,header = F, skip=1)
- # re-format the data
- CHONeII[is.na(CHONeII)] <- 0 # change na's to 0's
- colnames(CHONeII) <- rownames(CHONeII) # make sensible column names
- CHONeII <- as.matrix(CHONeII) # make the dataframe into a matrix
- g <- graph_from_adjacency_matrix(as.matrix(CHONeII)) #create graph
- png("CHONeII.png",height=600,width=600) # open .png file
- # 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)
- plot.igraph(g,vertex.color=c(rep("lightblue",11),rep("yellow",8)),edge.arrow.size=.6)
- dev.off() # close .png file
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement