Quellcode durchsuchen

added color functionality to anim_options

before the additional arguments such as color_header  = "black" would trigger a warning that the argument is not recognised. Now the color arguments passed to add_color_join
pkg
David vor 7 Jahren
Ursprung
Commit
b3d249e9a1
12 geänderte Dateien mit 85 neuen und 28 gelöschten Zeilen
  1. +2
    -2
      R/animate_joins.R
  2. +23
    -0
      R/animate_options.R
  3. +1
    -2
      R/animate_sets.R
  4. +18
    -10
      R/process_data_helpers.R
  5. +6
    -1
      R/zzzz-package.R
  6. +3
    -6
      man/add_color_join.Rd
  7. +15
    -1
      man/anim_options.Rd
  8. +2
    -2
      man/animate_join.Rd
  9. +1
    -2
      man/animate_set.Rd
  10. +4
    -1
      man/process_data_join.Rd
  11. +3
    -1
      man/process_join.Rd
  12. +7
    -0
      man/static_plot.Rd

+ 2
- 2
R/animate_joins.R Datei anzeigen

@@ -8,7 +8,7 @@
#' @param by the by arguments for the join
#' @param export the export type, either gif, first or last. The latter two
#' export ggplots of the first/last state of the join
#' @param ... further arguments passed to static_plot
#' @param ... further arguments passed to anim_options()
#'
#' @return either a gif or a ggplot
#'
@@ -37,7 +37,7 @@
#' animate_semi_join(x, y, by = "id")
#' animate_anti_join(x, y, by = "id")
#'
#' # further arguments can be passed to all animate_* functions
#' # further arguments can be passed to all animate_* functions, see also ?anim_options
#' animate_full_join(
#' x, y, by = "id", export = "last",
#' text_size = 5, title_size = 25,

+ 23
- 0
R/animate_options.R Datei anzeigen

