-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcode.R
More file actions
30 lines (24 loc) · 1004 Bytes
/
code.R
File metadata and controls
30 lines (24 loc) · 1004 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
library(animint2)
library(gistr)
data(WorldBank, package="animint2")
WorldBank2005 <- subset(WorldBank, year==2005)
WorldBankBefore2005 <- subset(WorldBank, 2000 <= year & year <= 2005)
plot <- function(df, x.var){
data.frame(df, x.var=factor(x.var, c("year", "life expectancy")))
}
(visualization <- animint(
scatter=ggplot()+
geom_point(aes(x=life.expectancy, y=fertility.rate, color=region),
data=plot(WorldBank2005, "life expectancy"))+
geom_path(aes(x=life.expectancy, y=fertility.rate, color=region,
group=country),
data=plot(WorldBankBefore2005, "life expectancy"))+
geom_line(aes(x=year, y=fertility.rate, color=region, group=country),
data=plot(WorldBank, "year"))+
xlab("")+
facet_grid(. ~ x.var, scales="free")+
theme_bw()+
theme(panel.margin=grid::unit(0, "lines"))
))
animint(out.dir="Interactive Data Visualization")
animint2gist(visualization, description = "My Interactive Visualization")