渲染图像时出现错误

时间:2021-03-28 19:12:19

标签: r ggplot2 gganimate

我已在 RStudio community message boards 上发布了此内容,但尚未收到回复,因此在此发布以寻求帮助。我正在使用以下代码创建 gganimate:

library(tidyverse)
library(dplyr)
library(ggimage)
library(ggplot2)
library(ggrepel)
library(nflfastR)
library(gganimate)
library(ggstance)
library(zoo)

source('https://raw.githubusercontent.com/samhoppen/Fantasy-Evaluator/main/Code/Image%20themes.R')

rb_stats_final <- read_csv(url("https://raw.githubusercontent.com/samhoppen/Fantasy-Evaluator/main/Data/Animation%20Test%20Data.csv"))
all_weeks <- read_csv(url("https://raw.githubusercontent.com/samhoppen/Fantasy-Evaluator/main/Data/Animation%20Weeks%20Data.csv"))

rb_ani <- ggplot(data = rb_stats_final) +
  geom_col(aes(x = tot_fpts, y = reorder(player_name, -rank), color = player_id, fill = player_id, group = player_id)) + 
  geom_shadowtext(aes(x = name_loc, y = reorder(player_name, -rank), label = player_name, color = player_id, group = player_id), 
                  hjust = 1, bg.color = 'white', size = 5.5, na.rm = T, bg.r = 0.06, show.legend = FALSE) +
  scale_color_manual(values = NFL_sec)+
  scale_fill_manual(values = NFL_pri)+ 
  scale_x_continuous(expand = expansion(mult = c(0, 0.05))) +
  theme_FE +
  labs(title = "Highest-scoring Fantasy Running Backs of the Past Decade",
       subtitle = paste0("{all_weeks$week_name[as.numeric(previous_state)]}"),
       caption = "Figure: @SamHoppen | Data: @nflfastR",
       y = "",
       x = "Total Fantasy Points")+
  theme(legend.position = "none",
        axis.text.y = element_blank(),
        axis.ticks.y = element_blank(),
        axis.line = element_line(color = 'black', size = 1.5)) +
  transition_states(week_order, transition_length = 2, state_length = 1) +
  view_follow(fixed_y = T) +
  enter_fly(y_loc = -21) +
  exit_fly(y_loc = -21) +
  ease_aes('linear')

animation <- animate(rb_ani, nframes = 340, fps = 5)

然而,每当我运行最后一个 animate() 代码时,我都会收到以下错误:

Warning messages:
1: Cannot get dimensions of plot table. Plot region might not be fixed
2: attempt to apply non-function
3: attempt to apply non-function
4: attempt to apply non-function
5: attempt to apply non-function

然后当我尝试保存它时,我只会得到一个空白的 gif。我尝试更改副标题,向 scale_x_continuous 添加特定中断,并且不保持 y 轴静止,但这些都不起作用。任何有关如何解决此问题的建议都会很棒!

0 个答案:

没有答案