if(interactive()) {
# undirected graph
policeGraphUn = toaGraph("dallaspolice_officer_vertices", "dallaspolice_officer_edges_un",
directed = FALSE, key = "officer", source = "officer1", target = "officer2",
vertexAttrnames = c("offense_count"), edgeAttrnames = c("weight"))
communities = computeGraphClusters(conn, policeGraphUn, type="connected",
createMembership = TRUE, includeMembership = TRUE,
distanceTableName = "public.shortestpathdistances",
membershipTableName = "public.clustermembership")
# get first 5 largest connected components as graphs
cluster_graphs = computeGraphClustersAsGraphs(conn, communities = communities, ids = 1:5)
# visualize component 2
library(GGally)
ggnet2(cluster_graphs[[2]], node.label="vertex.names", node.size="offense_count",
node.color="color", legend.position="none")
# compute connected components for certain type of subgraph that
# includes only verteics that start with the letters
communities2 = computeGraphClusters(conn, policeGraphUn, type="connected", membership = TRUE,
distanceTableName = "public.shortestpathdistances",
vertexWhere = "officer ~ '[A-Z].*'",
edgeWhere = "weight > 0.36")
}
Run the code above in your browser using DataLab