Learn R Programming

toaster (version 0.5.1)

computeGraph: Materialize Aster graph as network object in R.

Description

Results in network object representation of the graph stored in Aster tables. Usually in Aster database a graph is represented using a pair of vertice and edge tables.

Usage

computeGraph(channel, graph, v = NULL, vertexWhere = graph$vertexWhere, edgeWhere = graph$edgeWhere, allTables = NULL, test = FALSE)

Arguments

channel
connection object as returned by odbcConnect
graph
an object of class 'toagraph' referencing graph tables in Aster database.
v
a SQL SELECT that returns key values or a list of key values (corresponding to the vertex.names attribute) of the vertices to include in the graph. When not NULL this guarentees that no other vertices or edges between other vertices are included in the resulting network.
vertexWhere
optionally, a SQL WHERE clause to subset vertex table. When not NULL it overrides vertexWhere condition from the graph.
edgeWhere
optionally, a SQL WHERE clause to subset edge table. When not NULL it overrides edgeWhere condition from the graph.
allTables
pre-built information about existing tables.
test
logical: if TRUE show what would be done, only (similar to parameter test in RODBC functions: sqlQuery and sqlSave).

Details

Use caution when computing network objects stored in Aster with this function as data may include considerable amount of vertices and edges which are too large to load into a memory.

Examples

Run this code
if(interactive()) {
library(GGally)

policeGraphUn = toaGraph("dallaspolice_officer_vertices", "dallaspolice_officer_edges_un", 
                         directed = FALSE, key = "officer", 
                         source = "officer1", target = "officer2", 
                         vertexAttrnames = c("offense_count"), edgeAttrnames = c("weight"))
               
# initialize connection to Lahman baseball database in Aster 
conn = odbcDriverConnect(connection="driver={Aster ODBC Driver};
                         server=<dbhost>;port=2406;database=<dbname>;uid=<user>;pwd=<pw>")
                             
# create network object and visualize with ggplot2
net1 = computeGraph(conn, policeGraphUn)
ggnet2(net1, node.label="vertex.names", node.size="offense_count", 
       legend.position="none")
       
# network object with filters and color attribute
net2 = computeGraph(conn, policeGraphUn, vertexWhere = "officer ~ '[A-Z].*'", 
                    edgeWhere = "weight > 0.36")
net2 %v% "color" = substr(get.vertex.attribute(net2, "vertex.names"), 1, 1)
ggnet2(net2, node.label="vertex.names", node.size="offense_count", 
       size.cut=TRUE, node.color="color", legend.position="none", 
       palette = "Set2")

# networ object for subgraph of top degree vertices
topDegree = computeGraphMetric(conn, policeGraphUn, type="degree", top=50)
net3 = computeGraph(conn, policeGraphUn, v=as.list(as.character(topDegree$key)))
net3 %v% "degree" = topDegree[match(get.vertex.attribute(net3, "vertex.names"), 
                                            topDegree$key), "degree"]
ggnet2(net3, node.label="vertex.names", node.size="degree", 
       legend.position="none")
                         
}                          

Run the code above in your browser using DataLab