library(ggplot2)
library(animation)
library(dplyr)
library(tidyr)
library(xlsx)
library(ggthemes)
female
male
female%gather(Year,Poputation,-1)
male%gather(Year,Poputation,-1)
female$Poputation
male$sex
China_Population%mutate(abs_pop=abs(Poputation))
China_Population$agegroup
levels=c("0-4","5-9","10-14","15-19","20-24","25-29","30-34","35-39","40-44","45-49","50-54","55-59","60-64","65-69","70-74","75-79","80+") ,order=T)
m
saveGIF({
for (i in m) {
title
year_data
g1
coord_fixed()+
coord_flip() +
geom_bar(data=subset(year_data,sex=="female"),stat = "identity") +
geom_bar(data=subset(year_data,sex=="male"), stat = "identity") +
scale_y_continuous(breaks = seq(-70000,70000,length=9),
labels = paste0(as.character(c(abs(seq(-70,70,length=9)))), "m"),
limits = c(-75000, 75000)) +
theme_economist(base_size = 14) +
scale_fill_manual(values = c('#D40225', '#374F8F')) +
labs(title=paste0("Population structure of China:", title),
caption="Data Source:United Nations Department of Economic and Docial Affairs\nPopulation Division\nWorld Population Prospects,the 2015 Revision"
,y="Population",x="Age") +
guides(fill=guide_legend(reverse = TRUE))+
theme(
legend.position =c(0.8,0.9),
legend.title = element_blank(),
plot.title = element_text(size=20),
plot.caption = element_text(size=12,hjust=0),
)
print(g1)
}
},movie.name='japan_pyramid.gif',interval=0.5,ani.width=700,ani.height=600)