简体   繁体   中英

MAPS & Animation in R

Trying to do similar to this: How the Ghana Floods animation was created

My code below

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)

When trying to get points on the map - I have some warnings about unknown aesthetics (cumulative, frame). Then when I try to animate the result - I just got crash - see the code output below.

> 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

What is the problem and how can i fix it?

If it's important - WindowsX64... So I think there will be some difficulties with the animations, ImageMagock and so on...

UPDATE: THE FIX was found with the help of @lukeA It seems some warnings that happened during the work of a script crashed the animation generation.

Working solution:

    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)

Here's an example, which should be reproducible:

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)

在此输入图像描述

With the help of 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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM