Instantly share code, notes, and snippets.

@thomasp85 thomasp85/script.R
Last active Feb 22, 2019

Embed
What would you like to do?
Temporal Network Viz
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)
@thomasp85

This comment has been minimized.

Copy link
Owner Author

thomasp85 commented Jun 6, 2018

@thomasp85

This comment has been minimized.

Copy link
Owner Author

thomasp85 commented Jun 6, 2018

gganimate_birth13

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment