summaryrefslogtreecommitdiffstats
path: root/R Scripts/plot-graph.R
diff options
context:
space:
mode:
authorBen Green <bgreen@g.harvard.edu>2015-06-08 15:21:51 -0400
committerBen Green <bgreen@g.harvard.edu>2015-06-08 15:21:51 -0400
commit1739e9f5706bb8a73de5dbf0b467de49ea040898 (patch)
tree6f1d0f166986c5f0757be9b40d8eeb3409ab022c /R Scripts/plot-graph.R
parente5dada202c34521618bf82a086093c342841e5e8 (diff)
downloadcriminal_cascades-1739e9f5706bb8a73de5dbf0b467de49ea040898.tar.gz
added my R scripts
Diffstat (limited to 'R Scripts/plot-graph.R')
-rwxr-xr-xR Scripts/plot-graph.R22
1 files changed, 22 insertions, 0 deletions
diff --git a/R Scripts/plot-graph.R b/R Scripts/plot-graph.R
new file mode 100755
index 0000000..b6f9341
--- /dev/null
+++ b/R Scripts/plot-graph.R
@@ -0,0 +1,22 @@
+#### plot the victims and non-victims of the network
+cols = rep('lightgrey',vcount(g)) #number of nodes in g
+cols[V(g)$vic==1] = 'red'
+shapes = rep('circle',vcount(g))
+shapes[V(g)$vic==1] = 'square'
+plot(g, layout=layout.kamada.kawai, vertex.label=NA, vertex.color=cols, vertex.shape=shapes,vertex.size=2)
+legend('topleft', legend=c("non-victim", "victim"), pch=c(16,15), col=c("lightgrey", "red"), inset=0.1)
+
+#### plot the neighborhood of a node
+v = 10
+v1 = unlist(neighborhood(lcc,nodes=v,order=1))
+v2 = unlist(neighborhood(lcc,nodes=v,order=2))
+v3 = unlist(neighborhood(lcc,nodes=v,order=3))
+v3 = setdiff(v3,v2)
+v2 = setdiff(v2,v1)
+v1 = setdiff(v1,v)
+cols = rep('lightgrey',vcount(g))
+cols[v] = 'red'
+cols[v1] = 'blue'
+cols[v2] = 'green'
+cols[v3] = 'black'
+plot(g, layout=layout.kamada.kawai, vertex.label=NA, vertex.color=cols,vertex.size=2)