Skip to content

Instantly share code, notes, and snippets.

@chrishaid
Created April 12, 2016 17:49
Show Gist options
  • Save chrishaid/e958500d7735268b292a5c1b811b78eb to your computer and use it in GitHub Desktop.
Save chrishaid/e958500d7735268b292a5c1b811b78eb to your computer and use it in GitHub Desktop.
# Load packages
require(googlesheets)
require(dplyr)
require(igraph)
require(ggraph)
# get spreadsheet
x <- gs_title("Data Whiz Tool Tracker Sheet")
# get data from Product Matrix Sheet
gs <- x %>% gs_read_csv("Product Matrix", skip = 2)
# Get unique organizations
cmos<-unique(gs$Organization)
# Pull Org, Product, Use and and Subj
relations <- gs %>% select(Organization, Product, Use, Subj = Subject.s.)
# create igraph object from relations. first column is to, second is from in the
# directed graph
d<-graph_from_data_frame(relations, directed = FALSE, vertices = NULL)
# add degrees attribure to each vertice
V(d)$degrees <- degree(d, mode = 'in')
# add CMO status to each vertice.
V(d)$cmo <- names(V(d)) %in% cmos
# Graph it!
ggraph(d, 'igraph', algorithm = 'kk') +
geom_edge_fan(aes(alpha = ..index..)) +
geom_node_point(aes(size = degrees, color=cmo)) +
geom_node_text(aes(angle = nAngle(x, y), label = name),
size=3, hjust='outward', check_overlap = TRUE) +
scale_edge_alpha('Uses', guide = 'edge_direction') +
scale_color_manual(values = c("gray40", "hotpink")) +
theme_bw() +
theme(panel.border = element_blank(),
panel.margin = element_blank(),
panel.grid = element_blank(),
axis.ticks = element_blank(),
axis.text = element_blank(),
axis.title = element_blank())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment