While replicating a question posed on this website, I tried to rerun the following code
data <- structure(list(x = 1:6, y = 2:7, year = c(2010L, 2010L, 2011L,
2011L, 2012L, 2012L)), class = "data.frame", row.names = c(NA,
-6L))
library(tidyverse)
library(gganimate)
p <- ggplot(data, aes(x, y))+
geom_point() +
transition_time(year) +
labs(title = "Year: {as.integer(frame_time)}")
p_anim <- animate(p, nframes = 30, fps = 4)
anim_save("myfig.gif", p_anim)
While it was supposed to work fine, I received the following error, which I am usually getting in making animated visualizations with gganimate
such as replicating the animated map in this post
Invalid input type, expected 'double' actual 'logical'
.
I do not understand why this error occurs, and I could not find any similar posts on the web except this post, which is unanswered. Therefore, I welcome your replies regarding this error. Thank you beforehand.
I can't seem to replicate your error:
I'd suggest checking your R and package versions (e.g. with sessionInfo()
) and make sure they're all up-to-date.
Output of your code + my sessionInfo():
> data <- structure(list(x = 1:6, y = 2:7, year = c(2010L, 2010L, 2011L,
+ 2011L, 2012L, 2012L)), class = "data.frame", row.names = c(NA,
+ -6L))
> library(tidyverse)
── Attaching packages ──────────────────────────────────────────────────────────────────────────────────────────────────────────── tidyverse 1.3.1 ──
✔ ggplot2 3.3.6 ✔ purrr 0.3.4
✔ tibble 3.1.7 ✔ dplyr 1.0.9
✔ tidyr 1.2.0 ✔ stringr 1.4.0
✔ readr 2.1.2 ✔ forcats 0.5.1
── Conflicts ─────────────────────────────────────────────────────────────────────────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag() masks stats::lag()
> library(gganimate)
> p <- ggplot(data, aes(x, y))+
+ geom_point() +
+ transition_time(year) +
+ labs(title = "Year: {as.integer(frame_time)}")
> p_anim <- animate(p, nframes = 30, fps = 4)
Inserting image 30 at 7.25s (100%)...
Encoding to gif... done!
> anim_save("myfig.gif", p_anim)
> sessionInfo()
R version 4.2.1 (2022-06-23)
Platform: x86_64-apple-darwin21.5.0 (64-bit)
Running under: macOS Monterey 12.3.1
Matrix products: default
LAPACK: /usr/local/Cellar/r/4.2.1/lib/R/lib/libRlapack.dylib
locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] gganimate_1.0.7 forcats_0.5.1 stringr_1.4.0 dplyr_1.0.9 purrr_0.3.4 readr_2.1.2 tidyr_1.2.0 tibble_3.1.7 ggplot2_3.3.6
[10] tidyverse_1.3.1
loaded via a namespace (and not attached):
[1] progress_1.2.2 tidyselect_1.1.2 haven_2.5.0 colorspace_2.0-3 vctrs_0.4.1 generics_0.1.2 utf8_1.2.2 rlang_1.0.3
[9] pillar_1.7.0 glue_1.6.2 withr_2.5.0 DBI_1.1.3 tweenr_1.0.2 dbplyr_2.2.1 modelr_0.1.8 readxl_1.4.0
[17] lifecycle_1.0.1 plyr_1.8.7 munsell_0.5.0 gtable_0.3.0 cellranger_1.1.0 rvest_1.0.2 labeling_0.4.2 tzdb_0.3.0
[25] fansi_1.0.3 gifski_1.6.6-1 broom_1.0.0 Rcpp_1.0.8.3 scales_1.2.0 backports_1.4.1 jsonlite_1.8.0 farver_2.1.0
[33] fs_1.5.2 digest_0.6.29 hms_1.1.1 stringi_1.7.6 grid_4.2.1 cli_3.3.0 tools_4.2.1 magrittr_2.0.3
[41] crayon_1.5.1 pkgconfig_2.0.3 ellipsis_0.3.2 xml2_1.3.3 prettyunits_1.1.1 reprex_2.0.1 lubridate_1.8.0 assertthat_0.2.1
[49] httr_1.4.3 rstudioapi_0.13 R6_2.5.1 compiler_4.2.1