动画错误:无法为签名“ gganim”找到函数“动画”的继承方法

时间:2019-05-13 05:08:38

标签: r gganimate

我想用gganimate制作动画情节。当我尝试渲染动画时,它会显示以下错误消息:

Error in (function (classes, fdef, mtable)  : 
  unable to find an inherited method for function ‘animate’ for signature ‘"gganim"’ 

这是我要复制的代码。我正在使用R 3.6.0

library(gganimate)
library(magick)
library(dplyr)
library(animation)
library(tidyverse)
library(patchwork)
library(animation)
library(sp)
library(raster)
library(rgeos)
library(gifski)

REPD <- readr::read_tsv(RCurl::getURL("https://gist.githubusercontent.com/dr-harper/abc79ce4ec63644324aa2e6134ddf1ac/raw/49f8a5d6c5c41395af46428007048be7301b9f7b/REPD.csv"))

planning_summary <- read.table(text = "
'Status'                        'Status Summary'
'Application Approved'        'Approved'
'Application Refused'           'Refused/Abandoned'
'Application Submitted'       'Submitted'
'Application Withdrawn'       'Refused/Abandoned'
'Connection Applied For'        'Submitted'
'No Application Made'           'Refused/Abandoned'
'No Application'              'Required Approved'
'Abandoned'                   'Refused/Abandoned'
'Awaiting Construction'       'Approved'
'Decommissioned'                'Approved'
'Operational'                   'Approved'
'Planning Permission Expired'   'Approved'
'Under Construction'            'Approved'
", header = TRUE, stringsAsFactors = FALSE)


REPD <-
  REPD %>%
  merge(planning_summary, by.x = "Development Status (short)", by.y = "Status") %>%
  mutate(date = lubridate::dmy(`Planning Application Submitted`),
         year = lubridate::year(date),
         `Installed Capacity (MWelec)` = as.numeric(`Installed Capacity (MWelec)`))

# Obtener fronteras:

UK <-  raster::getData('GADM', country='GBR', level = 1) %>%
  sp::spTransform(CRSobj = CRS("+init=epsg:27700")) %>%
  gSimplify(tol=1000, topologyPreserve=TRUE) %>%
  fortify()


REPD_tech <- 
  REPD %>%
  filter(`Status.Summary` == "Approved")
# build GIF
p <- 
  ggplot() +
  geom_polygon(data=UK, aes(long, lat, group = group), fill = "#528076") +
  geom_point(data = REPD_tech, aes(x = `X-coordinate`, y = `Y-coordinate`, fill = `Technology Type`),
             size = 5, shape = 21, alpha = 0.7) +

  # gganimate parts
  transition_states(`Technology Type`, transition_length = 2, state_length = 20) +
  enter_fade() +
  exit_fade() +
  # Styling
  coord_equal(xlim = c(-75000, 825000), ylim = c(0, 1200000)) +
  theme(panel.grid.major = element_blank(),
        panel.grid.minor = element_blank(),
        axis.text = element_blank(),
        axis.title = element_blank(),
        axis.ticks = element_blank(),
        panel.background = element_rect(fill = "grey99", colour = "grey80"),
        plot.title = element_text(hjust = 0, size = 16, vjust=0))
animate(p, length = 15, width = 700, height = 400)

1 个答案:

答案 0 :(得分:0)

您加载了很多软件包,这些软件包也可能具有覆盖gganimate的动画功能

尝试

gganimate::animate(p, length = 15, width = 700, height = 400)