Currently only used for setting global text and title font sizes, but can be extended to other options that we may wish to set for more than one plot. For fonts, we now provide `set_font_size()` that can be used to set text and title sizes across all subsequent animations. Includes internal getter functions get_{text|title}_size().
pull/18/merge
| export(animate_spread) | export(animate_spread) | ||||
| export(animate_union) | export(animate_union) | ||||
| export(animate_union_all) | export(animate_union_all) | ||||
| export(set_font_size) | |||||
| importFrom(dplyr,anti_join) | importFrom(dplyr,anti_join) | ||||
| importFrom(dplyr,arrange) | importFrom(dplyr,arrange) | ||||
| importFrom(dplyr,bind_cols) | importFrom(dplyr,bind_cols) |
| #' | #' | ||||
| #' @examples | #' @examples | ||||
| #' NULL | #' NULL | ||||
| static_plot <- function(d, title = "", | |||||
| text_family = "Fira Sans", title_family = "Fira Mono", | |||||
| text_size = 5, title_size = 17, ...) { | |||||
| static_plot <- function( | |||||
| d, | |||||
| title = "", | |||||
| text_family = "Fira Sans", title_family = "Fira Mono", | |||||
| text_size = NULL, title_size = NULL, | |||||
| ... | |||||
| ) { | |||||
| text_size <- get_text_size(text_size, default = 5) | |||||
| title_size <- get_title_size(title_size, default = 17) | |||||
| 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(plot.title = element_text(family = title_family, hjust = 0.5, size = title_size)) | theme(plot.title = element_text(family = 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 | |||||
| } | |||||
| `%||%` <- function(x, y) if (is.null(x)) y else x | |||||
| set_text_color <- function(x, black = "#000000", white = "#FFFFFF") { | set_text_color <- function(x, black = "#000000", white = "#FFFFFF") { | ||||
| # x = color_hex | # x = color_hex | ||||
| color_rgb <- col2rgb(x) | color_rgb <- col2rgb(x) |
| #' @importFrom dplyr mutate select filter arrange bind_rows bind_cols group_by pull slice data_frame row_number | #' @importFrom dplyr mutate select filter arrange bind_rows bind_cols group_by pull slice data_frame row_number | ||||
| #' @keywords internal | #' @keywords internal | ||||
| "_PACKAGE" | "_PACKAGE" | ||||
| plot_settings <- new.env(parent = emptyenv()) |
| % Generated by roxygen2: do not edit by hand | |||||
| % Please edit documentation in R/plot_helpers.R | |||||
| \name{set_font_size} | |||||
| \alias{set_font_size} | |||||
| \title{Set Default Text Sizes for Animation Plots} | |||||
| \usage{ | |||||
| set_font_size(text_size = NULL, title_size = NULL) | |||||
| } | |||||
| \arguments{ | |||||
| \item{text_size}{Font size of value labels inside the data frame squares} | |||||
| \item{title_size}{Font size of the function call or plot title} | |||||
| } | |||||
| \description{ | |||||
| Sets the default text sizes for the animated and static plots produced by | |||||
| this package during the current session. | |||||
| } |
| \title{Prints the tiles for a processed dataset statically} | \title{Prints the tiles for a processed dataset statically} | ||||
| \usage{ | \usage{ | ||||
| static_plot(d, title = "", text_family = "Fira Sans", | static_plot(d, title = "", text_family = "Fira Sans", | ||||
| title_family = "Fira Mono", text_size = 5, title_size = 17, ...) | |||||
| title_family = "Fira Mono", text_size = NULL, title_size = NULL, | |||||
| ...) | |||||
| } | } | ||||
| \arguments{ | \arguments{ | ||||
| \item{d}{a processed dataset} | \item{d}{a processed dataset} |