#
#
#
library(animation)
library(gganimate)
## Loading required package: ggplot2
#跑了這動畫跑非常久,不得以參考KY同學的將張數下修

Brownian <- function(n = 11, pause = 0.05, nIter = 64, ...) {
    x = rnorm(n)
    y = rnorm(n)
    i = 1
    while (i <= nIter) {
        plot(x, y, ...)
        text(x, y, cex = 0.5)
        x = x + rnorm(n)
        y = y + rnorm(n)
        Sys.sleep(pause)
        i = i + 1
    }
} 

saveGIF(Brownian(xlim = c(-20, 20), ylim = c(-20, 20),pch = 21, cex = 2, col = "cyan", bg = "lavender"))
## Output at: animation.gif
## [1] TRUE
###

test it

/Users/Tjlee/Desktop/weather/animation.gif

/Users/Tjlee/Desktop/weather/animation.gif