computeGraphMetric: Compute top vertices by the metric values on a graph.

Description Usage Arguments Value Examples

View source: R/computeGraph.R

Description

Compute top vertices by the metric values on a graph.

Usage

1
2
3
4
computeGraphMetric(channel, graph, type = "degree", top = 10,
  rankFunction = "rank", weight = FALSE, vertexWhere = graph$vertexWhere,
  edgeWhere = graph$edgeWhere, keyAsFactor = TRUE, allTables = NULL,
  test = FALSE, ...)

Arguments

channel

connection object as returned by odbcConnect

graph

an object of class 'toagraph' referencing graph tables in Aster database.

type

choose between graph metrics to compute: 'degree', 'in-degree', 'out-degree', 'clustering', 'shortestpath', 'pagerank', 'betweenness', 'eigenvector', 'closeness', 'avg-closeness', 'k-degree', 'alt-closeness'.

top

the number of vertices to return. If top >= 0 then top vertices sorted by the metric value are returned, otherwise all vertices are returned. Returned vertices are ordered by the computed graph metric only when top >= 0.

rankFunction

one of rownumber, rank, denserank, percentrank. Rank computed and returned for each vertex and each metric type. rankFunction determines which SQL window function computes vertex rank value (default rank corresponds to SQL RANK() window function). When threshold top is greater than 0 ranking function used to limit number of vertices returned (see details).

weight

logical or character: if logical then TRUE indicates using 'weight' edge attribute, otherwise no weight used. If character then use as a name for the edge weight attribute. The edge weight may apply with types 'clustering', 'shortestpath' and centrality measures.

vertexWhere

SQL WHERE clause limiting data from the vertex table. This value when not null overrides corresponding value vertexWhere from graph (use SQL as if in WHERE clause but omit keyword WHERE).

edgeWhere

SQL WHERE clause limiting data from the edge table. This value when not null overrides corresponding value edgeWhere from graph (use SQL as if in WHERE clause but omit keyword WHERE).

keyAsFactor

logical: should key column be converted to factor? If TRUE then conversion will always take place for any of integer, numeric, or character data types.

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).

...

other arguments passed on to Aster graph functions except for EDGEWEIGHT argument - use argument weight instead. Aster function areguments are not case-sensetive.

Value

dataframe containing one vertice per row with key value, computed metric value, and its rank using rankFunction.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
if(interactive()) {
library(ggplot2)

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>")
                         
createTopMetricPlot <- function(data, metric, xlab='Officer', ylab='Degree', title) {
   p = ggplot(data) +
       geom_bar(aes_string("key", metric, fill="key"), stat='identity') +
       labs(x=xlab,y=ylab,title=title) +
       ggthemes::theme_tufte() + 
       theme(legend.position='none', 
             axis.text.x = element_text(size=16, angle = 315, vjust = 1), 
             plot.title = element_text(size=20),
             axis.ticks = element_blank())
   
   return(p)
}

# top degree officers
topDegree = computeGraphMetric(conn, policeGraphUn, type="degree", top=30)
createTopMetricPlot(topDegree, 'degree', ylab='Degree', title='Top 30 Officers by Degree') 

# top betweenness officers
topbetweenness = computeGraphMetric(conn, policeGraphUn, type='betweenness', top=25)
createTopMetricPlot(topbetweenness, 'betweenness', ylab='Betweenness', 
                    title='Top 25 Officers (Betweenness)')                     
                         
}

toaster documentation built on May 30, 2017, 3:51 a.m.