| @@ -16,6 +16,8 @@ | |||
| #' 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 cell_width Width of a cell, default is 1. | |||
| #' @param cell_height Height of a cell, default is 1. | |||
| #' @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. | |||
| @@ -46,6 +48,8 @@ anim_options <- function( | |||
| color_missing = NULL, | |||
| color_fun = NULL, | |||
| text_color = NULL, | |||
| cell_width = NULL, | |||
| cell_height = NULL, | |||
| ... | |||
| ){ | |||
| enter_name <- if (!missing(enter)) rlang::quo_name(rlang::enquo(enter)) | |||
| @@ -66,6 +70,8 @@ anim_options <- function( | |||
| color_missing = color_missing, | |||
| color_fun = color_fun, | |||
| text_color = text_color, | |||
| cell_width = cell_width, | |||
| cell_height = cell_height, | |||
| ... | |||
| ) | |||
| ao <- purrr::compact(ao) | |||
| @@ -129,6 +135,8 @@ fill_anim_opts <- function(ao) { | |||
| ao$color_missing <- ao$color_missing %||% get_anim_opt("color_missing") | |||
| ao$color_fun <- ao$color_fun %||% get_anim_opt("color_fun") | |||
| ao$text_color <- ao$text_color %||% get_anim_opt("text_color") | |||
| ao$cell_width <- ao$cell_width %||% get_anim_opt("cell_width") | |||
| ao$cell_height <- ao$cell_height %||% get_anim_opt("cell_height") | |||
| ao | |||
| } | |||
| @@ -58,8 +58,12 @@ static_plot <- function( | |||
| d <- d %>% mutate(.item_id = .id) | |||
| } | |||
| ggplot(d, aes(x = .x, y = .y, fill = .color, alpha = .alpha, group = .item_id)) + | |||
| geom_tile(width = 0.9, height = 0.9) + | |||
| width <- ao$cell_width %||% 1 | |||
| height <- ao$cell_height %||% 1 | |||
| ggplot(d, aes(x = .x * width, y = .y * height, fill = .color, alpha = .alpha, | |||
| group = .item_id)) + | |||
| geom_tile(width = 0.9 * width, height = 0.9 * height) + | |||
| coord_equal() + | |||
| geom_text(data = d %>% filter(!is.na(.val)), aes(label = .val, color = .textcolor), | |||
| family = ao$text_family, size = text_size) + | |||
| @@ -20,6 +20,8 @@ plot_settings$default <- list( | |||
| color_other = "#d0d0d0", | |||
| color_missing = "#ffffff", | |||
| color_fun = scales::brewer_pal(type = "qual", "Set1"), | |||
| text_color = NA | |||
| text_color = NA, | |||
| cell_width = 1, | |||
| cell_height = 1 | |||
| ) | |||
| @@ -10,7 +10,7 @@ anim_options(transition_length = NULL, state_length = NULL, | |||
| exit = NULL, text_family = NULL, title_family = NULL, | |||
| text_size = NULL, title_size = NULL, color_header = NULL, | |||
| color_other = NULL, color_missing = NULL, color_fun = NULL, | |||
| text_color = NULL, ...) | |||
| text_color = NULL, cell_width = NULL, cell_height = NULL, ...) | |||
| set_anim_options(anim_opts = anim_options()) | |||
| } | |||
| @@ -58,6 +58,10 @@ cells, default is \code{\link[scales:brewer_pal]{scales::brewer_pal()}} Set1.} | |||
| \item{text_color}{Color of the text of the cells, default is a black or | |||
| white, based on the background color of the cell.} | |||
| \item{cell_width}{Width of a cell, default is 1.} | |||
| \item{cell_height}{Height of a cell, default is 1.} | |||
| \item{anim_opts}{An \code{\link[=anim_options]{anim_options()}} options list.} | |||
| } | |||
| \description{ | |||
| @@ -26,6 +26,8 @@ white, based on the background color of the cell.} | |||
| 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{cell_width}{Width of a cell, default is 1.} | |||
| \item{cell_height}{Height of a cell, default is 1.} | |||
| \item{ease_default}{Default aes easing function. See \code{\link[tweenr:display_ease]{tweenr::display_ease()}} | |||
| for more options. The tidyexplain default value is \code{sine-in-out}.} | |||
| \item{ease_other}{Additional aes easing options, specified as a named list. | |||