如何在R/Shining中制作时间演化动画?
我正在研究随机微分方程的模拟。我想为获得的轨迹制作一个时间演化动画。我通过如何在R/Shining中制作时间演化动画?,r,animation,shiny,R,Animation,Shiny,我正在研究随机微分方程的模拟。我想为获得的轨迹制作一个时间演化动画。我通过库(anim.plots)尝试了R(我不知道如何使用库(animation)制作时间演化动画),我成功地绘制了两条轨迹,但不是同时绘制。我尝试了合并函数,但没有得到想要的结果。代码如下 library(Sim.DiffProc) library(anim.plots) theta=1 rt=1 at=0.25 K=1000 Tf=3 f<-expression(x*(1-(x/K))^theta*rt) g<
库(anim.plots)
尝试了R(我不知道如何使用库(animation)
制作时间演化动画),我成功地绘制了两条轨迹,但不是同时绘制。我尝试了合并函数,但没有得到想要的结果。代码如下
library(Sim.DiffProc)
library(anim.plots)
theta=1
rt=1
at=0.25
K=1000
Tf=3
f<-expression(x*(1-(x/K))^theta*rt)
g<-expression(x*(1-(x/K))^theta*at)
res <- snssde1d(drift=f,diffusion=g,M=2,x0=150,N=500,t0=0, T=Tf)
windows()
tmp1<-anim.plot(time(res),res$X[,1], speed = 500, type="l", col="red", window=1:t, xlim=c(0,Tf), ylim=c(0,K))
tmp2<-anim.plot(time(res),res$X[,2], speed = 500, type="l", col="red", window=1:t, xlim=c(0,Tf), ylim=c(0,K))
myplot<-merge(tmp1,tmp2)
replay(myplot)
库(Sim.DiffProc)
图书馆(动画情节)
θ=1
rt=1
at=0.25
K=1000
Tf=3
ftweenr加上许多无用的填充物,你需要为每一帧绘制一个完整的图;不能合并两个绘图gganimate
专门为ggplot2
包装animation
,使其非常简单。我还没有使用ggplot及其扩展。我看到tweenr也需要ggplot。还有别的方法吗?或者你能帮我做ggplot吗?tweenr加上很多无用的填充物你需要为每一帧制作一个完整的绘图;不能合并两个绘图gganimate
专门为ggplot2
包装animation
,使其非常简单。我还没有使用ggplot及其扩展。我看到tweenr也需要ggplot。还有别的方法吗?或者你能帮我做些什么?
library(shiny)
ui<-fluidPage(
sliderInput(inputId = "time", label="Time:",
min=0.01, max=10, value=0, step=0.05, animate = animationOptions(50)),
plotOutput("animation")
)
server<-function(input, output, session)
{
res<-reactive({
f<-as.expression(bquote(x*(1-(x/1000))^2*0.5))
g<-as.expression(bquote(x*(1-(x/1000))^2*0.5))
snssde1d(drift=f,diffusion=g, M=5, x0=100, T=input$time, N=1000)
})
output$animation<-renderPlot({
plot(res(), plot.type="single",col="lightgrey", xlim=c(0,10), ylim=c(0,1000))
lines(time(res()),mean(res()), col="red")
})
}
shinyApp(ui=ui, server=server)