animation
packageCreated by Toby Hocking (McGill University)
Development through Google Summer of Code
geom_point(aes(x=fertility.rate, y=life.expectancy,
clickSelects=country, showSelected=year,
colour=region, size=population),
data=WorldBank)
svg.selectAll("circle")
.data(one_year)
.enter().append("circle")
.attr("cx", function(d){ return x_scale(d.fertility_rate); })
.attr("cy", function(d){ return y_scale(d.life_expectancy); })
.attr("r", function(d){ return size_scale(d.population); }
.style("fill", function(d){ return color_scale(d.region); })
library(animint)
data(WorldBank)
ts <- ggplot() + make_tallrect(WorldBank, "year")+
geom_line(aes(year, life.expectancy, group=country,
colour=region, clickSelects=country),
data=WorldBank, size=4, alpha=3/5),
scatter <- ggplot() + make_text(WorldBank, 5, 80, "year") +
geom_point(aes(life.expectancy, fertility.rate,
clickSelects=country, showSelected=year,
colour=region, size=population, key=country),
# key aesthetic for animated transitions!
data=WorldBank)+
geom_text(aes(life.expectancy, fertility.rate,
label=country, showSelected=country,
showSelected2=year, key=country),
#also use key here!
data=WorldBank),
viz <- list(ts = ts, scatter = scatter,
time = list(variable="year",ms=3000),
duration = list(year=1000))
gg2animint(viz, open.browser=FALSE)
USpolygons <- map_data("state")
map <- ggplot() +
geom_polygon(aes(x=long, y=lat, group=group, clickSelects=state),
data=USpolygons, fill="black", colour="grey") +
geom_segment(aes(x=startLong, y=startLat, xend=endLong, yend=endLat,
showSelected=year),
colour="#55B1F7", data=UStornadoes) +
theme(axis.line=element_blank(), axis.text=element_blank(),
axis.ticks=element_blank(), axis.title=element_blank()) +
theme_animint(width=970, height=400) # plot dimensions
map
ts <- ggplot() +
geom_bar(aes(year, count, clickSelects=year, showSelected=state),
data=UStornadoCounts, stat="identity", position="identity") +
ylab("Number of Tornadoes") +
xlab("Year") +
theme_animint(width=500, height=400) # plot dimensions
ts
tornado.bar <- list(map = map, ts = ts)
gg2animint(tornado.bar, out.dir = "tornado-bar", open.browser=FALSE)
UStornadoCounts <-
ddply(UStornadoes, .(state, year), summarize, count=length(state))
# Count the number of tornadoes in each state, each year
map <- map + make_text(UStornadoCounts, x=-100, y=50,
label.var="year", format="Tornadoes in %d")
ts <- ts + make_text(UStornadoes, x=1980, y=200,
label.var="state")
tornado.bar <- list(map = map, ts = ts)
gg2animint(tornado.bar, out.dir = "tornado-bar2", open.browser=F)
time <- list(variable="year", ms=1500)
# new part of the list passed to gg2animint().
tornado.anim <- list(map=map, ts=ts, time=time)
# pass the time object in as another object in the main list.
gg2animint(tornado.anim, out.dir = "tornado-anim", open.browser=FALSE)
Slides:
http://srvanderplas.github.io/Presentations/Animint/animint.html
Paper (submitted to InfoVis) -
https://github.com/tdhock/animint-paper/