结合ggmap和ggplot在r中创建动画

结合ggmap和ggplot在r中创建动画,r,animation,ggplot2,ggmap,R,Animation,Ggplot2,Ggmap,我在shapefile中有一些多行字符串数据,我已将其转换为data.frame,如下所示(data) 我试图在静态卫星地图上设置线条的动画。我可以使用ggmap在卫星地图上单独绘制线条,也可以使用ggplot为它们设置动画。然而,我无法让动画在卫星地图上运行 我的代码是: setwd("~/R Projects/pipes") library("ggmap") library("ggplot2") library("tidyverse") library("readxl") library("

我在shapefile中有一些多行字符串数据,我已将其转换为data.frame,如下所示(data)

我试图在静态卫星地图上设置线条的动画。我可以使用ggmap在卫星地图上单独绘制线条,也可以使用ggplot为它们设置动画。然而,我无法让动画在卫星地图上运行

我的代码是:

setwd("~/R Projects/pipes")
library("ggmap")
library("ggplot2")
library("tidyverse")
library("readxl")
library("rgdal")
library("sf")
library("lubridate")
library("gganimate")
library("magick")
library("animation")

api<-"my api"
register_google(key=api)
getOption("ggmap")

df <- read.csv('combined.csv')

动画
好问题。但是请运行
dput(df)
并将输出粘贴到您的问题中,这样我们就可以访问数据(而不仅仅是它的屏幕抓图),谢谢您的关注。我已经在原始问题中添加了截断的dput(df)@5783745我在原始帖子中添加的更新代码允许我在shapefile上完成。我希望底图是卫星图像,但这是最终结果。好问题。但是请运行
dput(df)
并将输出粘贴到您的问题中,这样我们就可以访问数据(而不仅仅是它的屏幕抓图),谢谢您的关注。我已经在原始问题中添加了截断的dput(df)@5783745我在原始帖子中添加的更新代码允许我在shapefile上完成。我希望底图是卫星图像,但这是最终结果。
##  static map
alto <- get_googlemap(center = c(lon = 144.970561, lat = -37.833619),
                  zoom = 11, scale = 2,
                  maptype ='satellite',
                  color = 'color')
ggmap(alto)
ggsave("map.png")

##  static map
alto <- get_googlemap(center = c(lon = 144.970561, lat = -37.833619),
                  zoom = 11, scale = 2,
                  maptype ='satellite',
                  color = 'color')
ggmap(alto)
ggsave("map.png")
## static plus lines


 ggmap(alto) +
   geom_path(data = df, aes(x = lon, y = lat,  group = group)) +
   theme(legend.position="none")
 ggsave("map2.png")
## animation

pgg <- ggplot() +
  geom_path(data = df, aes(x = lon, y = lat, group = group)) +
  transition_states(df$DATE_OF_CO, transition_length = 2, state_length = 1 ) +
  labs(title = 'Year: {closest_state}') +
  shadow_mark() +
  theme(legend.position="none")
pgg <- ggmap(alto) + ggplot()
  geom_path(data = df, aes(x = lon, y = lat,  group = group)) +
  transition_states(df$DATE_OF_CO, transition_length = 2, state_length = 1 ) +
  labs(title = 'Year: {closest_state}') +
  shadow_mark() +
  theme(legend.position="none")
pgg <- ggplot() +
coord_map(xlim = c(144.3, 147), ylim = c(-38.5, -37.0)) +
geom_sf(data = cropped, mapping = aes(col=stater$DATE_OF_CO)) +
geom_sf(data = lessthan1880, mapping = aes(col=lessthan1880$DATE_OF_CO)) +
transition_states(lessthan1880$DATE_OF_CO, transition_length = 2, state_length = 1 ) +
labs(title = 'Year: {closest_state}') +
shadow_mark() +
theme(legend.position="none",
      axis.text.x = element_blank(), axis.text.y = element_blank())

animate(pgg, renderer = ffmpeg_renderer())