Lab: Data & code
- The code for Figure 8.1 is shown below.
- Learn…
- role of data management for visualization
- visualizing unorder and ordered variable
- manual scales
- automatically creating labels from the data
- sizing text elements
data <- readr::read_csv(sprintf("https://docs.google.com/uc?id=%s&export=download", "1PzXaQZ9cSjtMaNGv3cOV8AMuPjmsc1L0"))
p <- ggplot(data, aes(x = followers_count, friends_count, colour = party)) +
geom_point() +
#facet_wrap(~continent) +
# Here comes the gganimate specific bits
labs(title = 'German MPs on Twitter',
subtitle = 'Winning and losing friends/followers (Date: {frame_time})',
colour = "Party",
x = "Number of followers",
y = "Number of friends") +
xlim(0,10000)+
ylim(0,2000)+
theme_light() +
transition_time(date_creation) +
ease_aes('linear') +
shadow_wake(wake_length = 0.2, alpha = FALSE)
# Animate and save
p_animated <- animate(p,
duration = 5,
end_pause = 6,
fps = 20,
width = 7,
height = 4,
units = "in",
res = 300,
renderer = gifski_renderer())
anim_save(animation = p_animated,
"animation_twitter.gif",
path = "www/images/")