Created
June 9, 2014 11:57
-
-
Save nicolewhite/376f0ee878a740092f69 to your computer and use it in GitHub Desktop.
Community detection in R.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(RNeo4j) | |
library(igraph) | |
graph = startGraph("http://localhost:7474/db/data/") | |
clear(graph) | |
create_users = "FOREACH (i IN RANGE(1,50) | CREATE (:User {id:i, name:'name ' + i})) | |
WITH 1 AS dummy | |
MATCH (a:User), (b:User) | |
WITH a, b | |
WHERE (a.id % 5 = b.id % 5 AND rand() < 0.2) OR rand() < 0.005 | |
CREATE UNIQUE (a)-[:KNOWS]-(b)" | |
cypher(graph, create_users) | |
addConstraint(graph, "User", "name") | |
adj = adjacencyMatrix(graph, | |
label = "User", | |
key = "name", | |
type = "KNOWS") | |
g = graph.adjacency(adj, diag = F) | |
g$layout = layout.fruchterman.reingold(g) | |
plot(g) | |
V(g)$color = edge.betweenness.community(g, directed = F)$membership | |
plot(g) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment