在R中创建动画时,月份按字母顺序显示

问题描述

我正在R中创建一个动画。但是当动画渲染时,它会按字母顺序显示月份。 它从四月,八月等开始。它应该从一月,二月开始

我还没有找到满意的答案。


library(tidyverse)
library(gganimate)

ov_tidy <- read_csv("ov_tidy.csv")

ov_formatted <- ov_tidy %>%
  group_by(year) %>%
  # The * 1 makes it possible to have non-integer ranks while sliding
  mutate(rank = rank(-value),Value_rel = value/value[rank==1],Value_lbl = paste0("$",format(value,scientific = FALSE))) %>%
  group_by(country_name) %>% 
  filter(rank <=10) %>%
  ungroup()

# Animation


anim <- ggplot(ov_formatted,aes(rank,group = country_name,fill = as.factor(country_name),color = as.factor(country_name))) +
  geom_tile(aes(y = value/2,height = value,width = 0.9),alpha = 0.8,color = NA) +
  geom_text(aes(y = 0,label = paste(country_name," ")),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) +
  theme(axis.line=element_blank(),axis.text.x=element_blank(),axis.text.y=element_blank(),axis.ticks=element_blank(),axis.title.x=element_blank(),axis.title.y=element_blank(),legend.position="none",panel.background=element_blank(),panel.border=element_blank(),panel.grid.major=element_blank(),panel.grid.minor=element_blank(),panel.grid.major.x = element_line( size=.1,color="grey" ),panel.grid.minor.x = element_line( size=.1,plot.title=element_text(size=25,hjust=0.5,face="bold",colour="grey",vjust=-1),plot.subtitle=element_text(size=18,face="italic",color="grey"),plot.caption =element_text(size=8,plot.background=element_blank(),plot.margin = margin(2,2,4,"cm")) +
  transition_states(year,transition_length = 4,state_length = 1,wrap = FALSE) +
  view_follow(fixed_x = TRUE)  +
  labs(title = 'Funding data YTD : {closest_state}',subtitle  =  "Sub heading",caption  = "Caption... Outlier Ventures") 

# For GIF

animate(anim,200,fps = 20,width = 1200,height = 1000,renderer = gifski_renderer("ov_funding_data.gif"),end_pause = 15,start_pause =  15) 

# For MP4

animate(anim,renderer = ffmpeg_renderer()) -> for_mp4

anim_save("ov_funding_data.mp4",animation = for_mp4 )


在这方面的任何帮助都将得到高度重视

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...