How to animate a vector field along a given curve with gganimate

Happy 2022, RStudio Community!

I want to animate a vector field along a given curve, using gganimate, so that at any given moment the current frame shows only the vector at the current position along the curve, but the entire curve is shown in every frame. I would really appreciate any help?

In the code chunk below, I almost created what I want but the curve loops back. Also, the curve looks very pixelated. There must be a way to turn this geom_function into a layer so that the entire curve is displayed in every frame, without looping back.

data<- tibble(x = seq(0,20,by = 0.1), y = sqrt(x) , vx = 1, vy = 1)
p<-ggplot(data, aes(x,y)) +
  coord_fixed() +
  geom_function(fun=function(u) sqrt(u), xlim=c(0,20), col="gray") +
  geom_line() +
  geom_point() +
  geom_segment(aes(x = x, y = y, xend = x + vx, yend = y + vy), 
               arrow = arrow(angle = 30, length = unit(2, "mm"),
               ends = "last", type = "open"), col="blue")
p + transition_reveal(x)


This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.