library(RMySQL) library(tidyverse) library(animation) yhendus<-dbConnect(dbDriver("MySQL"), user='mart', password='ajutine1234', host='localhost', dbname='mart' ) paring<-dbSendQuery(yhendus, " SELECT COUNT(*) AS kogus, FLOOR(production_year/10)*10 AS kymnend FROM efis_film GROUP BY FLOOR(production_year/10)*10") andmed=fetch(paring, n=-1) andmed=andmed %>% filter(kymnend>=1910 & kymnend<=2010) andmed #ggplot(andmed, aes(kymnend, kogus))+geom_point() saveGIF({ for(k in seq(1910, 2010, 10)){ p=filter(andmed, kymnend==k) %>% ggplot(aes(kymnend, kogus))+geom_point()+ xlim(1900, 2020) + ylim(0, 3500) + ggtitle(k) print(p) } }, movie.name="koguskymnendid.gif", interval=1)