Created
May 15, 2017 13:06
-
-
Save mrchypark/57bf3ea4e9e9017c994050be3aba9201 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# loading packages | |
library(dplyr) | |
library(tidyr) | |
library(igraph) | |
# set sample data set | |
options(stringsAsFactors = F) | |
exd<-data.frame(comp=sample(LETTERS), | |
partner1=sample(LETTERS), | |
partner2=sample(LETTERS), | |
partner3=sample(LETTERS), | |
partner4=sample(LETTERS), | |
partner5=sample(LETTERS)) | |
exd[sample(length(letters),3),c(3,4,5,6)]<-NA | |
exd[sample(length(letters),3),c(4,5,6)]<-NA | |
exd[sample(length(letters),3),c(5,6)]<-NA | |
exd[sample(length(letters),3),c(6)]<-NA | |
# data wrangling | |
exd.info<-LETTERS | |
exd.long <- exd %>% gather(key=partNum,value=partner,-comp) %>% select(comp,partner) | |
exd.long <- exd.long %>% filter(!is.na(partner)) | |
names(exd.long)<-c("from","to") | |
# plot graph data | |
# http://kateto.net/network-visualization | |
g <- graph_from_data_frame(exd.long, directed=TRUE, vertices=exd.info) | |
plot(g) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment