# 我花了4小時研究它讓它動起來
#
#
library(animation)
library(gganimate)
## Loading required package: ggplot2
library(dplyr)
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
n <- 60
t <- seq(0, 2*pi, length=n)
x <- sin(t)
y <- cos(t)
#
par(pty = "s")
#
saveGIF(for (i in 1:n) {
  plot.new()
  plot.window(c(-1, 1), c(-1, 1))
  lines(x*y, -y, col="gray")
  points(x[i]*y[i], -y[i], pch=16,
  col=gray((i-1)/(n+1)))
  Sys.sleep(.05)
})
## Output at: animation.gif
## [1] TRUE
  gif <- function(pathIn="/Users/Tjlee/Desktop/weather/animation.gif") 

gif 

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

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

#we can see n=1:60 are 60 plot #point character =pch #Sys.sleep(.05)= time interval .05