我有下面的数据集,它包含许多来自不同椭圆的点。我想每次显示一个完整的椭圆,一旦完全显示,椭圆就可以消失。我目前的解决方案是在gganimate中使用transition_reveal。它有两个问题,第一,过去的痕迹无法消除。第二,椭圆是用geom_路径慢慢显示的,我想从一开始就显示一个完整的椭圆。如何解决这些问题?
library(ggplot2)
library(gganimate)
xx=c(1,1)
vv=c(-1,0)
ep=0.2
L=3
dl=100
#generate data
data<-matrix(0,L*dl,2)
for(i in 1:L){
for(j in 1:dl){
data[(i-1)*dl+j,]=cos(ep*j)*xx+sin(ep*j)*vv
if(j==dl){
xx=data[i*dl,]
vv=rnorm(2)*4
}
}
}
t<-rep(c(1:L),each=dl)
dat=cbind(t,data)
dat<-as.data.frame(dat)
colnames(dat)=c("t","x1","x2")
p=ggplot(dat,aes(x = x1,
y = x2)) +
geom_path()+
transition_reveal(t)
p
在这里输入代码