如何创建一个动画,显示带有数字行的有序数字数组?
How to create an animation showing an array of ordered numbers with number line?
我有一个包含 94 个数字的数组 var1
。我希望它们以定义的间隔(例如 0.05 秒)显示在 gif 中。如果可能的话,我还想添加一个数字行。我希望看到这样的图片(当然是动画):
=========================================== ===========
COV1 = 2.34
------------|-------------------------------- ---> cov1
_____2.34
=========================================== ===========
我刚刚成功地将 gganimate
包用于一些情节,但后来我意识到我还需要为一些不是情节的东西制作动画......也许与 animation
包有关?
谢谢!
看起来不是特别有启发性(其实看着就头疼),但是动画化了。
library(tidyverse)
library(gganimate)
set.seed(10)
dat = data.frame(x=sort(runif(94, 0, 100)))
p = ggplot(dat) +
geom_line(data=data.frame(y=rep(c(0.90,0.905,1.095,1.1),each=2), x=rep(range(dat$x), 4)),
aes(x,y,group=y), size=1, colour="grey40", linetype=2) +
geom_line(aes(x,y=1), colour="grey60", size=1.5, linetype="11") +
geom_text(aes(label=paste0("COV1\n", round(x,2)), x=x, y=1.05, frame=x), size=5) +
geom_segment(aes(x=min(dat$x), xend=x, y=1, yend=1, frame=x),
arrow=arrow(angle=90, length=unit(0.4, "cm")), size=1.5) +
scale_y_continuous(limits=c(0.8,1.1)) +
theme_void() +
theme(plot.title=element_blank())
gganimate(p, filename="my_gif.gif", interval=0.05)
我有一个包含 94 个数字的数组 var1
。我希望它们以定义的间隔(例如 0.05 秒)显示在 gif 中。如果可能的话,我还想添加一个数字行。我希望看到这样的图片(当然是动画):
=========================================== ===========
COV1 = 2.34
------------|-------------------------------- ---> cov1
_____2.34
=========================================== ===========
我刚刚成功地将 gganimate
包用于一些情节,但后来我意识到我还需要为一些不是情节的东西制作动画......也许与 animation
包有关?
谢谢!
看起来不是特别有启发性(其实看着就头疼),但是动画化了。
library(tidyverse)
library(gganimate)
set.seed(10)
dat = data.frame(x=sort(runif(94, 0, 100)))
p = ggplot(dat) +
geom_line(data=data.frame(y=rep(c(0.90,0.905,1.095,1.1),each=2), x=rep(range(dat$x), 4)),
aes(x,y,group=y), size=1, colour="grey40", linetype=2) +
geom_line(aes(x,y=1), colour="grey60", size=1.5, linetype="11") +
geom_text(aes(label=paste0("COV1\n", round(x,2)), x=x, y=1.05, frame=x), size=5) +
geom_segment(aes(x=min(dat$x), xend=x, y=1, yend=1, frame=x),
arrow=arrow(angle=90, length=unit(0.4, "cm")), size=1.5) +
scale_y_continuous(limits=c(0.8,1.1)) +
theme_void() +
theme(plot.title=element_blank())
gganimate(p, filename="my_gif.gif", interval=0.05)