6.6 Level 2 Charging Stations Animation
Code
dg = dd %>%
filter(lev2 > 0,
lon >= -127,
lon <= -62,
lat >= 23,
lat <= 51)
title = "Level 2 Charging Stations as of {next_state}"
g = ggplot(dg,
aes(x = lon,
y = lat,
color = network2,
size = lev2))+
borders('usa',
colour = publightgray)+
geom_point(alpha = .4,
show.legend = F)+
facet_wrap(~network2)+
labs(title = title,
caption = 'As of July 13, 2023. Data: https://afdc.energy.gov/')+
scale_color_manual(
values = c('orange',
pubdarkgray,
pubred,
'forestgreen',
pubblue,
pubmediumgray))
g %>%
pub('map') +
scale_size(range = c(.25, 2)) +
theme(panel.spacing = unit(10*1/72/3, "in"))
Code
gg = g %>%
pub(type = 'map',
base_size = 36) +
scale_size(range = c(.5, 6))+
theme(panel.spacing = unit(10*1/72, "in")) +
transition_states(states = month.year,
transition_length = 0,
state_length = 1,
wrap = F) +
shadow_mark()
## other animation settings
## 2 frames per month, aka 6 months per second (12 fps),
## plus a 5 second pause at the end
## Hmm, it seems like we need to use number of levels.
## When using length(unique(dg$month.year)), some are dropped.
## So we use length(levels(dg$month.year)) instead.
## seems like gganimate uses all levels,
## so don't want to undercount the frames.
nframes = length(levels(dg$month.year))*2 + 12*5
# a2 = animate(gg,
# width = 1440,
# height = 1440*.7,
# fps = 12,
# nframes = nframes,
# start_pause = 0,
# end_pause = 12*5)
# a2
#
# # # ## save animation
# anim_save(a2, filename = 'img/EV.stations.animation.lev2.gif')
[1] 0
[1] 80
[1] 20
[1] 100
[1] 0
[1] 80
[1] 20
[1] 100