Sophie E. Hill
May 4, 2021
CHIPS Public Seminar: Advancing Health Policy Through Data Visualizations
How do we create data visualizations that are useful, accessible, and true to the data?
This seemed like a good candidate for a data visualization.
library(tidyverse)
library(visNetwork)
# load network data
people <- read_csv("people_ex1.csv")
connections <- read_csv("connections_ex1.csv")
# add attributes
people$label <- people$id
connections$title <- paste0("<p>", connections$detail, "</p>")
# create network graph
visNetwork(people, connections) %>%
visInteraction(hover=TRUE, zoomView = TRUE)
# add icons
people <- people %>% mutate(shape = "icon",
icon.code = case_when(type=="person" ~ "f007",
type=="firm" ~ "f1ad",
type=="political party" ~ "f0c0",
type=="government" ~ "f19c"),
icon.face = "FontAwesome",
icon.weight = "bold")
# create network graph
visNetwork(people, connections) %>%
visInteraction(hover=TRUE, zoomView = TRUE) %>%
addFontAwesome() # add FontAwesome library for icons
connections <- connections %>%
# color edges by type
mutate(color.color = case_when(type=="contract" ~ "#fc9a9a",
type=="donor" ~ "#95bbf0",
TRUE ~ "#dbd9db"),
# scale edges by amount
value = case_when(is.na(amount) ~ 100000,
!is.na(amount) ~ amount))
# create network graph
visNetwork(people, connections) %>%
visInteraction(hover=TRUE, zoomView = TRUE) %>%
addFontAwesome() %>%# add FontAwesome library for icons
visSave(file = "crony_ex3.html")