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)')
}
Run the code above in your browser using DataLab