如果你使用gganimate
你可以包括transition_states
使您的观点充满活力。对于积分的累积添加,请使用shadow_mark
包含当前帧后面的数据。
library(ggthemes)
library(gganimate)
library(ggplot2)
DF <- data.frame("latitude" = c(42.29813,41.83280,41.83280,30.24354),
"longitude" =c(-71.23154,-72.72642,-72.72642,-81.62098),
"month" = c(1,2,3,4))
usa <- ggplot() +
borders("usa", colour = "gray85", fill = "gray80") +
theme_map()
map <- usa +
geom_point(aes(x = longitude, y = latitude), color = "black", data = DF) +
transition_states(month, transition_length = 0, state_length = 1) +
shadow_mark()
map
Edit:要将动画保存为 .gif,请使用anim_save
.
anim_save("mapanim.gif", map)
另外,如果你想改变最终动画的宽度/高度,你可以指定,例如:
animate(map, height = 400, width = 600)