2

我有一个州每个县的每周数据。我想创建一个动画,每周循环显示绘制到地图上的数据,颜色表示强度和/或前一周的变化。

library(ggplot2); library(animation); library(maps); library(plyr)

county <- map_data("county")

wy <- county[county$region =="wyoming",]

l = length((wy$subregion))
#Add random variales
wy <- mutate(wy, a = runif(length(region)), 
             b = runif(length(region)), 
             c= runif(length(region)))

test <- function(j){             
ggplot(wy, aes(long, lat, group = group))+ 
  geom_path() + 
  geom_polygon(aes_string(fill=j))
}

test("c")
test("b")


v = c("a","b","c"))

oopt <- animation::ani.options(interval = 0.1)

FUN2 <- function() {
  lapply(v, function(i) {
    test(i)
    animation::ani.pause()
  })
}
FUN2()

saveHTML(FUN2(), autoplay = FALSE, loop = FALSE, verbose = FALSE, outdir = "images/animate/new",
 single.opts = "'controls': ['first', 'previous', 'play', 'next', 'last', 'loop', 'speed'], 'delayMin': 0")

最后一个函数调用有什么问题?

4

1 回答 1

6
library(ggplot2); library(animation); library(maps); library(plyr)

county <- map_data("county")

wy <- county[county$region =="wyoming",]

l = length((wy$subregion))
#Add random variales
wy <- mutate(wy, a = runif(length(region)), 
             b = runif(length(region)), 
             c= runif(length(region)))

test <- function(j){             
  ggplot(wy, aes(long, lat, group = group))+ 
    geom_path() + 
    geom_polygon(aes_string(fill=j))
}

test("c")
test("b")

wy$1 <- wy$a

oopt <- animation::ani.options(interval = 0.1)

FUN2 <- function() {
  v = c("a","b","c")
  lapply(v, function(i) {
    print(test(i))
    ani.pause()
  })
}
FUN2()

saveHTML(FUN2(), autoplay = FALSE, loop = FALSE, verbose = FALSE, outdir = "images/animate/new",
         single.opts = "'controls': ['first', 'previous', 'play', 'next', 'last', 'loop', 'speed'], 'delayMin': 0")

缺少print(test(i))第二个功能。

于 2013-11-13T04:05:22.013 回答