参数暗示 R 中的行数不同 - 特定情况

Arguments imply differing number of rows in R - Specific Case

我在以下链接中有两个数据文件:tuckdf and tgames

我还有以下代码使用这些文件创建动画:

library('dplyr')
library('tidyverse')
library('ggplot2')
library('gganimate')
library('ggforce')
library('gifski')
library('readr')
library('deldir')
library('transformr')

colorDict <- c('ARI'='#97233F','ATL'='#A71930','BAL'='#241773','BUF'='#00338D','CAR'='#0085CA','CHI'='#00143F',
               'CIN'='#FB4F14','CLE'='#FB4F14','DAL'='#B0B7BC','DEN'='#002244','DET'='#046EB4','GB'='#24423C',
               'HOU'='#C9243F','IND'='#003D79','JAX'='#136677','KC'='#CA2430','LA'='#002147','LAC'='#2072BA',
               'LV'='#C4C9CC','MIA'='#0091A0','MIN'='#4F2E84','NE'='#0A2342','NO'='#A08A58','NYG'='#192E6C',
               'NYJ'='#203731','PHI'='#014A53','PIT'='#FFC20E','SEA'='#7AC142','SF'='#C9243F','TB'='#D40909',
               'TEN'='#4095D1','WAS'='#FFC20F', 'FBL'='#964B00')

tgames <- read_csv("PATH_TO_TGAMES_DATA")
tuckdf <- read_csv("PATH_TO_TUCKDF_DATA", 
                    col_types = cols(time = col_character())
)

vertical_lines <- c(10,20,30,40,50,60,70,80,90,100,110)
txt = c(10,20,30,40,50,40,30,20,10)
nums = c(20,30,40,50,60,70,80,90, 100)
bot = c(5,5,5,5,5,5,5,5,5)
top = c(48.3, 48.3, 48.3, 48.3, 48.3, 48.3, 48.3, 48.3, 48.3)
bot_nums = data.frame(nums, txt, bot)
top_nums = data.frame(nums, txt, top)
rects <- data.frame(x1 = 0, x2 = 10, x3 = 110, x4 = 120, y1 = 0, y2 = 53.3)

animar <- ggplot(tuckdf, aes(x, y, colour=t_abbr)) +
  #fill="#78b833"
          theme(panel.background = element_rect(fill="#78b833"),
              panel.grid.major = element_blank(),
              panel.grid.minor = element_blank(), legend.position = "bottom",
              axis.ticks = element_blank(), axis.text = element_blank()) +
          geom_rect(data = rects, aes(xmin = x1, xmax = x2, ymin = y1, ymax = y2), inherit.aes = FALSE, 
                    fill = colorDict[[tgames$homeTeamAbbr[[1]]]]) +
          geom_rect(data = rects, aes(xmin = x3, xmax = x4, ymin = y1, ymax = y2), inherit.aes = FALSE,
                    fill = colorDict[[tgames$homeTeamAbbr[[1]]]]) +
          geom_vline(xintercept = vertical_lines, colour="#FFFFFF") +
          geom_text(data = bot_nums, aes(nums, bot, label=txt), inherit.aes = FALSE, color = '#FFFFFF') +
          geom_text(data = top_nums, aes(nums, top, label=txt), inherit.aes = FALSE, color = '#FFFFFF', angle=180) +
          # home team velocities
          # geom_segment(
            #p_data = specdf %>% filter(team == 'home'),
            #mapping = aes(x = x, y = y, xend = x*sin(o), yend = y*cos(o)),
            #colour = colorDict[[tgames$homeTeamAbbr[[1]]]], size = 1, arrow = arrow(length = unit(0.01, "npc"))
          #) + 
          geom_point(aes(), show.legend= FALSE, size = 6) +
          geom_point(shape=1, size = 6, colour='black') +
          geom_text(aes(x, y, label = jerseyNumber), color = '#FFFFFF', size=3) +
          #{if(aes(jerseyNumber) == 22)geom_line()} +
          geom_segment(
            mapping = aes(x = x, y = y, xend = x + 0.5*s*sin(o*pi/180), yend = y + 0.5*s*cos(o*pi/180)),
            show.legend= FALSE, 
            size = 1, arrow = arrow(length = unit(0.01, "npc"))
          ) + 
          scale_colour_manual(values=colorDict) +
          scale_fill_manual(values=colorDict) +
          scale_x_continuous(limits=c(0,120), expand=c(0,0)) +
          scale_y_continuous(limits=c(0,53.3), expand=c(0,0)) + 
          coord_fixed() +
          labs(title="", x="", y="") +
          transition_states(frameId, transition_length = 2, state_length = 1, wrap = FALSE)

animate(animar, renderer = gifski_renderer())
anim_save("C:\Users\jakes\Downloads\thing3.gif")

此代码产生以下错误:

Error in data.frame(..., check.names = FALSE) : arguments imply differing number of rows: 209, 100

看了资料我还是不明白这是怎么回事。有人有办法解决吗?我觉得这需要一个非常简单的解决方案,但我找不到。例如,将 tuckdf 数据帧减少到仅 frameId 为 <= 30 的数据帧可消除此错误。不幸的是,我需要所有数据行。

好的,我认为问题出在默认帧数 (100)


  animate(animar, renderer = gifski_renderer(),nframes=210)