Introduce gganimate for Psychometric

R
Tutorial
Author

Jihong

Published

February 22, 2019

A new R packge (gganimate ) provides some new features for animation in R. Its big advantage is it could make use of ggplot API and embeded into ggplot. Next, I will use a sample data to show the example. Then I will use some real educational data to explore a little bit what we can do in psychometric area.

1 A Simple Example

I want to introduce this package.

1.1 1.0 Load the packages requried

1.2 1.1 prepare the data

⌘+C
data("austres")
dt <- data.frame(x=as.matrix(austres), date=time(austres))
dt$y <- rnorm(nrow(dt))
dt$date  <- as.numeric(dt$date)
⌘+C
p <- ggplot(dt,
            aes(y = y, x =x)) +
  geom_line(alpha = 0.7) +
  geom_point()
p

1.2.1 transition_reveal: gradually reveal the data

⌘+C
p + transition_reveal(date)

⌘+C
dt$g <- rep( c("red", "green", "blue"), length.out = nrow(dt))
⌘+C
p_bygroup <- ggplot(dt,
            aes(y = y, x =x, col = g)) +
  geom_line(alpha = 0.7) +
  geom_point()
p_bygroup

⌘+C
p_bygroup + transition_reveal(date)

1.2.2

Back to top