【发布时间】:2019-10-12 18:47:22
【问题描述】:
在 R 中,我试图获得基于多张图像的动画 GIF。我编写了一个返回图像的函数,并使用动画包的 saveGIF() 函数来创建 GIF。返回图像的功能有效(我看到图像在查看器中弹出)。使用 saveGIF 创建 GIF 时,没有错误消息但 GIF 为空。
library(leaflet)
library(mapview)
library(animation)
latitude = c(seq(48.13608, 52.48608, 0.00145))
longitude = c(seq(11.57278, 13.40278, 0.00061))
sampledf <- as.data.frame(cbind(longitude, latitude))
plot.1 <- function(df)
{
for (i in seq(1,nrow(df),300)){
m<- leaflet() %>%
addTiles() %>%
setView( lng = 12.48778
, lat = 50.31108
, zoom = 4 ) %>%
addPolylines(data = df[1:i,],
lng = ~longitude,
lat = ~latitude,
color = ~"red")
print(m)
}
}
saveGIF(plot.1(sampledf),movie.name="test.gif", interval=0.5, ani.width=1980/2, ani.height=1080/2)
【问题讨论】:
-
我不知道
leaflet,但我会尝试m而不是print(m)。 -
@RonakShah,我添加了一个示例 df 和使用的包
-
@StéphaneLaurent 我试过了,没用
标签: r animation imagemagick gif