【发布时间】:2019-09-20 16:11:40
【问题描述】:
我开发了一个代码来在世界地图上创建动画轨迹。我首先将其保存为 .png,然后想将其转换为 .gif 文件。
我下载了 ImageMagick 并尝试了这里的建议:Creating a Movie from a Series of Plots in R 但无法让它工作。有人可以帮我吗?
这是我的图书馆:
library(purrr)
library(magick)
library(ggplot2)
library(animation)
library(png)
library(caTools) # for write.gif
我的数据框是坐标,所以是这样的:
x y
1 100.3 13.4
2 101.3 13.3
3 101.4 13.2
4 101.4 13.0
5 102.4 12.9
6 102.4 12.7
7 103.5 12.5
8 103.5 12.4
9 105.5 12.2
10 105.5 12.1
MP <- NULL
mapWorld <- borders("world", colour="gray50", fill="gray50")
mp <- ggplot() + mapWorld
for (i in 1:10) {
MP[i] <- mp + geom_point(aes(x=df$x[i*10], y=df$y[i*10]) ,color="blue", size=1)
picture_name <- paste0("newsheet",i,".png")
png(filename=picture_name)
MP[[i]]
dev.off()
}
all_images <- list.files(path = "./", pattern = "*.png", full.names = T)
P1 <- readPNG(all_images)
我希望 gif 一次在世界地图上显示一个坐标为蓝点,但到目前为止我唯一得到的是 R 只用一张图像解释 P1,但出现以下错误:
警告信息: 在 if (col == "jet") col = colorRampPalette(c("#00007F", "blue", : 条件的长度 > 1,并且只使用第一个元素
【问题讨论】:
-
一旦有了
png文件的路径向量,就可以使用gifski包来创建gif。
标签: r imagemagick