Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error in build(..., self = self): “theme” argument is missing, #511

Open
dominicroye opened this issue Feb 28, 2025 · 1 comment
Open

Comments

@dominicroye
Copy link

I have issues with animating several different plots with transition_states(). The error always indicate "theme" argument missing.

library(ggplot2)
library(gganimate)
library(dplyr)
library(lubridate)

# Crear datos de ejemplo
set.seed(123)
data <- data.frame(
  date = seq.Date(from = as.Date("2023-01-01"), to = as.Date("2023-12-31"), by = "day"),
  city = rep(c("Madrid", "Barcelona", "Valencia"), each = 365),
  temperature = round(rnorm(365 * 3, mean = 15, sd = 10), 1),
  precipitation = round(runif(365 * 3, min = 0, max = 20), 1)
)

# Filtrar datos para dos ciudades y agrupar por mes
data_summary <- data %>%
  filter(city %in% c("Madrid", "Barcelona")) %>%
  mutate(month = floor_date(date, "month")) %>%
  group_by(city, month) %>%
  summarize(
    avg_temp = mean(temperature),
    total_precip = sum(precipitation)
  )

# Definir una paleta de colores
city_palette <- c("Madrid" = "#1f77b4", "Barcelona" = "#ff7f0e")

# Crear gráfico de temperatura
p1 <- ggplot(data_summary, aes(x = month, y = avg_temp, color = city)) +
  geom_line() +
  labs(title = 'Temperatura Media Mensual: {closest_state}', x = 'Mes', y = 'Temperatura (°C)') +
  scale_color_manual(values = city_palette) +
  theme_minimal() +
  transition_states(month, transition_length = 2, state_length = 1)

# Crear gráfico de precipitación
p2 <- ggplot(data_summary, aes(x = month, y = total_precip, fill = city)) +
  geom_bar(stat = 'identity', position = 'dodge') +
  labs(title = 'Precipitación Total Mensual: {closest_state}', x = 'Mes', y = 'Precipitación (mm)') +
  scale_fill_manual(values = city_palette) +
  theme_minimal() +
  transition_states(month, transition_length = 2, state_length = 1)

# Guardar las animaciones
animate(p1, renderer = gifski_renderer(), duration = 10, fps = 10, width = 800, height = 400)
Error in build(..., self = self): 
  “theme” argument is missing, no default value.
animate(p2, renderer = gifski_renderer(), duration = 10, fps = 10, width = 800, height = 400)
Error in build(..., self = self): 
  “theme” argument is missing, no default value.
> sessionInfo()
R version 4.4.2 (2024-10-31 ucrt)
Platform: x86_64-w64-mingw32/x64
Running under: Windows 11 x64 (build 26100)

Matrix products: default


locale:
[1] LC_COLLATE=Spanish_Spain.utf8  LC_CTYPE=Spanish_Spain.utf8   
[3] LC_MONETARY=Spanish_Spain.utf8 LC_NUMERIC=C                  
[5] LC_TIME=Spanish_Spain.utf8    

time zone: Europe/Madrid
tzcode source: internal

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] lubridate_1.9.4    dplyr_1.1.4        gganimate_1.0.9   
[4] ggplot2_3.5.1.9000

loaded via a namespace (and not attached):
 [1] crayon_1.5.3      vctrs_0.6.5       cli_3.6.3        
 [4] knitr_1.49        rlang_1.1.5       xfun_0.51        
 [7] gifski_1.32.0-1   stringi_1.8.4     generics_0.1.3   
[10] labeling_0.4.3    glue_1.8.0        prettyunits_1.2.0
[13] colorspace_2.1-1  hms_1.1.3         rsconnect_1.3.4  
[16] scales_1.3.0      tweenr_2.0.3      grid_4.4.2       
[19] munsell_0.5.1     evaluate_1.0.3    tibble_3.2.1     
[22] progress_1.2.3    lifecycle_1.0.4   compiler_4.4.2   
[25] timechange_0.3.0  pkgconfig_2.0.3   rstudioapi_0.17.1
[28] farver_2.1.2      R6_2.6.1          tidyselect_1.2.1 
[31] pillar_1.10.1     magrittr_2.0.3    tools_4.4.2      
[34] withr_3.0.2       gtable_0.3.6 
@dominicroye
Copy link
Author

There seems to be a bug. This example has similar issues.

ggplot(mtcars, aes(factor(cyl), mpg)) + 
  geom_boxplot() + 
 # Here comes the gganimate code
  transition_states(
    gear,
    transition_length = 2,
    state_length = 1
  ) +
  enter_fade() + 
  exit_shrink() +
  ease_aes('sine-in-out')
Theme element `panel.border` is missing
Theme element `panel.grid.minor.y` is missing
Theme element `panel.grid.major.y` is missing
Theme element `panel.grid.major.x` is missing
Theme element `panel.background` is missing
Aviso: Cannot get dimensions of plot table. Plot region might not be fixed
Caused by error in `UseMethod()`:
! no applicable method for 'element_grob' applied to an object of class "NULL"
Theme element `panel.border` is missing
Theme element `panel.grid.minor.y` is missing
Theme element `panel.grid.major.y` is missing
Theme element `panel.grid.major.x` is missing
Theme element `panel.background` is missing
Aviso: Failed to plot frame

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant