Skip to content

Instantly share code, notes, and snippets.

@yashgyy
Created December 9, 2018 11:22
Show Gist options
  • Save yashgyy/3892ce4b87162a3ce32c09de246fb3e7 to your computer and use it in GitHub Desktop.
Save yashgyy/3892ce4b87162a3ce32c09de246fb3e7 to your computer and use it in GitHub Desktop.
library(igraph)
library(ggplot2)
library(dplyr)
read.csv("socidataset.csv") -> a
ggplot(aes(Sign),data=a)+geom_bar(fill=c("Red","Green"))+labs(title="Trust and Distrust")
sort(table(a$X..FromNodeId),decreasing=T)[1:10] -> Top
barplot(Top,space = 0.5,main = "Nodes Having highest out Degree")
sort(table(a$ToNodeId),decreasing=T)[1:10] -> L2
barplot(L2,space = 0.5,main = "Nodes Having highest in Degree")
as.numeric(names(Top)) -> Index
table(a[Index %in% a$X..FromNodeId,]$Sign) -> Plotting
barplot(Plotting,main="Signs in Top 10 outdegree Nodes")
for (i in 1:50){
plot(graph_from_data_frame(a[1:280,]))
}
plot(graph_from_data_frame(filter(a,X..FromNodeId==8897)))
plot(graph_from_data_frame(head(filter(a,ToNodeId==80),50)))
plot(graph_from_data_frame(filter(a,X..FromNodeId==8897,ToNodeId==80)))
closeness(graph_from_data_frame(a)) -> Close #79973 How Many Steps are require to move to other node
centr_betw(graph_from_data_frame(a)) -> Close1
plot(graph_from_data_frame(filter(a,(X..FromNodeId==79973|ToNodeId==79973))))
plot(graph_from_data_frame(filter(a,(X..FromNodeId==142|ToNodeId==142)))) #Centrality 142 Most of the pass through this
#About 1.4 percent
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment