Attaching Multiple Graphs Together

I made the following 3 graphs in R:

#create data
a = abs(rnorm(100,10,10))
b = abs(rnorm(100,10,10))
i = 1
c = data.frame(a,b,i)
c$col = as.factor(ifelse(c$b>10,"red", "blue"))

a = abs(rnorm(100,10,10))
b = abs(rnorm(100,10,10))
i = 2
d = data.frame(a,b,i)
d$col = as.factor(ifelse(d$a>10,"red", "blue"))

a = abs(rnorm(100,10,10))
b = abs(rnorm(100,10,10))
i = 3
e = data.frame(a,b,i)
e$col = as.factor(ifelse(e$b>10,"red", "blue"))

   #put all the datasets together (i=1, i=2, i=3)
g = rbind(c,d,e)

 #plot
plot_1 = plot(c$a, type = "h", col = c$col, main = "plot_1, i = 1")
plot_2 = plot(d$a, type = "h", col = d$col, main = "plot_2, i = 2")
plot_3 = plot(e$a, type = "h", col = e$col, main = "plot_3, i = 3")

enter image description here

I am trying to make an "animation" of these graphs : plot_1 -> plot_2 -> plot_3

I was able to do something similar using ggplot2/gganimate:

library(ggplot2)
library(gganimate)

animate(
  ggplot(g, aes(x=a)) + 
  geom_histogram(binwidth=1) +
  transition_states(i, state_length = 0.2) +
  labs(title = "Group: {closest_state}"),
  fps = 25)

enter image description here

But I am specifically trying to do this using the graphs created with base R. This is because I find the coloring scheme more effective, I can't seem to as clearly show the different colors in the ggplot version as I can with the base R version. Can someone please show me how to "animate/attach" these 3 graphs together?

enter image description here

Thanks!

In ggplot2 you can pick what colour to use for any colourable element, of which there are many. Perhaps look into that?

1 Like

thank you! i will look into that

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.