Australian Mortality Data

The following data comes from the Human Mortality Database.

library(ggplot2)
library(gganimate)
library(dplyr)
theme_set(theme_bw())
tab<-read.csv("e:/pandoc/rmd/ausm.csv",sep=",")
tab$age<-rep(0:110,91)
m2011<-filter(tbl_df(tab),Year==2011)
au<-ggplot()+geom_line(data=tab,aes(age,ex,frame=Year),color="red",lwd=1)+
  ylim(0,80)+xlab("Age (years)")+ylab("Life Expency At Age x " )+
  ggtitle("Year: ")+
  theme(plot.title = element_text(hjust = 1/2, vjust=2.12))+
  geom_line(aes(age,ex),m2011)
 
gg_animate(au)

Interactive Plot

library(ggvis)
## Warning: package 'ggvis' was built under R version 3.3.2
## 
## Attaching package: 'ggvis'
## The following object is masked from 'package:ggplot2':
## 
##     resolution
 library(dplyr)
tabd<-tbl_df(tab)
tabd %>%
 ggvis(~age, ~ex) %>%
 filter(Year== eval(input_slider(1921,2011,step=1))) %>%
 layer_lines()%>%add_axis("y", title = "Life Expectancy at Age x") %>% 
  scale_numeric("y", domain = c(0, 80), nice = FALSE)
## Warning: Can't output dynamic/interactive ggvis plots in a knitr document.
## Generating a static (non-dynamic, non-interactive) version of the plot.