I'm trying to make an animated line graph to model ecosystem biomass, but I want to have one line (variable) move while the other line (the other variable) is static in the background.
my data frames are taken from an excel sheet using the readxl
package. I have two excel sheets both with an x and y variable, but the x variable on both sheets is the same (biomass).
I set the data from the excel sheets into data frames.
ydf <- data.frame(weight)
y2df <- data.frame (height)
I downloaded ggplot2
,gganimate
, and magick
for this graph. I used the code below to create a graph with two sets of y-variables sharing the same x-variable. I was able to create a line graph that had both y-variables graphed with the same x-variable. Then I tried to animate the plot to have only the "weight" variable move and to keep the "height" variable static :
geom_line(data = ydf, aes(y = weight), color = "green") +
geom_line(data = y2df, aes (y = height), color = "dark green") +
labs(x = "Biomass", y = "size") +
scale_x_reverse (breaks = c(100, 95, 90, 85, 80, 75, 70, 65, 60, 55, 50, 45, 40, 35, 30, 25, 20, 15, 10, 5, 0)) +
scale_y_continuous (breaks = c(0.00, 0.50, 1.00, 1.50, 2.00, 2.50, 3.00, 3.50, 4.00)) +
theme(legend.position="none")
q1_gif <- q1+ geom_line (data = ydf, aes(y = weight)) +
transition_reveal(biomass, range = c(100,0), keep_last = FALSE)
q1_gif
This still resulted in the whole graph being animated (both y-variables being animated) based on the x-variable. Does anyone know how to change the code so that only one variable is animated, but the other variable stays static? I would really appreciate your help!