Smoker figure

library(animint)
## Loading required package: ggplot2
smoker.viz <- list(
  bar = ggplot() + geom_bar(
    data = reshape2::tips,
    aes(x = smoker, clickSelects = smoker)
    ),
  scatter = ggplot() + geom_point(
    data = reshape2::tips,
    aes(x =  total_bill, y = tip,
        showSelected = smoker)
    )
  )
structure(smoker.viz, class="animint")

World Bank figure

data(WorldBank)
WorldBank$region <-
  sub(" (all income levels)", "", WorldBank$region, fixed=TRUE)
years <- data.frame(year=unique(WorldBank$year))
wb.viz <- list(
  timeSeries=ggplot()+
    geom_tallrect(aes(
      xmin=year-0.5, xmax=year+0.5, clickSelects=year),
                  alpha=0.5,
                  data=years)+
    guides(color="none")+
    geom_line(aes(year, life.expectancy, group=country, colour=region,
                  showSelected=region,
                  clickSelects=country),
              data=WorldBank, size=4, alpha=3/5),
  scatterPlot=ggplot()+
    geom_point(aes(fertility.rate, life.expectancy, clickSelects=country,
                   showSelected=year, colour=region, size=population,
                   tooltip=paste(country, "population", population),
                   key=country), # key aesthetic for animated transitions!
               data=WorldBank)+
    geom_text(aes(fertility.rate, life.expectancy, label=country,
                  clickSelects=country,
                  showSelected=country, showSelected2=year,
                  showSelected3=region,
                  key=country), #also use key here!
              data=WorldBank)+
    scale_size_animint(breaks=10^(9:5))+
    geom_text(aes(
      5, 80, label=paste("year =", year), key=year, showSelected=year),
              data=years),
  time=list(variable="year",ms=3000),
  duration=list(year=1000),
  selector.types=list(country="multiple", region="multiple"),
  first=list(
    year=1979,
    country=c("United States", "Vietnam"),
    region=c("East Asia & Pacific", "North America")
    ))
structure(wb.viz, class="animint")

Tornado figure

library(maps)
## 
##  # ATTENTION: maps v3.0 has an updated 'world' map.        #
##  # Many country borders and names have changed since 1990. #
##  # Type '?world' or 'news(package="maps")'. See README_v3. #
library(plyr)
## 
## Attaching package: 'plyr'
## The following object is masked from 'package:maps':
## 
##     ozone
data(UStornadoes)
ord <- order(unique(UStornadoes$TornadoesSqMile), decreasing=T)
stateOrder <- data.frame(state = unique(UStornadoes$state)[ord], rank = 1:49)
UStornadoes$state <-
  factor(UStornadoes$state, levels=stateOrder$state, ordered=TRUE)
UStornadoes$weight <- 1/UStornadoes$LandArea
USpolygons <- map_data("state")
USpolygons$state = state.abb[match(USpolygons$region, tolower(state.name))]
UStornadoCounts <-
  ddply(UStornadoes, .(state, year), summarize, count=length(state))
seg.color <- "#55B1F7"
years <- data.frame(year=unique(UStornadoes$year))
states <- data.frame(state=unique(UStornadoes$state))
tornado.viz <- list(
  map=ggplot()+
    theme_bw()+
    theme_animint(width=750, height=500)+
    geom_text(aes(
      -100, 50, label=paste(
                  "Tornado paths and endpoints in ", year),
      showSelected=year),
              data=years)+
    geom_segment(aes(x=startLong, y=startLat, xend=endLong, yend=endLat,
                     showSelected=year),
                 colour=seg.color, data=UStornadoes)+
    geom_point(aes(endLong, endLat, showSelected=year),
               colour=seg.color,
               fill=NA,
               data=UStornadoes)+
    geom_polygon(aes(x=long, y=lat, group=group, clickSelects=state),
                 data=USpolygons, fill="grey", colour="black", alpha=3/4)+
    theme(axis.line=element_blank(), axis.text=element_blank(),
          panel.background=element_rect(color=NA),
          panel.border=element_rect(color=NA),
          axis.ticks=element_blank(), axis.title=element_blank()),
  ts=ggplot()+
    theme_bw()+
    theme_animint(width=300, height=400)+
    xlab("year")+
    ylab("Number of tornadoes")+
    geom_bar(aes(year, count, clickSelects=year, showSelected=state),
             data=UStornadoCounts, stat="identity", position="identity")+
    geom_text(aes(
      1980, 200, label=paste("state =", state), showSelected=state),
              data=states)+
    geom_text(aes(year, count + 5, label=count,
                  showSelected2=year, showSelected=state),
              data=UStornadoCounts, size=20))
structure(tornado.viz, class="animint")