Description Usage Arguments Value Examples
Compute top vertices by the metric values on a graph.
1 2 3 4 |
channel |
connection object as returned by |
graph |
an object of class |
type |
choose between graph metrics to compute: |
top |
the number of vertices to return. If |
rankFunction |
one of |
weight |
logical or character: if logical then |
vertexWhere |
SQL WHERE clause limiting data from the vertex table. This value when not null
overrides corresponding value |
edgeWhere |
SQL WHERE clause limiting data from the edge table. This value when not null
overrides corresponding value |
keyAsFactor |
logical: should key column be converted to factor? If |
allTables |
pre-built information about existing tables. |
test |
logical: if TRUE show what would be done, only (similar to parameter |
... |
other arguments passed on to Aster graph functions except for |
dataframe containing one vertice per row with key value, computed metric value, and its rank
using rankFunction
.
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)')
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.