Last active
October 13, 2021 01:33
-
-
Save thomasp85/e6280e554c08f00c9e46f8efca2a5929 to your computer and use it in GitHub Desktop.
Temporal Network Viz
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(ggraph) | |
library(tidygraph) | |
library(gganimate) | |
# Data from http://konect.uni-koblenz.de/networks/sociopatterns-infectious | |
infect <- read.table('out.sociopatterns-infectious', skip = 2, sep = ' ', stringsAsFactors = FALSE) | |
infect$V3 <- NULL | |
names(infect) <- c('from', 'to', 'time') | |
infect$time <- as.POSIXct(infect$time, origin = Sys.time() - as.numeric(Sys.time())) | |
gr <- tbl_graph(edges = infect, directed = FALSE) %>% | |
mutate(degree = centrality_degree()) | |
# Animation Code | |
p <- ggraph(gr, 'lgl') + | |
geom_edge_link0(edge_colour = '#991814', edge_width = 1, edge_alpha = 1) + | |
geom_node_point(aes(size = degree), colour = '#1B2733', show.legend = FALSE) + | |
scale_size_area(max_size = 4) + | |
ggtitle('Human Interactions', subtitle = 'Time of encounter {format(frame_time, "%H:%M")}') + | |
theme_graph() + | |
theme(plot.background = element_rect(fill = '#B5C9BA'), | |
plot.title = element_text(color = '#F77976')) + | |
transition_events(start = time, enter_length = hms::hms(hours = 3), exit_length = hms::hms(hours = 3)) + | |
enter_fade() + | |
exit_fade() | |
animate(p, 100, 10) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Modern version of https://gist.github.com/thomasp85/eee48b065ff454e390e1