【发布时间】:2020-11-11 12:13:01
【问题描述】:
我正在尝试使用 gganimate 为地图制作动画,但遇到以下错误:
Error in seq.default(range[1], range[2], length.out = nframes) :
'from' must be a finite number
这似乎通常发生在用于transition_time() 的变量不是数字或数据格式错误的情况下,但我不知道我的情况如何;我的数据是正确的长格式,transition_time() 的变量是数字并且总是有限的。
这是plot_usmap() 的特定问题吗?我错过了什么明显的东西吗?
我的数据在GitHub。代码如下:
library("usmap")
library("ggplot2")
library("gganimate")
load("helpdata.Rda")
check = plot_usmap(data = df_map, values = "frac_cov") +
scale_fill_stepsn(breaks=c(-100, 0, 0.1, 0.2, 0.3, 0.4, 0.5,
0.6, 0.7, 0.8, 0.9, 1, 100),
colors=c("red", "gray100", "gray90", "gray80", "gray70", "gray60",
"gray50", "gray40", "gray30", "gray20", "gray10", "red"),
na.value="white") +
labs(fill = "", title = "Fraction of excess deaths\nattributed to COVID-19") +
theme(legend.position = "right", plot.title = element_text(hjust = 0.5)) +
transition_time(month)
anim <- animate(check, nframes=9, fps=1)
非常感谢!
【问题讨论】: