I figured out that I need to use the animation package and not gganimate because my code consists of 2 vectors. My new code is:
install.packages("animation")
library(animation)
saveGIF({for (pi in seq(0,1,0.1)) {
x <- seq(1,11,by=1)
y <- dbinom(1, x,pi)
barplot(y,xlim=c(0,10),ylim=c(0,1), col = "blue", main = "n=10", names.arg=c(0,1,2,3,4,5,6,7,8,9,10))
Sys.sleep(1)
print(y)
ani.record()}
})
I cannot get all the frames to come together in a loop even when I said "ani.record" it gives me an error. Do you maybe know how i can create the gif with all my frames already created?