【问题标题】:Arguments imply differing number of rows in R - Specific Case参数暗示 R 中不同的行数 - 特定情况
【发布时间】:2021-12-14 02:50:36
【问题描述】:

我在以下链接中有两个数据文件:tuckdftgames

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

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")

此代码产生以下错误:

data.frame(..., check.names = FALSE) 中的错误: 参数暗示不同的行数:209、100

查看数据后,我真的还是不明白这里发生了什么。有没有人有修复?我觉得这需要一个非常简单的解决方案,但我找不到。例如,将tuckdf 数据帧减少到仅frameId

【问题讨论】:

  • 您在 tuckdf 中是否有任何 NA?
  • 请不要在外部站点发布数据文件。见how to create a reproducible example。您共享的代码应该足以重现错误。如果主题或比例尺等代码与错误无关,请删除它们。
  • 检查我更新的答案并请批准我的编辑。你需要更好地澄清你的 Q 是关于什么的。

标签: r ggplot2 gganimate


【解决方案1】:

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


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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-12-27
    • 1970-01-01
    • 2019-02-13
    • 2015-12-08
    • 1970-01-01
    • 2017-11-04
    • 1970-01-01
    • 2021-01-01
    相关资源
    最近更新 更多