From 1739e9f5706bb8a73de5dbf0b467de49ea040898 Mon Sep 17 00:00:00 2001 From: Ben Green Date: Mon, 8 Jun 2015 15:21:51 -0400 Subject: added my R scripts --- R Scripts/plot-graph.R | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100755 R Scripts/plot-graph.R (limited to 'R Scripts/plot-graph.R') 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) -- cgit v1.2.3-70-g09d2