Created
September 5, 2017 11:36
-
-
Save schochastics/1b850600a8b0b8e71c5883bac92b8683 to your computer and use it in GitHub Desktop.
replication of u/Tjukanov's post in r/dataisbeautiful in R
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
################################################################################ | |
# replication of https://i.redd.it/q0udc4wfhvjz.gif | |
# originally posted to r/dataisbeautiful by u/Tjukanov | |
################################################################################ | |
library(tidyverse) | |
library(gganimate) | |
library(lubridate) | |
#data from: https://www.ncdc.noaa.gov/ibtracs/index.php?name=wmo-data | |
df <- read_csv("Allstorms.ibtracs_wmo.v03r09.csv") | |
df <- df[-1,] | |
df <- df %>% mutate_at(c("Season","Longitude","Latitude","Wind(WMO)"),as.numeric) | |
df <- df %>% mutate(ISO_time=ymd_hms(ISO_time) %>% as.Date) | |
df <- df %>% dplyr::filter(ISO_time>as.Date("1917-09-05")) %>% | |
dplyr::filter(between(Longitude,-150,-40) & between(Latitude,0,50)) | |
df$id <- group_indices(df,Serial_Num) | |
df$ym <- zoo::as.yearmon(df$ISO_time) | |
world <- map_data("world") | |
worldmap <- ggplot(world) + | |
geom_polygon(aes(x=long, y=lat, group=group),fill="grey23",color=NA) + | |
coord_cartesian(xlim = c(-130, -40),ylim = c(0, 50))+ | |
theme(panel.background = element_rect(fill="black"), | |
plot.background=element_rect(fill="black"), | |
panel.grid = element_blank(), | |
axis.text = element_blank(), | |
axis.ticks = element_blank(), | |
legend.position="none")+ | |
labs(x="",y="") | |
worldmap | |
k=0 | |
for(c in unique(df$ym)){ | |
k=k+1 | |
print(k) | |
p <- worldmap+ | |
geom_path(data=df[df$ym<c,],aes(Longitude,Latitude,group=Serial_Num), #alpha | |
col="white", | |
size=0.05)+ | |
geom_path(data=df[df$ym==c,],aes(Longitude,Latitude,group=id), | |
col="yellow", | |
size=0.7)+ | |
annotate("text",x=-113,y=50,label=zoo::as.yearmon(c),color="white",hjust=1) | |
p | |
ggsave(paste0("out/",k,".png"),p,width=5,height=3) | |
} | |
setwd("out/") | |
system("rm out.mp4") | |
system("ffmpeg -framerate 15 -i %d.png -c:v libx264 out.mp4") #mp4 | |
system("convert -limit memory 6GiB -resize 768x576 -delay 5 -loop 1 `ls -v` out.gif") #gif | |
setwd("..") | |
gc() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment