- Collected in animate_options.R - Sets global defaults in plot_settings environment - Adds ability to set animation options, similar to theme_set() from ggplot2 - Adds getters for current (if set) or default animation options Merge branch 'pkg-add-anim-options-merge' into pkg-add-anim-options # Conflicts: # NAMESPACE # R/animate_tidyr.R # R/plot_helpers.R # man/anim_options.Rd # man/animate_gather.Rd # man/animate_spread.Rd # man/static_plot.Rdpkg-add-anim-opts-fixed
| export("%>%") | export("%>%") | ||||
| export(anim_options) | export(anim_options) | ||||
| export(anim_options_set) | |||||
| export(animate_anti_join) | export(animate_anti_join) | ||||
| export(animate_full_join) | export(animate_full_join) | ||||
| export(animate_gather) | export(animate_gather) | ||||
| export(animate_spread) | export(animate_spread) | ||||
| export(animate_union) | export(animate_union) | ||||
| export(animate_union_all) | export(animate_union_all) | ||||
| export(get_font_size) | |||||
| export(set_font_size) | export(set_font_size) | ||||
| importFrom(dplyr,anti_join) | importFrom(dplyr,anti_join) | ||||
| importFrom(dplyr,arrange) | importFrom(dplyr,arrange) |
| #' Animation Options | |||||
| #' | |||||
| #' Helper function to set animation and plotting options to be passed to | |||||
| #' [animate_plot()] and [static_plot()]. | |||||
| #' | |||||
| #' @param text_family Font family for the plot text, default is "Fira Mono". Use | |||||
| #' [set_font_size()] to set global default font sizes. | |||||
| #' @param title_family Font family for the plot title, default is "Fira Mono". | |||||
| #' Use [set_font_size()] to set global default font sizes. | |||||
| #' @param text_size Font size of the plot text, default is 5. | |||||
| #' @param title_size Font size of the plot title, default is 17. | |||||
| #' @param ease_default Default aes easing function. See [tweenr::display_ease()] | |||||
| #' for more options. The tidyexplain default value is `sine-in-out`. | |||||
| #' @param ease_other Additional aes easing options, specified as a named list. | |||||
| #' List entries are named with the aesthetic to which the easeing should be | |||||
| #' applied, consistent with [gganimate::ease_aes()]. E.g. `list(color = | |||||
| #' "sine")`. | |||||
| #' @param enter Enter fading function applied to objects in the animation. See | |||||
| #' [gganimate::enter_exit] for a complete list of options. The tidyexplain | |||||
| #' default is [gganimate::enter_fade()]. | |||||
| #' @param exit Exit fading function applied to objects in the animation. See | |||||
| #' [gganimate::enter_exit] for a complete list of options. The tidyexplain | |||||
| #' default is [gganimate::exit_fade()]. | |||||
| #' @inheritParams gganimate::transition_states | |||||
| #' @export | |||||
| anim_options <- function( | |||||
| transition_length = NULL, | |||||
| state_length = NULL, | |||||
| ease_default = NULL, | |||||
| ease_other = NULL, | |||||
| enter = NULL, | |||||
| exit = NULL, | |||||
| text_family = NULL, | |||||
| title_family = NULL, | |||||
| text_size = NULL, | |||||
| title_size = NULL, | |||||
| ... | |||||
| ){ | |||||
| enter_name <- if (!missing(enter)) rlang::quo_name(rlang::enquo(enter)) | |||||
| exit_name <- if (!missing(exit)) rlang::quo_name(rlang::enquo(exit)) | |||||
| ao <- list( | |||||
| transition_length = transition_length, | |||||
| state_length = state_length, | |||||
| ease_default = ease_default, | |||||
| ease_other = ease_other, | |||||
| enter = if (!is.null(enter)) setNames(list(enter), enter_name), | |||||
| exit = if (!is.null(exit)) setNames(list(exit), exit_name), | |||||
| text_family = text_family, | |||||
| text_size = text_size, | |||||
| title_family = title_family, | |||||
| title_size = title_size, | |||||
| ... | |||||
| ) | |||||
| ao <- purrr::compact(ao) | |||||
| structure(ao, class = "anim_opts") | |||||
| } | |||||
| # Global Animation Options Setters and Getters ---------------------------- | |||||
| #' @describeIn anim_options Set default animation options for the current session. | |||||
| #' @param anim_opts An [anim_options()] options list. | |||||
| #' @export | |||||
| anim_options_set <- function(anim_opts) { | |||||
| stopifnot(is.anim_opts(anim_opts)) | |||||
| ao_old <- plot_settings$anim_opts | |||||
| plot_settings$anim_opts <- merge(anim_opts, plot_settings$anim_opts) | |||||
| invisible(ao_old) | |||||
| } | |||||
| get_anim_opt <- function(anim_opt = NULL) { | |||||
| if (is.null(anim_opt)) return(plot_settings$anim_opts) | |||||
| if (anim_opt %in% c("text_size", "title_size")) rlang::abort( | |||||
| "Use get_text_size() or get_title_size()" | |||||
| ) | |||||
| plot_settings$anim_opts[[anim_opt]] %||% plot_settings$default[[anim_opt]] | |||||
| } | |||||
| # Animation Options Methods ----------------------------------------------- | |||||
| print.anim_opts <- function(ao) { | |||||
| aop <- purrr::discard(ao, is.null) | |||||
| # Replace ggproto (enter/exit functions) with their names | |||||
| if ("enter" %in% names(aop)) aop$enter <- paste("ggproto:", names(ao$enter)) | |||||
| if ("exit" %in% names(aop)) aop$exit <- paste("ggproto:", names(ao$exit)) | |||||
| str(aop) | |||||
| invisible(ao) | |||||
| } | |||||
| is.anim_opts <- function(ao) inherits(ao, "anim_opts") | |||||
| # Fill, Validate, Merge Animation Options --------------------------------- | |||||
| # Fills in default animation options | |||||
| fill_anim_opts <- function(ao) { | |||||
| ao$transition_length <- ao$transition_length %||% get_anim_opt("transition_length") | |||||
| ao$state_length <- ao$state_length %||% get_anim_opt("state_length") | |||||
| ao$ease_default <- ao$ease_default %||% get_anim_opt("ease_default") | |||||
| ao$ease_other <- ao$ease_other %||% get_anim_opt("ease_other") | |||||
| ao$enter <- ao$enter %||% get_anim_opt("enter") | |||||
| ao$exit <- ao$exit %||% get_anim_opt("exit") | |||||
| ao$text_family <- ao$text_family %||% get_anim_opt("text_family") | |||||
| ao$title_family <- ao$title_family %||% get_anim_opt("title_family") | |||||
| ao | |||||
| } | |||||
| validate_anim_opts <- function(ao, quiet = FALSE, strict = getOption("tidyexplain.strict_dots", FALSE)) { | |||||
| if (!inherits(ao, "anim_opts")) { | |||||
| rlang::warn("Use `anim_options()` to set `anim_opts`") | |||||
| } | |||||
| ao <- fill_anim_opts(ao) | |||||
| stopifnot(is.ggproto(ao$enter[[1]]), is.ggproto(ao$exit[[1]])) | |||||
| extra_names <- setdiff(names(ao), names(formals(anim_options))) | |||||
| if (!quiet && length(extra_names)) { | |||||
| extra_names <- paste0(sprintf("`%s`", extra_names), collapse = ", ") | |||||
| msg <- paste("Unknown animation options will be ignored:", extra_names) | |||||
| if (isTrue(strict)) rlang::abort(msg) else rlang::warn(msg) | |||||
| } | |||||
| invisible(ao) | |||||
| } | |||||
| merge.anim_opts <- function(ao_new, ao_base = anim_options()) { | |||||
| ao_new <- purrr::discard(ao_new, is.null) | |||||
| ao_base <- purrr::discard(ao_base, is.null) | |||||
| unique_base <- setdiff(names(ao_base), names(ao_new)) | |||||
| ao <- append(ao_new, ao_base[unique_base]) | |||||
| ao <- ao[names(formals(anim_options))] | |||||
| ao <- purrr::discard(ao, is.null) | |||||
| class(ao) <- "anim_opts" | |||||
| ao | |||||
| } | |||||
| # Default Animation Options for Verb Families ----------------------------- | |||||
| default_anim_opts <- function(family, ao_custom = NULL) { | |||||
| family_options <- c("join", "set", "gather", "spread") | |||||
| family <- match.arg(family, family_options, several.ok = FALSE) | |||||
| ao_default <- switch( | |||||
| family, | |||||
| "gather" = anim_options(enter = enter_fade(), exit = exit_fade(), | |||||
| ease_default = "sine-in-out", | |||||
| ease_other = list(y = "cubic-out", x = "cubic-in")), | |||||
| "spread" = anim_options(enter = enter_fade(), exit = exit_fade(), | |||||
| ease_default = "sine-in-out", | |||||
| ease_other = list(y = "cubic-out", x = "cubic-in")), | |||||
| anim_options() | |||||
| ) | |||||
| if (is.null(ao_custom)) ao_default else merge(ao_custom, ao_default) | |||||
| } | |||||
| # Font Size Setters and Getters ------------------------------------------- | |||||
| #' Set Default Text Sizes for Animation Plots | |||||
| #' | |||||
| #' Sets the default text sizes for the animated and static plots produced by | |||||
| #' this package during the current session. | |||||
| #' | |||||
| #' @param text_size Font size of value labels inside the data frame squares | |||||
| #' @param title_size Font size of the function call or plot title | |||||
| #' @export | |||||
| set_font_size <- function(text_size = NULL, title_size = NULL) { | |||||
| old <- list() | |||||
| if (!is.null(text_size)) old$text_size <- set_text_size(text_size) | |||||
| if (!is.null(title_size)) old$title_size <- set_title_size(title_size) | |||||
| invisible(old) | |||||
| } | |||||
| #' @describeIn set_font_size Get current global font sizes | |||||
| #' @export | |||||
| get_font_size <- function() { | |||||
| list("text_size" = get_text_size(), "title_size" = get_title_size()) | |||||
| } | |||||
| set_text_size <- function(size) { | |||||
| old <- plot_settings$text_size | |||||
| anim_options_set(anim_options(text_size = size)) | |||||
| invisible(old) | |||||
| } | |||||
| set_title_size <- function(size) { | |||||
| old <- plot_settings$title_size | |||||
| anim_options_set(anim_options(title_size = size)) | |||||
| invisible(old) | |||||
| } | |||||
| get_text_size <- function(x = NULL) { | |||||
| if (!is.null(x)) return(x) | |||||
| plot_settings$anim_opts$text_size %||% | |||||
| getFromNamespace("theme_env", "ggplot2")$current$text$size %||% | |||||
| plot_settings$default$text_size | |||||
| } | |||||
| get_title_size <- function(x = NULL) { | |||||
| if (!is.null(x)) return(x) | |||||
| plot_settings$anim_opts$text_size %||% | |||||
| getFromNamespace("theme_env", "ggplot2")$current$plot.title$size %||% | |||||
| plot_settings$default$title_size | |||||
| } |
| #' Animates the gather function | #' Animates the gather function | ||||
| #' | #' | ||||
| #' @param w a data_frame in the wide format | #' @param w a data_frame in the wide format | ||||
| #' # if you want to have a less detailed animation, you can also use | #' # if you want to have a less detailed animation, you can also use | ||||
| #' animate_gather(wide, "person", "sales", -year, export = "gif", detailed = FALSE) | #' animate_gather(wide, "person", "sales", -year, export = "gif", detailed = FALSE) | ||||
| #' } | #' } | ||||
| animate_gather <- function(w, key, value, ..., export = "gif", detailed = TRUE, anim_opts = anim_options()) { | |||||
| animate_gather <- function(w, key, value, ..., export = "gif", detailed = TRUE, anim_opts = NULL) { | |||||
| anim_opts <- default_anim_opts("gather", anim_opts) | |||||
| lhs <- w | lhs <- w | ||||
| rhs <- tidyr::gather(w, !!key, !!value, ...) | rhs <- tidyr::gather(w, !!key, !!value, ...) | ||||
| #' # if you want to have a less detailed animation, you can also use | #' # if you want to have a less detailed animation, you can also use | ||||
| #' animate_spread(long, key = "person", value = "sales", export = "gif", detailed = FALSE) | #' animate_spread(long, key = "person", value = "sales", export = "gif", detailed = FALSE) | ||||
| #' } | #' } | ||||
| animate_spread <- function(l, key, value, export = "gif", detailed = TRUE, ..., anim_opts = anim_options()) { | |||||
| animate_spread <- function(l, key, value, export = "gif", detailed = TRUE, ..., anim_opts = NULL) { | |||||
| anim_opts <- default_anim_opts("spread", anim_opts) | |||||
| lhs <- l | lhs <- l | ||||
| rhs <- tidyr::spread(l, key = key, value = value) | rhs <- tidyr::spread(l, key = key, value = value) |
| #' Animation Options | #' Animation Options | ||||
| #' | #' | ||||
| #' Helper function to set animation and plotting options to be passed to | |||||
| #' [animate_plot()] and [static_plot()]. | |||||
| #' | |||||
| #' @param text_family Font family for the plot text | |||||
| #' @param title_family Font family for the plot title | |||||
| #' @param text_size Font size of the plot text | |||||
| #' @param title_size Font size of the plot title | |||||
| #' @param ease_default Default aes easing function. See [tweenr::display_ease()] | |||||
| #' for more options. | |||||
| #' @param ease_other Additional aes easing options, specified as a named list. | |||||
| #' List entries are named with the aesthetic to which the easeing should be | |||||
| #' applied, consistent with [gganimate::ease_aes()]. | |||||
| #' E.g. `list(color = "sine")`. | |||||
| #' @param enter Enter fading function applied to objects in the animation. See | |||||
| #' [gganimate::enter_exit] for a complete list of options. | |||||
| #' @param exit Exit fading function applied to objects in the animation. See | |||||
| #' [gganimate::enter_exit] for a complete list of options. | |||||
| #' @inheritParams gganimate::transition_states | |||||
| #' @export | |||||
| anim_options <- function( | |||||
| transition_length = 2, | |||||
| state_length = 1, | |||||
| ease_default = "sine-in-out", | |||||
| ease_other = NULL, | |||||
| enter = enter_fade(), | |||||
| exit = exit_fade(), | |||||
| text_family = "Fira Sans", | |||||
| title_family = "Fira Mono", | |||||
| text_size = NULL, | |||||
| title_size = NULL, | |||||
| ... | |||||
| ){ | |||||
| enter_name <- rlang::quo_name(rlang::enquo(enter)) | |||||
| exit_name <- rlang::quo_name(rlang::enquo(exit)) | |||||
| structure( | |||||
| list( | |||||
| transition_length = transition_length, | |||||
| state_length = state_length, | |||||
| ease_default = ease_default, | |||||
| ease_other = ease_other, | |||||
| enter = setNames(list(enter), enter_name), | |||||
| exit = setNames(list(exit), exit_name), | |||||
| text_family = text_family, | |||||
| text_size = text_size, | |||||
| title_family = title_family, | |||||
| title_size = title_size, | |||||
| ... | |||||
| ), | |||||
| class = "anim_opts" | |||||
| ) | |||||
| } | |||||
| print.anim_opts <- function(ao) { | |||||
| aop <- ao | |||||
| # Replace ggproto (enter/exit functions) with their names | |||||
| aop$enter <- paste("ggproto:", names(ao$enter)) | |||||
| aop$exit <- paste("ggproto:", names(ao$exit)) | |||||
| str(aop) | |||||
| invisible(ao) | |||||
| } | |||||
| validate_anim_opts <- function(ao, quiet = FALSE, strict = getOption("tidyexplain.strict_dots", FALSE)) { | |||||
| if (!inherits(ao, "anim_opts")) { | |||||
| rlang::warn("Use `anim_options()` to set `anim_opts`") | |||||
| } | |||||
| stopifnot(is.ggproto(ao$enter[[1]]), is.ggproto(ao$exit[[1]])) | |||||
| extra_names <- setdiff(names(ao), names(formals(anim_options))) | |||||
| if (!quiet && length(extra_names)) { | |||||
| extra_names <- paste0(sprintf("`%s`", extra_names), collapse = ", ") | |||||
| msg <- paste("Unknown animation options will be ignored:", extra_names) | |||||
| if (isTrue(strict)) rlang::abort(msg) else rlang::warn(msg) | |||||
| } | |||||
| invisible(ao) | |||||
| } | |||||
| #' Animates a plot | |||||
| #' | |||||
| #' @param d a processed dataset | #' @param d a processed dataset | ||||
| #' @param title the title of the plot | #' @param title the title of the plot | ||||
| #' @param anim_opts Animation options generated with [anim_options()]. Overrides | #' @param anim_opts Animation options generated with [anim_options()]. Overrides | ||||
| anim_opts = anim_options(...) | anim_opts = anim_options(...) | ||||
| ) { | ) { | ||||
| ao <- validate_anim_opts(anim_opts) | ao <- validate_anim_opts(anim_opts) | ||||
| text_size <- get_text_size(ao$text_size, default = 5) | |||||
| title_size <- get_title_size(ao$title_size, default = 17) | |||||
| text_size <- get_text_size(ao$text_size) | |||||
| title_size <- get_title_size(ao$title_size) | |||||
| if (!".alpha" %in% names(d)) d <- d %>% mutate(.alpha = 1) | if (!".alpha" %in% names(d)) d <- d %>% mutate(.alpha = 1) | ||||
| if (!".textcolor" %in% names(d)) | if (!".textcolor" %in% names(d)) | ||||
| theme_void() + | theme_void() + | ||||
| theme(plot.title = element_text(family = ao$title_family, hjust = 0.5, size = title_size)) | theme(plot.title = element_text(family = ao$title_family, hjust = 0.5, size = title_size)) | ||||
| } | } | ||||
| #' Set Default Text Sizes for Animation Plots | |||||
| #' | |||||
| #' Sets the default text sizes for the animated and static plots produced by | |||||
| #' this package during the current session. | |||||
| #' | |||||
| #' @param text_size Font size of value labels inside the data frame squares | |||||
| #' @param title_size Font size of the function call or plot title | |||||
| #' @export | |||||
| set_font_size <- function(text_size = NULL, title_size = NULL) { | |||||
| old <- list() | |||||
| if (!is.null(text_size)) old$text_size <- set_text_size(text_size) | |||||
| if (!is.null(title_size)) old$title_size <- set_title_size(title_size) | |||||
| invisible(old) | |||||
| } | |||||
| set_text_size <- function(size) { | |||||
| old <- plot_settings$text_size | |||||
| plot_settings$text_size <- size | |||||
| invisible(old) | |||||
| } | |||||
| set_title_size <- function(size) { | |||||
| old <- plot_settings$title_size | |||||
| plot_settings$title_size <- size | |||||
| invisible(old) | |||||
| } | |||||
| get_text_size <- function(x = NULL, default = 5) { | |||||
| if (!is.null(x)) return(x) | |||||
| plot_settings$text_size %||% | |||||
| getFromNamespace("theme_env", "ggplot2")$current$text$size %||% | |||||
| default | |||||
| } | |||||
| get_title_size <- function(x = NULL, default = 17) { | |||||
| if (!is.null(x)) return(x) | |||||
| plot_settings$title_size %||% | |||||
| getFromNamespace("theme_env", "ggplot2")$current$plot.title$size %||% | |||||
| default | |||||
| } | |||||
| "_PACKAGE" | "_PACKAGE" | ||||
| plot_settings <- new.env(parent = emptyenv()) | plot_settings <- new.env(parent = emptyenv()) | ||||
| plot_settings$default <- list( | |||||
| transition_length = 2, | |||||
| state_length = 1, | |||||
| ease_default = "sine-in-out", | |||||
| ease_other = NULL, | |||||
| enter = setNames(list(enter_fade()), "enter_fade()"), | |||||
| exit = setNames(list(exit_fade()), "exit_fade()"), | |||||
| text_family = "Fira Mono", | |||||
| title_family = "Fira Mono", | |||||
| text_size = 5, | |||||
| title_size = 17 | |||||
| ) | |||||
| % Generated by roxygen2: do not edit by hand | % Generated by roxygen2: do not edit by hand | ||||
| % Please edit documentation in R/plot_helpers.R | |||||
| % Please edit documentation in R/animate_options.R | |||||
| \name{anim_options} | \name{anim_options} | ||||
| \alias{anim_options} | \alias{anim_options} | ||||
| \alias{anim_options_set} | |||||
| \title{Animation Options} | \title{Animation Options} | ||||
| \usage{ | \usage{ | ||||
| anim_options(transition_length = 2, state_length = 1, | |||||
| ease_default = "sine-in-out", ease_other = NULL, | |||||
| enter = enter_fade(), exit = exit_fade(), | |||||
| text_family = "Fira Sans", title_family = "Fira Mono", | |||||
| anim_options(transition_length = NULL, state_length = NULL, | |||||
| ease_default = NULL, ease_other = NULL, enter = NULL, | |||||
| exit = NULL, text_family = NULL, title_family = NULL, | |||||
| text_size = NULL, title_size = NULL, ...) | text_size = NULL, title_size = NULL, ...) | ||||
| anim_options_set(anim_opts) | |||||
| } | } | ||||
| \arguments{ | \arguments{ | ||||
| \item{transition_length}{The relative length of the transition. Will be | \item{transition_length}{The relative length of the transition. Will be | ||||
| recycled to match the number of states in the data} | recycled to match the number of states in the data} | ||||
| \item{ease_default}{Default aes easing function. See \code{\link[tweenr:display_ease]{tweenr::display_ease()}} | \item{ease_default}{Default aes easing function. See \code{\link[tweenr:display_ease]{tweenr::display_ease()}} | ||||
| for more options.} | |||||
| for more options. The tidyexplain default value is \code{sine-in-out}.} | |||||
| \item{ease_other}{Additional aes easing options, specified as a named list. | \item{ease_other}{Additional aes easing options, specified as a named list. | ||||
| List entries are named with the aesthetic to which the easeing should be | List entries are named with the aesthetic to which the easeing should be | ||||
| applied, consistent with \code{\link[gganimate:ease_aes]{gganimate::ease_aes()}}. | |||||
| E.g. \code{list(color = "sine")}.} | |||||
| applied, consistent with \code{\link[gganimate:ease_aes]{gganimate::ease_aes()}}. E.g. \code{list(color = "sine")}.} | |||||
| \item{enter}{Enter fading function applied to objects in the animation. See | \item{enter}{Enter fading function applied to objects in the animation. See | ||||
| \link[gganimate:enter_exit]{gganimate::enter_exit} for a complete list of options.} | |||||
| \link[gganimate:enter_exit]{gganimate::enter_exit} for a complete list of options. The tidyexplain | |||||
| default is \code{\link[gganimate:enter_fade]{gganimate::enter_fade()}}.} | |||||
| \item{exit}{Exit fading function applied to objects in the animation. See | \item{exit}{Exit fading function applied to objects in the animation. See | ||||
| \link[gganimate:enter_exit]{gganimate::enter_exit} for a complete list of options.} | |||||
| \link[gganimate:enter_exit]{gganimate::enter_exit} for a complete list of options. The tidyexplain | |||||
| default is \code{\link[gganimate:exit_fade]{gganimate::exit_fade()}}.} | |||||
| \item{text_family}{Font family for the plot text, default is "Fira Mono". Use | |||||
| \code{\link[=set_font_size]{set_font_size()}} to set global default font sizes.} | |||||
| \item{text_family}{Font family for the plot text} | |||||
| \item{title_family}{Font family for the plot title, default is "Fira Mono". | |||||
| Use \code{\link[=set_font_size]{set_font_size()}} to set global default font sizes.} | |||||
| \item{title_family}{Font family for the plot title} | |||||
| \item{text_size}{Font size of the plot text, default is 5.} | |||||
| \item{text_size}{Font size of the plot text} | |||||
| \item{title_size}{Font size of the plot title, default is 17.} | |||||
| \item{title_size}{Font size of the plot title} | |||||
| \item{anim_opts}{An \code{\link[=anim_options]{anim_options()}} options list.} | |||||
| } | } | ||||
| \description{ | \description{ | ||||
| Helper function to set animation and plotting options to be passed to | Helper function to set animation and plotting options to be passed to | ||||
| \code{\link[=animate_plot]{animate_plot()}} and \code{\link[=static_plot]{static_plot()}}. | \code{\link[=animate_plot]{animate_plot()}} and \code{\link[=static_plot]{static_plot()}}. | ||||
| } | } | ||||
| \section{Functions}{ | |||||
| \itemize{ | |||||
| \item \code{anim_options_set}: Set default animation options for the current session. | |||||
| }} | |||||
| \title{Animates the gather function} | \title{Animates the gather function} | ||||
| \usage{ | \usage{ | ||||
| animate_gather(w, key, value, ..., export = "gif", detailed = TRUE, | animate_gather(w, key, value, ..., export = "gif", detailed = TRUE, | ||||
| anim_opts = anim_options()) | |||||
| anim_opts = NULL) | |||||
| } | } | ||||
| \arguments{ | \arguments{ | ||||
| \item{w}{a data_frame in the wide format} | \item{w}{a data_frame in the wide format} | ||||
| \item{detailed}{boolean value if the animation should show one step for each | \item{detailed}{boolean value if the animation should show one step for each | ||||
| key value} | key value} | ||||
| \item{anim_opts}{An \code{\link[=anim_options]{anim_options()}} options list.} | |||||
| } | } | ||||
| \value{ | \value{ | ||||
| a gif or a ggplot | a gif or a ggplot |
| % Please edit documentation in R/plot_helpers.R | % Please edit documentation in R/plot_helpers.R | ||||
| \name{animate_plot} | \name{animate_plot} | ||||
| \alias{animate_plot} | \alias{animate_plot} | ||||
| \title{Animates a plot} | |||||
| \title{Animation Options} | |||||
| \usage{ | \usage{ | ||||
| animate_plot(d, title = "", ..., anim_opts = anim_options(...)) | animate_plot(d, title = "", ..., anim_opts = anim_options(...)) | ||||
| } | } | ||||
| a \code{gganim} object | a \code{gganim} object | ||||
| } | } | ||||
| \description{ | \description{ | ||||
| Animates a plot | |||||
| Animation Options | |||||
| } | } | ||||
| \examples{ | \examples{ | ||||
| NULL | NULL |
| \title{Animates the spread function} | \title{Animates the spread function} | ||||
| \usage{ | \usage{ | ||||
| animate_spread(l, key, value, export = "gif", detailed = TRUE, ..., | animate_spread(l, key, value, export = "gif", detailed = TRUE, ..., | ||||
| anim_opts = anim_options()) | |||||
| anim_opts = NULL) | |||||
| } | } | ||||
| \arguments{ | \arguments{ | ||||
| \item{l}{a data_frame in the long/tidy format} | \item{l}{a data_frame in the long/tidy format} | ||||
| key value} | key value} | ||||
| \item{...}{further arguments passed to \link{process_long} or \link{process_wide}} | \item{...}{further arguments passed to \link{process_long} or \link{process_wide}} | ||||
| \item{anim_opts}{An \code{\link[=anim_options]{anim_options()}} options list.} | |||||
| } | } | ||||
| \value{ | \value{ | ||||
| a ggplot or a gif | a ggplot or a gif |
| % Generated by roxygen2: do not edit by hand | % Generated by roxygen2: do not edit by hand | ||||
| % Please edit documentation in R/plot_helpers.R | |||||
| % Please edit documentation in R/animate_options.R | |||||
| \name{set_font_size} | \name{set_font_size} | ||||
| \alias{set_font_size} | \alias{set_font_size} | ||||
| \alias{get_font_size} | |||||
| \title{Set Default Text Sizes for Animation Plots} | \title{Set Default Text Sizes for Animation Plots} | ||||
| \usage{ | \usage{ | ||||
| set_font_size(text_size = NULL, title_size = NULL) | set_font_size(text_size = NULL, title_size = NULL) | ||||
| get_font_size() | |||||
| } | } | ||||
| \arguments{ | \arguments{ | ||||
| \item{text_size}{Font size of value labels inside the data frame squares} | \item{text_size}{Font size of value labels inside the data frame squares} | ||||
| Sets the default text sizes for the animated and static plots produced by | Sets the default text sizes for the animated and static plots produced by | ||||
| this package during the current session. | this package during the current session. | ||||
| } | } | ||||
| \section{Functions}{ | |||||
| \itemize{ | |||||
| \item \code{get_font_size}: Get current global font sizes | |||||
| }} | |||||
| \item{...}{Arguments passed on to \code{anim_options} | \item{...}{Arguments passed on to \code{anim_options} | ||||
| \describe{ | \describe{ | ||||
| \item{text_family}{Font family for the plot text} | |||||
| \item{title_family}{Font family for the plot title} | |||||
| \item{text_size}{Font size of the plot text} | |||||
| \item{title_size}{Font size of the plot title} | |||||
| \item{text_family}{Font family for the plot text, default is "Fira Mono". Use | |||||
| \code{\link[=set_font_size]{set_font_size()}} to set global default font sizes.} | |||||
| \item{title_family}{Font family for the plot title, default is "Fira Mono". | |||||
| Use \code{\link[=set_font_size]{set_font_size()}} to set global default font sizes.} | |||||
| \item{text_size}{Font size of the plot text, default is 5.} | |||||
| \item{title_size}{Font size of the plot title, default is 17.} | |||||
| \item{ease_default}{Default aes easing function. See \code{\link[tweenr:display_ease]{tweenr::display_ease()}} | \item{ease_default}{Default aes easing function. See \code{\link[tweenr:display_ease]{tweenr::display_ease()}} | ||||
| for more options.} | |||||
| for more options. The tidyexplain default value is \code{sine-in-out}.} | |||||
| \item{ease_other}{Additional aes easing options, specified as a named list. | \item{ease_other}{Additional aes easing options, specified as a named list. | ||||
| List entries are named with the aesthetic to which the easeing should be | List entries are named with the aesthetic to which the easeing should be | ||||
| applied, consistent with \code{\link[gganimate:ease_aes]{gganimate::ease_aes()}}. | |||||
| E.g. \code{list(color = "sine")}.} | |||||
| applied, consistent with \code{\link[gganimate:ease_aes]{gganimate::ease_aes()}}. E.g. \code{list(color = "sine")}.} | |||||
| \item{enter}{Enter fading function applied to objects in the animation. See | \item{enter}{Enter fading function applied to objects in the animation. See | ||||
| \link[gganimate:enter_exit]{gganimate::enter_exit} for a complete list of options.} | |||||
| \link[gganimate:enter_exit]{gganimate::enter_exit} for a complete list of options. The tidyexplain | |||||
| default is \code{\link[gganimate:enter_fade]{gganimate::enter_fade()}}.} | |||||
| \item{exit}{Exit fading function applied to objects in the animation. See | \item{exit}{Exit fading function applied to objects in the animation. See | ||||
| \link[gganimate:enter_exit]{gganimate::enter_exit} for a complete list of options.} | |||||
| \link[gganimate:enter_exit]{gganimate::enter_exit} for a complete list of options. The tidyexplain | |||||
| default is \code{\link[gganimate:exit_fade]{gganimate::exit_fade()}}.} | |||||
| \item{transition_length}{The relative length of the transition. Will be | \item{transition_length}{The relative length of the transition. Will be | ||||
| recycled to match the number of states in the data} | recycled to match the number of states in the data} | ||||
| \item{state_length}{The relative length of the pause at the states. Will be | \item{state_length}{The relative length of the pause at the states. Will be |
| context("test-anim_options") | |||||
| test_that("merging of animation options works", { | |||||
| ao_new <- anim_options(5, 3, text_size = 9, title_size = 13) | |||||
| ao_old <- anim_options(ease_default = "cubic-in", text_family = "Times New Roman") | |||||
| ao_merged <- anim_options(5, 3, "cubic-in", text_size = 9, title_size = 13, text_family = "Times New Roman") | |||||
| expect_equal(merge(ao_new, ao_old), ao_merged) | |||||
| }) | |||||
| test_that("setting and getting animation options works", { | |||||
| set_font_size(5, 10) | |||||
| expect_equal(get_anim_opt(), anim_options(text_size = 5, title_size = 10)) | |||||
| expect_error(get_anim_opt("text_size")) | |||||
| expect_equal(get_text_size(), get_anim_opt()$text_size) | |||||
| anim_options_set(anim_options(2, 1)) | |||||
| expect_equal(get_anim_opt("transition_length"), 2) | |||||
| expect_equal(get_anim_opt("state_length"), 1) | |||||
| expect_equal(get_anim_opt(), anim_options(2, 1, text_size = 5, title_size = 10)) | |||||
| anim_options_set(anim_options()) | |||||
| expect_equal(get_anim_opt("transition_length"), plot_settings$default$transition_length) | |||||
| anim_options_set(anim_options(enter = enter_appear(early = TRUE))) | |||||
| expect_equal(names(get_anim_opt("enter")), "enter_appear(early = TRUE)") | |||||
| expect_s3_class(get_anim_opt("enter")[[1]], "ggproto") | |||||
| }) |