Hello all,

I have read the documentation of gganimate to animate plots. But how can i animate if there are subplots (scatter plots & histograms, merged together using grid.arrange) in the loop?

Can someone please modify the sample code to illustrate how to animate and create a video of plot p (with multiple subplots).

The original purpose is to save weights of logistic regression off all epochs while training 2D data. Later create a animation video illustrating -

a. hyperplane

b. loss function

c. histogram of probabilities

in different subplots at each epoch during the training process

```
library(tidyverse)
library(gridExtra)
library(grid)
# loop
for (m in 1:100)
{
# line
x <- seq(1, 10000, 1)
y <- m*x
df1 <- tibble(x, y)
p_line <- ggplot(data = df1,
aes(x = x,
y = y)) +
geom_point() +
theme_bw()
# histogram
x <- rnorm(10000, mean = m, sd = 2*m)
df2 <- tibble(x)
p_hist <- ggplot(data = df2,
aes(x = x)) +
geom_histogram(bins = 100) +
theme_bw()
p <- grid.arrange(p_line, p_hist, nrow = 2)
}
```