@@ -3,6 +3,13 @@
#' Helper function to set animation and plotting options to be passed to
#' [animate_plot()] and [static_plot()].
#'
#' @param color_header Color of the header row.
#' @param color_other Color of the cells that are not highlighted otherwise.
#' @param color_missing Color of the missing cells.
#' @param color_fun A function that generates the colors for the highlighted
#' cells, default is [scales::brewer_pal()] Set1.
#' @param text_color Color of the text of the cells, default is a black or
#' white, based on the background color of the cell.
#' @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".
@@ -34,6 +41,11 @@ anim_options <- function(
title_family = NULL,
text_size = NULL,
title_size = NULL,
color_header = NULL,
color_other = NULL,
color_missing = NULL,
color_fun = NULL,
text_color = NULL,
...
){
enter_name <- if (!missing(enter)) rlang::quo_name(rlang::enquo(enter))
@@ -49,6 +61,11 @@ anim_options <- function(
text_size = text_size,
title_family = title_family,
title_size = title_size,
color_header = color_header,
color_other = color_other,
color_missing = color_missing,
color_fun = color_fun,
text_color = text_color,
...
)
ao <- purrr::compact(ao)
@@ -107,6 +124,12 @@ fill_anim_opts <- function(ao) {
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$color_header <- ao$color_header %||% get_anim_opt("color_header")
ao$color_other <- ao$color_other %||% get_anim_opt("color_other")
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
}


+ 1
- 2
R/animate_sets.R Datei anzeigen

@@ -8,7 +8,7 @@
#' @param export the export type, either gif, first or last. The latter two
#' export ggplots of the first/last state of the join
#' @param type type of the set, i.e., intersect, setdiff, etc.
#' @param ... further argument passed to static_plot
#' @param ... further argument passed to anim_options()
#'
#' @return either a gif or a ggplot
#'
@@ -39,7 +39,6 @@
#' x, y,
#' text_size = 5, title_size = 25,
#' color_header = "black",
#' color_other = "lightblue",
#' color_fun = viridis::viridis
#' )
#' }

+ 18
- 10
R/process_data_helpers.R Datei anzeigen

@@ -6,12 +6,14 @@
#' @param by a by argument for joins / set operations
#' @param fill if missing ids should be filled
#' @param ... further arguments passed to add_color
#' @param ao anim_options()
#'
#' @return a preprocessed dataset
#'
#' @examples
#' NULL
process_join <- function(x, y, by, fill = TRUE, ...) {
process_join <- function(x, y, by, fill = TRUE, ...,
ao = anim_options(...)) {

#' test for
#' a <- c("unique", "mult", "mult", "also unique")
@@ -34,8 +36,8 @@ process_join <- function(x, y, by, fill = TRUE, ...) {
ids <- dplyr::union(x %>% dplyr::select(.id, .id_long),
y %>% dplyr::select(.id, .id_long))

x_ <- process_data_join(x, ids, by, fill = fill, ...)
y_ <- process_data_join(y, ids, by, fill = fill, ...) %>%
x_ <- process_data_join(x, ids, by, fill = fill, ao = ao)
y_ <- process_data_join(y, ids, by, fill = fill, ao = ao) %>%
mutate(.x = .x + ncol(x) - 1)

list(x = x_, y = y_)
@@ -51,12 +53,15 @@ process_join <- function(x, y, by, fill = TRUE, ...) {
#' @param side the side (x or y, lhs or rhs, etc)
#' @param fill if missing ids should be filled
#' @param ... further arguments passed to add_color
#' @param ao anim_options
#'
#' @return a data_frame including all necessary information
#'
#' @examples
#' NULL
process_data_join <- function(x, ids, by, width = 1, side = NA, fill = TRUE, ...) {
process_data_join <- function(x, ids, by, width = 1, side = NA, fill = TRUE,
...,
ao = anim_options(...)) {
if (is.na(side)) side <- deparse(substitute(x))

x_names <- names(x)[grepl("^[^\\.]", names(x))]
@@ -102,7 +107,7 @@ process_data_join <- function(x, ids, by, width = 1, side = NA, fill = TRUE, ...
}
}

add_color_join(x, rev(ids$.id), by, ...)
add_color_join(x, rev(ids$.id), by, ao)
}

#' Adds Color to a processed data_frame
@@ -122,11 +127,14 @@ process_data_join <- function(x, ids, by, width = 1, side = NA, fill = TRUE, ...
#'
#' @examples
#' NULL
add_color_join <- function(x, ids, by,
color_header = "#737373", color_other = "#d0d0d0",
color_missing = "#ffffff",
color_fun = scales::brewer_pal(type = "qual", "Set1"),
text_color = NA, ...) {
add_color_join <- function(x, ids, by, ao, ...) {

color_header <- ao$color_header %||% get_anim_opt("color_header")
color_other <- ao$color_other %||% get_anim_opt("color_other")
color_missing <- ao$color_missing %||% get_anim_opt("color_missing")
color_fun <- ao$color_fun %||% get_anim_opt("color_fun")
text_color <- ao$text_color %||% get_anim_opt("text_color")

colors <- c(color_header, color_fun(length(ids)))
names(colors) <- c(".header", ids)


+ 6
- 1
R/zzzz-package.R Datei anzeigen

@@ -15,6 +15,11 @@ plot_settings$default <- list(
text_family = "Fira Mono",
title_family = "Fira Mono",
text_size = 5,
title_size = 17
title_size = 17,
color_header = "#737373",
color_other = "#d0d0d0",
color_missing = "#ffffff",
color_fun = scales::brewer_pal(type = "qual", "Set1"),
text_color = NA
)


+ 3
- 6
man/add_color_join.Rd Datei anzeigen

@@ -4,10 +4,7 @@
\alias{add_color_join}
\title{Adds Color to a processed data_frame}
\usage{
add_color_join(x, ids, by, color_header = "#737373",
color_other = "#d0d0d0", color_missing = "#ffffff",
color_fun = scales::brewer_pal(type = "qual", "Set1"),
text_color = NA, ...)
add_color_join(x, ids, by, ao, ...)
}
\arguments{
\item{x}{a processed data_frame}
@@ -16,6 +13,8 @@ add_color_join(x, ids, by, color_header = "#737373",

\item{by}{a vector of column names that constitute the by-argument of joins/sets}

\item{...}{}

\item{color_header}{color for the header}

\item{color_other}{color for "inactive" values}
@@ -26,8 +25,6 @@ add_color_join(x, ids, by, color_header = "#737373",

\item{text_color}{the color for the text inside the tiles,
defaults to white/black depending on tile color}

\item{...}{}
}
\value{
the processed data_frame with a new column .color

+ 15
- 1
man/anim_options.Rd Datei anzeigen

@@ -8,7 +8,9 @@
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, color_header = NULL,
color_other = NULL, color_missing = NULL, color_fun = NULL,
text_color = NULL, ...)

anim_options_set(anim_opts = anim_options())
}
@@ -44,6 +46,18 @@ Use \code{\link[=set_font_size]{set_font_size()}} to set global default font siz

\item{title_size}{Font size of the plot title, default is 17.}

\item{color_header}{Color of the header row.}

\item{color_other}{Color of the cells that are not highlighted otherwise.}

\item{color_missing}{Color of the missing cells.}

\item{color_fun}{A function that generates the colors for the highlighted
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{anim_opts}{An \code{\link[=anim_options]{anim_options()}} options list.}
}
\description{

+ 2
- 2
man/animate_join.Rd Datei anzeigen

@@ -36,7 +36,7 @@ animate_anti_join(x, y, by, export = "gif", ...)
\item{export}{the export type, either gif, first or last. The latter two
export ggplots of the first/last state of the join}

\item{...}{further arguments passed to static_plot}
\item{...}{further arguments passed to anim_options()}
}
\value{
either a gif or a ggplot
@@ -67,7 +67,7 @@ animate_right_join(x, y, by = "id")
animate_semi_join(x, y, by = "id")
animate_anti_join(x, y, by = "id")

# further arguments can be passed to all animate_* functions
# further arguments can be passed to all animate_* functions, see also ?anim_options
animate_full_join(
x, y, by = "id", export = "last",
text_size = 5, title_size = 25,

+ 1
- 2
man/animate_set.Rd Datei anzeigen

@@ -29,7 +29,7 @@ animate_setdiff(x, y, export = "gif", ...)
\item{export}{the export type, either gif, first or last. The latter two
export ggplots of the first/last state of the join}

\item{...}{further argument passed to static_plot}
\item{...}{further argument passed to anim_options()}
}
\value{
either a gif or a ggplot
@@ -63,7 +63,6 @@ animate_union(
x, y,
text_size = 5, title_size = 25,
color_header = "black",
color_other = "lightblue",
color_fun = viridis::viridis
)
}

+ 4
- 1
man/process_data_join.Rd Datei anzeigen

@@ -4,7 +4,8 @@
\alias{process_data_join}
\title{Processes the data}
\usage{
process_data_join(x, ids, by, width = 1, side = NA, fill = TRUE, ...)
process_data_join(x, ids, by, width = 1, side = NA, fill = TRUE, ...,
ao = anim_options(...))
}
\arguments{
\item{x}{a preprocessed dataset}
@@ -20,6 +21,8 @@ process_data_join(x, ids, by, width = 1, side = NA, fill = TRUE, ...)
\item{fill}{if missing ids should be filled}

\item{...}{further arguments passed to add_color}

\item{ao}{anim_options}
}
\value{
a data_frame including all necessary information

+ 3
- 1
man/process_join.Rd Datei anzeigen

@@ -4,7 +4,7 @@
\alias{process_join}
\title{Preprocess data}
\usage{
process_join(x, y, by, fill = TRUE, ...)
process_join(x, y, by, fill = TRUE, ..., ao = anim_options(...))
}
\arguments{
\item{x}{a left dataset}
@@ -16,6 +16,8 @@ process_join(x, y, by, fill = TRUE, ...)
\item{fill}{if missing ids should be filled}

\item{...}{further arguments passed to add_color}

\item{ao}{anim_options()}
}
\value{
a preprocessed dataset

+ 7
- 0
man/static_plot.Rd Datei anzeigen

@@ -13,6 +13,13 @@ static_plot(d, title = "", ..., anim_opts = anim_options(...))

\item{...}{Arguments passed on to \code{anim_options}
\describe{
\item{color_header}{Color of the header row.}
\item{color_other}{Color of the cells that are not highlighted otherwise.}
\item{color_missing}{Color of the missing cells.}
\item{color_fun}{A function that generates the colors for the highlighted
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{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".

Laden…
Abbrechen
Speichern