我一直在玩这个waffle
包,并试图让它与gganimate
.
mpg
举个例子,我创建了华夫饼图来显示每个模型的数量class
。然后,我想使用 gganimate 依次显示每个制造商按类别划分的模型图表。我可以facet_wrap()
用来一次显示所有制造商的图表,但希望能够循环浏览它们。
当我尝试将 gganimate 应用于华夫饼图时,出现错误:
mapply 中的错误(FUN = f, ..., SIMPLIFY = FALSE):零长度输入不能与非零长度的输入混合
我不确定是否waffle
与 不兼容gganimate
,或者我做错了什么。
这是代码:
library(tidyverse)
library(waffle)
library(gganimate)
data("mpg")
d <- mpg
d$class <- as.factor(d$class)
d$manufacturer <- as.factor(d$manufacturer)
plot <- d %>% count(manufacturer, class) %>%
ggplot(aes(fill = class, values = n)) +
geom_waffle(color = "white",
size = .75,
n_rows = 4) +
ggthemes::scale_fill_tableau(name = NULL) +
coord_equal() +
theme_minimal() +
theme(panel.grid = element_blank(), axis.text = element_blank(), legend.position = "bottom")
#Facet wrap works fine:
plot + facet_wrap(~ manufacturer)
#gganimate returns error:
plot + transition_states(manufacturer, transition_length = 2, state_length = 2)
非常感谢任何帮助!谢谢。