Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/76.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R中随时间变化的动画条形图_R_Animation_Ggplot2_Plot_Bar Chart - Fatal编程技术网

R中随时间变化的动画条形图

R中随时间变化的动画条形图,r,animation,ggplot2,plot,bar-chart,R,Animation,Ggplot2,Plot,Bar Chart,我想在R中创建一个动画条形图,显示每个玩家和比赛日的得分 下面是我创建的虚构数据: df <- data.frame(player = c("Aguero", "Salah", "Aubameyang", "Kane", "Aguero", "Salah", "Aubameyang", "Kane", "Aguero", "Salah", "Aubameyang", "Kane"), team = c("ManCity", "Liverpool", "Arsen

我想在R中创建一个动画条形图,显示每个玩家和比赛日的得分

下面是我创建的虚构数据:

df <- data.frame(player = c("Aguero", "Salah", "Aubameyang", "Kane", "Aguero", "Salah", "Aubameyang", "Kane", "Aguero", "Salah", "Aubameyang", "Kane"), 
             team = c("ManCity", "Liverpool", "Arsenal", "Tottenham", "ManCity", "Liverpool", "Arsenal", "Tottenham", "ManCity", "Liverpool", "Arsenal", "Tottenham"), 
             gameday = c(1,1,1,1,2,2,2,2,3,3,3,3),
             goals = c(0,1,2,0,1,1,3,1,2,1,3,2),
             stringsAsFactors = F)

条形图的灵感来自这样一个视频:

是否有可能为此创建一个动画条形图


非常感谢你的帮助

是的,要设置ggplots的动画,您需要软件包。您可以通过查找找到它,但由于最重要的答案不是最新的语法,这里有一些代码:

library("ggplot2")
library("gganimate")
ggplot(data=df, aes(x=reorder(Player, Goals), y=Goals, fill=Team)) +
  geom_bar(stat="identity") +
  theme(legend.position = "none", axis.text.y=element_blank(), 
  axis.title.y=element_blank()) +
  geom_text(aes(label=Player), vjust=1, hjust=-0.1, color="white", size=3.5) +
  coord_flip() +
  ## gganimate code
  labs(title = 'Gameday: {frame_time}') +
  transition_time(gameday) +
  ease_aes('linear')

(代码未经测试,但应能正常工作)

请包括您用来制作图表的代码是的,对此表示抱歉非常感谢您的回答。我还检查了该帖子中提供的解决方案:很高兴看到你找到了解决方案!
library("ggplot2")
library("gganimate")
ggplot(data=df, aes(x=reorder(Player, Goals), y=Goals, fill=Team)) +
  geom_bar(stat="identity") +
  theme(legend.position = "none", axis.text.y=element_blank(), 
  axis.title.y=element_blank()) +
  geom_text(aes(label=Player), vjust=1, hjust=-0.1, color="white", size=3.5) +
  coord_flip() +
  ## gganimate code
  labs(title = 'Gameday: {frame_time}') +
  transition_time(gameday) +
  ease_aes('linear')