Gganimate animation not being plotted

25 Views Asked by At

I have the code below for an animation, while I can see the point moving, nothing is plotted. When I use the same code with transition_reveal, it's plotted. I'm trying to figure out why transition_states here is not plotting anything. I'm really curious to find out why this is happening

See Gif:

See Gif

library(ggplot2)
library(gganimate)
library(readxl)
library(dplyr)

gg <- read_excel("Book12.xlsx")
gg$year2 <- as.Date(gg$year2)

gg$week <- format(gg$year2, "%V")
gg$year <- format(gg$year2, "%Y")

# Define your custom titles
gg$custom_titles <- paste("Week", gg$week, "of Year", gg$year)

# Create animated life expectancy chart
expectancyca <- gg %>%
  filter(fruit %in% c("Blueberries", "Strawberries", "Blackberries", "Raspberries")) %>%
  ggplot(aes(x = year2, y = price, frame = custom_titles)) +
  geom_line(size = 4, color = "#ff0326") +
  geom_point(aes( group = seq_along(year2), color = "#ff0326"), size = 4, alpha = 1) +
  geom_image(aes(image = image_path), size = 0.1) +
  labs(title = '{closest_state}',
       x = NULL, y = NULL) +
  facet_wrap(~fruit) +
  # Adding y-axis labels with commas
  theme_minimal() +
  theme(legend.position = "none",
        panel.grid.minor = element_blank(),
        panel.border = element_blank(),
        plot.title = element_text(hjust = 0.5, size = 18, face = "bold"),
        plot.subtitle = element_text(hjust = 0.5, size = 14, face = "italic"),
        plot.caption = element_text(size = 11)) +
  transition_states(custom_titles,
                    transition_length = 0.1,
                    state_length = 0.1)

# Save animation
anim_save("fruitprice.gif", expectancyca, width = 1000, height = 1000, res = 110)


I played around with geom_point and geom_line but not seeing any changes

0

There are 0 best solutions below