summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--R Scripts/plot-data-prep.R42
1 files changed, 42 insertions, 0 deletions
diff --git a/R Scripts/plot-data-prep.R b/R Scripts/plot-data-prep.R
new file mode 100644
index 0000000..b56ca1f
--- /dev/null
+++ b/R Scripts/plot-data-prep.R
@@ -0,0 +1,42 @@
+library(igraph)
+library(grid)
+library(gridExtra)
+
+# create bipartite graph
+edges = c(1,6,
+ 1,7,
+ 2,8,
+ 3,7,
+ 3,8,
+ 3,10,
+ 4,7,
+ 4,8,
+ 5,6,
+ 5,9)
+g = graph.bipartite(c(rep(T,5),rep(F,5)),edges)
+
+# need to plot table separately from graphs and combine outside R
+par(mfrow=c(1,2))
+
+# (A) data table
+data = data.frame(get.edgelist(g))
+data$X2 = toupper(letters[data$X2-5])
+colnames(data) = c('Event Code (EC)','Identity Code (IC)')
+grid.newpage(F)
+plot(graph(1:2),layout=matrix(c(1,1,1,1),ncol=2))
+grid.table(data)
+
+# (B) bipartite person-event graph
+layout = matrix(c(rep(seq(4,0,-1),2),rep(0,5),rep(1,5)),ncol=2)
+labels = c( 1:5, toupper(letters[1:5]) )
+cols = c( rep('#1a9850',5), rep('#1f78b4',5) )
+plot(g, layout=layout[,2:1], vertex.color=cols,edge.color='black',
+ vertex.frame.color=NA,vertex.size=30,vertex.label=labels,
+ vertex.label.color='white',vertex.label.family='sans')
+
+# (C) unipartite person-person graph
+g2 = bipartite.projection(g)$proj1
+plot(g2, vertex.color='#1f78b4', edge.color='black',
+ vertex.frame.color=NA,vertex.size=30,vertex.label=toupper(letters[1:5]),
+ vertex.label.color='white',vertex.label.family='sans')
+