block by timelyportfolio 0ae64825cf9b3278faf9

NCAA Division 1 Football 2015 Game Network

Full Screen

Built with blockbuilder.org

NCAA Division 1 Football Games

As I started work on building an htmlwidget for a d3.js adjacency matrix, I realized what probably should have been obvious. An adjacency matrix is really just a subset of heatmap, so I decided to try to blend the NCAA college football adjacency matrix idea from Matthew Lincoln’s Shiny Adjacency Plot app with RStudio’s d3heatmap.

Fortunately @octonion has already scraped the data and made it available as a tsv.

Thanks

Thanks to everyone who shared their ideas and code to make this fairly painless and easy.

R Code

I would love for you to fork, extend, modify, improve, and enjoy the code.

# adjacency network with 2015 NCAA football data
#   https://github.com/octonion/football

library(dplyr)
library(igraph)
library(pipeR)

# get game data
"https://cdn.rawgit.com/octonion/football/master/ncaa/tsv/ncaa_games_2016.tsv" %>>%
  read.delim(stringsAsFactors = FALSE) %>>%
  mutate( opponent_name = gsub(x=opponent_name,pattern = "(%\\n)[\\s]{2,}", replacement = "", perl =T ) )-> games

# get school meta data
"https://cdn.rawgit.com/octonion/football/master/ncaa/tsv/ncaa_schools_2016.tsv" %>>%
  read.delim(stringsAsFactors = FALSE) -> schools

# join schools and games to only get division 1 games
games %>>%
  inner_join( schools ) %>>%
  filter( division_id == 11 ) %>>%
  inner_join( schools, c( "opponent_id" = "school_id" )) %>>%
  filter( division_id.y == 11) %>>%
  (
    list(
      nodes = rbind(
        select(., id = school_id, name = school_name.x),
        select(
          .,
          id = opponent_id,
          name = opponent_name
        )
      ) %>>% unique,
      edges = select(., source = school_id, target = opponent_id)
    )
  ) -> game_network

graph_from_data_frame(
  game_network$edges,
  vertices = game_network$nodes,
  directed = FALSE
) %>>%
  get.adjacency(sparse = FALSE) %>>%
  d3heatmap(col = "Blues")