Hi community,
Im want to make a gganimate plot, but when use anim_save()
the plot make in ggplot2 was change in x axis and legend.
library(tidyverse)
library(gganimate)
library(lubridate)
url <- "https://raw.githubusercontent.com/Aria-Dolatabadian/Dynamic-line-chart/main/temperature_data.csv"
temperature_data<- read_csv(url)
# Convertir la columna 'Day' a formato de fecha
temperature_data$Day <- as.Date(temperature_data$Day, format='%j')
temperature_data <- temperature_data %>%
mutate(Day = ymd(Day)) %>%
arrange(Day) %>%
select(Day, Region1, Region2)
# Crear el gráfico base
p <- ggplot(temperature_data, aes(x = Day)) +
geom_line(aes(y = Region1, color = 'Region 1'), size = 1) +
geom_line(aes(y = Region2, color = 'Region 2'), size = 1) +
scale_color_manual(name = "Regions", values = c("Region 1" = "blue", "Region 2" = "red")) +
labs(x = "Day", y = "Temperature (°C)", title = "Daily Temperature Changes in Two Regions") +
theme_minimal()
But when use anim_save()
show this:
# Animar el gráfico
p_animated <- p +
transition_reveal(Day) +
ease_aes('linear')
# Guardar la animación como un archivo GIF
anim_save("Temperature_Changes_Animation.gif", p_animated)
The x axis and legend are different.