library(igraph) setwd("~/Documents/Violence Cascades/") # plot cascade sizes data = read.csv('Results/components_dist-91515.csv',header=F) data = data[order(data$V1),] sizes = data$V1 counts = data$V2 plot(sizes,counts,log='xy',type='o',lwd=3, xlab='Size of Cascade', ylab='Number of Cascades', main='Distribution of Cascade Sizes') # plot cascades edges = read.csv('Results/edges-91515.csv',header=F, col.names=c('v1','t1','v2','t2','dist')) for(id in unique(union(edges$v1,edges$v2))){ e = edges[union(match(id,edges$v1), match(id,edges$v2)),] times = sort(union(e$t1[e$v1==id],e$t2[e$v2==id])) if (length(times)>1){ for(time in times[-1]){ idx = which(time==times) edges$v1[as.numeric(rownames(e))[e$t1==time]] = e$v1[e$t1==time] + (idx-1)/length(times) edges$v2[as.numeric(rownames(e))[e$t2==time]] = e$v2[e$t2==time] + (idx-1)/length(times) } } } dag = graph.data.frame(edges[,c(1,3)], directed=TRUE) table(clusters(dag)$csize) clusters = clusters(dag) membership = clusters$membership csize = clusters$csize order = rev(order(csize)) i = 4 V = which(clusters(dag)$membership==order[i]) # get all nodes in cluster cc = induced.subgraph(dag,V) Vi = vic_ids[V] Ei = intersect(which(dag_dat_vics$from[realized] %in% Vi),which(dag_dat_vics$to[realized] %in% Vi)) cc_dat = (dag_dat_vics[realized,])[Ei,] ### plot cascade ### cols = rep('lightblue',vcount(cc)) seed = which(degree(cc,mode='in')==0) cols[seed] = 'red' plot(cc,vertex.size=10,edge.arrow.size=0.5,vertex.color=cols,vertex.label.cex=1, edge.width=E(cc)$weight*20/max(E(cc)$weight),layout=layout.reingold.tilford(cc,root=seed), vertex.label=V(hyp_lcc)$vic.day[Vi]) plot(cc,vertex.size=10,edge.arrow.size=0.5,vertex.color=cols,vertex.label.cex=1, layout=layout.reingold.tilford(cc,root=seed)) ### basic graph statistics trl = mean(transitivity(cc,type='local',isolates='zero')) apl = average.path.length(cc) indeg = degree(cc,mode='in') outdeg = degree(cc,mode='out') ds = mean(cc_dat$dist)