由于我是如何逐组设置颜色的,所以无法使用gganimate包中的过渡效果。我的数据是按团队,季节,等级,原色,次要颜色组织的:
Team,Season,Rank,Primary,Secondary
Washington Wizards,1998,16,#e31837,#002B5C
Washington Wizards,1999,24,#e31837,#002B5C
Washington Wizards,2000,24,#e31837,#002B5C
Utah Jazz,1998,2,#F9A01B,#002B5C
Utah Jazz,1999,5,#F9A01B,#002B5C
Utah Jazz,2000,5,#F9A01B,#002B5C
Toronto Raptors,1998,28,#BA0C2F,#753BBD
Toronto Raptors,1999,19,#BA0C2F,#753BBD
Toronto Raptors,2000,9,#BA0C2F,#753BBD
San Antonio Spurs,1998,5,#000000,#c4ced4
San Antonio Spurs,1999,1,#000000,#c4ced4
San Antonio Spurs,2000,9,#000000,#c4ced4
Sacramento Kings,1998,23,#63727A,#5a2d81
Sacramento Kings,1999,9,#63727A,#5a2d81
Sacramento Kings,2000,9,#63727A,#5a2d81
以及我当前的代码:
library(ggplot2)
library(gganimate)
library(transformr)
library(dplyr)
df <- read.csv('NBARH_mini.csv')
df$Primary <- as.character.factor(df$Primary)
df$Secondary <- as.character.factor(df$Secondary)
df_sort <-arrange(df,Team)
PPalette <- c(df_sort$Primary[c(1,4,7,10,13)])
SPalette <- c(df_sort$Secondary[c(1,4,7,10,13)])
TPalette <- c(PPalette,SPalette)
p <- ggplot(df_sort, aes(x = Season, y = Rank)) +
geom_point(aes(colour = Team), size = 3, shape = 21, fill = df_sort$Secondary)+
geom_line(aes(group = Team, color = Team))+
scale_y_reverse()
p <- p + scale_colour_manual(values= PPalette)+
scale_fill_manual(values = SPalette, aesthetics = "fill")
p
anim <- p +
transition_states(Team,
transition_length = 5,
state_length = 5)+
ease_aes('quadratic-in-out')+ # Slow start and end for a smoother look
ggtitle('NBA Season ending rank since Jordan',
subtitle='Ranking History of the {closest_state}')
animate(anim +
enter_fade() +
exit_shrink(),
nframes = 50,
width = 500,
height =400)
我的目标是为每个团队创建一个线图和点图,其中线是原色,而点被第二色填充。我花了很多时间试图将它们破解在一起,只是一个尝试许多不同方法的情节。要使它起作用,我唯一能做的就是将df_sort$Secondary
传递到geom_point()中,并被告知这是“ NoNo”,但是我无法以其他方式绘制它。
现在我已经可以工作了
Error: identical(classes, col_classes(to)) is not TRUE
当我尝试使用enter_fade()+exit_shrink()
制作动画时。它将与/没有动画,但没有过渡。这是目前的样子。
https://gfycat.com/NervousComposedGrayfox
任何人都对此有经验吗?