gpt4 book ai didi

r - R 中的 map 和动画

转载 作者:行者123 更新时间:2023-12-01 19:40:54 24 4
gpt4 key购买 nike

尝试执行类似的操作:How the Ghana Floods animation was created

下面是我的代码

library(ggmap)
library(ggplot2)
library(gganimate)
#devtools::install_github("dgrtwo/gganimate")

library(readxl)

s_data <- read_excel("объекты.xls")
head(s_data)

p <- ggmap(get_map(c(32.10399,49.04548), zoom = 5))
p+geom_point(data = s_data, aes(x = longitude, y = latitude, size=channels_contracted, cumulative = TRUE, frame = year), alpha=0.5)+ labs(title = "Objects until 2016 \n")
gganimate(p, outfile = "outfile11.gif", convert = "gm convert", ani.width = 700, title_frame = TRUE)

当尝试在 map 上获取点时 - 我有一些关于未知美学(累积、框架)的警告。然后,当我尝试为结果设置动画时 - 我刚刚崩溃了 - 请参阅下面的代码输出。

> Warning: Ignoring unknown aesthetics: cumulative, frame Warning
> message: Removed 11 rows containing missing values (geom_point).
> >
> > gganimate(p, outfile = "outfile11.gif", convert = "gm convert", ani.width = 700, title_frame = TRUE) Error in gganimate(p, outfile =
> "outfile11.gif", convert = "gm convert", : No frame aesthetic
> found; cannot create animation

问题是什么以及如何解决?

如果它很重要 - WindowsX64...所以我认为动画、ImageMagock 等会有一些困难...

更新:在 @lukeA 的帮助下找到了修复程序脚本工作期间发生的一些警告似乎导致动画生成崩溃。

工作解决方案:

    library(ggmap)
library(ggplot2)
library(gganimate)
library(readxl)
library(animation)
#s_data <- read_excel("C:/Users/fire/OneDrive/Документы/AMICO_WORK/current/объекты.xls")

channels_contracted=c(10,20,30,40,50,70,10,1)
year=c(1999,1999,2000,2000,2001,2002,2003,2003)
latitude=c(44.61217,46.97676,46.66602,46.51235,46.77762, 41.00222, 46.51235,46.77762)
longitude=c(30.72798,30.71394, 31.94281, 30.70631, 33.47262, 29.90559, 30.71394, 30.71775)
type=c("ASZ", "AGS", "ASZ", "AGS", "GNS", "GNS1", "GNS1", "AGS")
df = data.frame(channels_contracted, year, latitude, longitude, type)

p <- ggmap(get_map(c(32.10399,49.04548), zoom = 5))

suppressWarnings(p <- p + geom_point(aes(longitude,latitude,frame=year,cumulative=FALSE, size = channels_contracted, color = type), df, alpha=0.3))

ani.options(interval=2)
gganimate(p)

最佳答案

这是一个应该可以重现的示例:

library(ggmap)
library(ggplot2)
library(gganimate)
p <- ggmap(get_map(c(32.10399,49.04548), zoom = 5))
df <- data.frame(lon=seq(20,45,length.out=10), lat=seq(40,55,length.out=10),year=2001:2010)
suppressWarnings(p <- p + geom_point(aes(lon,lat,frame=year),df,color="red",size=5))
gganimate(p, width=2, height=2)

enter image description here

关于r - R 中的 map 和动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41666472/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com