我的过渡过渡不顺畅并留下阴影

时间:2019-05-15 13:11:12

标签: r animation tidyverse gganimate

我正在尝试为销售问题构建gif动画。但是,动画和过渡效果并不流畅。

我试图研究转换率,但没有成功

输出如下

gif

gap <- mydata %>%
  group_by(date) %>%
  # The * 1 makes it possible to have non-integer ranks while sliding
  mutate(rank = min_rank(-count) * 1,
         Value_rel = count/count[rank==1],
         Value_lbl = paste0(" ",count)) %>%
  filter(rank <=10) %>%
  ungroup()

p <- ggplot(gap, aes(rank, group = category, 
                     fill = as.factor(category), color = as.factor(category))) +
  geom_tile(aes(y = value/2,
                height = value,
                width = 0.5), alpha = 0.8, color = NA) +
  geom_text(aes(y = 0, label = paste(category, " ")), vjust = 0.2, hjust = 1) +
  geom_text(aes(y=value,label = Value_lbl, hjust=0)) +
  coord_flip(clip = "off", expand = FALSE) +
  scale_y_continuous(labels = scales::comma) +
  scale_x_reverse() +
  guides(color = FALSE, fill = FALSE) +

  labs(title='{closest_state}', x = "", y = "TV Sales",
       caption = "TV Sales Report") +
  theme(plot.title = element_text(hjust = 0, size = 22),
        axis.ticks.y = element_blank(),  # These relate to the axes post-flip
        axis.text.y  = element_blank(),  # These relate to the axes post-flip
        plot.margin = margin(1,1,1,4, "cm")) +

  transition_states(month, transition_length = 2, state_length = 0) +
  ease_aes('cubic-in-out')

animate(p, 200, fps = 10, duration = 40, width = 800, height = 600, renderer = gifski_renderer("gganim.gif"))

0 个答案:

没有答案