This tutorial is about creating animated graphics in r with several packages particulary the gganimate package.
setwd("/Users/nanaakwasiabayieboateng/Documents/memphisclassesbooks/DataMiningscience/gganimate/gganimatetutorials")
#==================================================================
# Set up parallel processing
# leave two cores for operating system
#==================================================================
cluster <- makeCluster(detectCores() - 2)
registerDoParallel(cluster)
#==================================================================
#display all coumns of data with dplyr
# Print first 1000 rows of dataset
#==================================================================
options(dplyr.width = Inf)
options(dplyr.print_max = 1000)
average=data.table::fread("/Users/nanaakwasiabayieboateng/Documents/memphisclassesbooks/Econ9000/averageoecd.csv")
incidence=data.table::fread("/Users/nanaakwasiabayieboateng/Documents/memphisclassesbooks/Econ9000/incidenceoecd.csv")
duration=data.table::fread("/Users/nanaakwasiabayieboateng/Documents/memphisclassesbooks/Econ9000/unemploydur.csv")
#str(duration)
#glimpse(duration)
str(incidence)
## Classes 'data.table' and 'data.frame': 52387 obs. of 21 variables:
## $ COUNTRY : chr "AUS" "AUS" "AUS" "AUS" ...
## $ Country : chr "Australia" "Australia" "Australia" "Australia" ...
## $ SEX : chr "MW" "MW" "MW" "MW" ...
## $ Sex : chr "All persons" "All persons" "All persons" "All persons" ...
## $ AGE : int 1519 1519 1519 1519 1519 1519 1519 1519 1519 1519 ...
## $ Age : chr "15 to 19" "15 to 19" "15 to 19" "15 to 19" ...
## $ DURATION : chr "UN1" "UN1" "UN1" "UN1" ...
## $ Duration : chr "< 1 month" "< 1 month" "< 1 month" "< 1 month" ...
## $ FREQUENCY : chr "A" "A" "A" "A" ...
## $ Frequency : chr "Annual" "Annual" "Annual" "Annual" ...
## $ TIME : int 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 ...
## $ Time : int 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 ...
## $ Unit Code : chr "PC" "PC" "PC" "PC" ...
## $ Unit : chr "Percentage" "Percentage" "Percentage" "Percentage" ...
## $ PowerCode Code : int 0 0 0 0 0 0 0 0 0 0 ...
## $ PowerCode : chr "Units" "Units" "Units" "Units" ...
## $ Reference Period Code: logi NA NA NA NA NA NA ...
## $ Reference Period : logi NA NA NA NA NA NA ...
## $ Value : num 27.2 25.4 28.5 28.7 32.2 ...
## $ Flag Codes : logi NA NA NA NA NA NA ...
## $ Flags : logi NA NA NA NA NA NA ...
## - attr(*, ".internal.selfref")=<externalptr>
#str(average)
theme_set(theme_bw())
p <- ggplot(incidence, aes(Time, Value, size =Value, frame = COUNTRY)) +
geom_smooth(method="loess") +labs(y="Unemployment rate(%)",x="Year")
suppressWarnings(suppressMessages(gganimate(p)))
#suppressWarnings(suppressMessages(gganimate(p,"/Users/nanaakwasiabayieboateng/Documents/memphisclassesbooks/DataMiningscience/oecd.gif")))
theme_set(theme_bw())
p <- ggplot(incidence, aes(Time, Value, size =Value, frame = COUNTRY))+
#p <- ggplot(gapminder, aes(gdpPercap, lifeExp, size = pop, color = continent, frame = year)) +
stat_summary(fun.y="mean", geom="line",color="purple")+labs(y="Unemployment rate(%)",x="Year")
gganimate::gganimate(p)
#gganimate::gganimate_save(p,"/Users/nanaakwasiabayieboateng/Documents/memphisclassesbooks/DataMiningscience/oecd1.gif")
theme_set(theme_bw())
p <- ggplot(incidence, aes(Time, Value, size =Value, frame = COUNTRY))+
#p <- ggplot(gapminder, aes(gdpPercap, lifeExp, size = pop, color = continent, frame = year)) +
stat_summary(fun.data="mean_cl_boot",color="purple")+labs(y="Unemployment rate(%)",x="Year")
gganimate::gganimate(p)
#==================================================================
# Stop Cluster
#
#==================================================================
stopCluster(cluster)