Просмотр исходного кода

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 7 лет назад
Родитель
Сommit
b3d249e9a1
12 измененных файлов: 85 добавлений и 28 удалений
  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 Просмотреть файл

#' @param by the by arguments for the join #' @param by the by arguments for the join
#' @param export the export type, either gif, first or last. The latter two #' @param export the export type, either gif, first or last. The latter two
#' export ggplots of the first/last state of the join #' 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 #' @return either a gif or a ggplot
#' #'
#' animate_semi_join(x, y, by = "id") #' animate_semi_join(x, y, by = "id")
#' animate_anti_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( #' animate_full_join(
#' x, y, by = "id", export = "last", #' x, y, by = "id", export = "last",
#' text_size = 5, title_size = 25, #' text_size = 5, title_size = 25,

+ 23
- 0
R/animate_options.R Просмотреть файл

#' Helper function to set animation and plotting options to be passed to #' Helper function to set animation and plotting options to be passed to
#' [animate_plot()] and [static_plot()]. #' [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 #' @param text_family Font family for the plot text, default is "Fira Mono". Use
#' [set_font_size()] to set global default font sizes. #' [set_font_size()] to set global default font sizes.
#' @param title_family Font family for the plot title, default is "Fira Mono". #' @param title_family Font family for the plot title, default is "Fira Mono".
title_family = NULL, title_family = NULL,
text_size = NULL, text_size = NULL,
title_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)) enter_name <- if (!missing(enter)) rlang::quo_name(rlang::enquo(enter))
text_size = text_size, text_size = text_size,
title_family = title_family, title_family = title_family,
title_size = title_size, 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) ao <- purrr::compact(ao)
ao$exit <- ao$exit %||% get_anim_opt("exit") ao$exit <- ao$exit %||% get_anim_opt("exit")
ao$text_family <- ao$text_family %||% get_anim_opt("text_family") ao$text_family <- ao$text_family %||% get_anim_opt("text_family")
ao$title_family <- ao$title_family %||% get_anim_opt("title_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 ao
} }



+ 1
- 2
R/animate_sets.R Просмотреть файл

#' @param export the export type, either gif, first or last. The latter two #' @param export the export type, either gif, first or last. The latter two
#' export ggplots of the first/last state of the join #' export ggplots of the first/last state of the join
#' @param type type of the set, i.e., intersect, setdiff, etc. #' @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 #' @return either a gif or a ggplot
#' #'
#' x, y, #' x, y,
#' text_size = 5, title_size = 25, #' text_size = 5, title_size = 25,
#' color_header = "black", #' color_header = "black",
#' color_other = "lightblue",
#' color_fun = viridis::viridis #' color_fun = viridis::viridis
#' ) #' )
#' } #' }

+ 18
- 10
R/process_data_helpers.R Просмотреть файл

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


#' test for #' test for
#' a <- c("unique", "mult", "mult", "also unique") #' a <- c("unique", "mult", "mult", "also unique")
ids <- dplyr::union(x %>% dplyr::select(.id, .id_long), ids <- dplyr::union(x %>% dplyr::select(.id, .id_long),
y %>% 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) mutate(.x = .x + ncol(x) - 1)


list(x = x_, y = y_) list(x = x_, y = y_)
#' @param side the side (x or y, lhs or rhs, etc) #' @param side the side (x or y, lhs or rhs, etc)
#' @param fill if missing ids should be filled #' @param fill if missing ids should be filled
#' @param ... further arguments passed to add_color #' @param ... further arguments passed to add_color
#' @param ao anim_options
#' #'
#' @return a data_frame including all necessary information #' @return a data_frame including all necessary information
#' #'
#' @examples #' @examples
#' NULL #' 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)) if (is.na(side)) side <- deparse(substitute(x))


x_names <- names(x)[grepl("^[^\\.]", names(x))] x_names <- names(x)[grepl("^[^\\.]", names(x))]
} }
} }


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


#' Adds Color to a processed data_frame #' Adds Color to a processed data_frame
#' #'
#' @examples #' @examples
#' NULL #' 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))) colors <- c(color_header, color_fun(length(ids)))
names(colors) <- c(".header", ids) names(colors) <- c(".header", ids)



+ 6
- 1
R/zzzz-package.R Просмотреть файл

text_family = "Fira Mono", text_family = "Fira Mono",
title_family = "Fira Mono", title_family = "Fira Mono",
text_size = 5, 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 Просмотреть файл

\alias{add_color_join} \alias{add_color_join}
\title{Adds Color to a processed data_frame} \title{Adds Color to a processed data_frame}
\usage{ \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{ \arguments{
\item{x}{a processed data_frame} \item{x}{a processed data_frame}


\item{by}{a vector of column names that constitute the by-argument of joins/sets} \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_header}{color for the header}


\item{color_other}{color for "inactive" values} \item{color_other}{color for "inactive" values}


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

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

+ 15
- 1
man/anim_options.Rd Просмотреть файл

anim_options(transition_length = NULL, state_length = NULL, anim_options(transition_length = NULL, state_length = NULL,
ease_default = NULL, ease_other = NULL, enter = NULL, ease_default = NULL, ease_other = NULL, enter = NULL,
exit = NULL, text_family = NULL, title_family = 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()) anim_options_set(anim_opts = anim_options())
} }


\item{title_size}{Font size of the plot title, default is 17.} \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.} \item{anim_opts}{An \code{\link[=anim_options]{anim_options()}} options list.}
} }
\description{ \description{

+ 2
- 2
man/animate_join.Rd Просмотреть файл

\item{export}{the export type, either gif, first or last. The latter two \item{export}{the export type, either gif, first or last. The latter two
export ggplots of the first/last state of the join} 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{ \value{
either a gif or a ggplot either a gif or a ggplot
animate_semi_join(x, y, by = "id") animate_semi_join(x, y, by = "id")
animate_anti_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( animate_full_join(
x, y, by = "id", export = "last", x, y, by = "id", export = "last",
text_size = 5, title_size = 25, text_size = 5, title_size = 25,

+ 1
- 2
man/animate_set.Rd Просмотреть файл

\item{export}{the export type, either gif, first or last. The latter two \item{export}{the export type, either gif, first or last. The latter two
export ggplots of the first/last state of the join} 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{ \value{
either a gif or a ggplot either a gif or a ggplot
x, y, x, y,
text_size = 5, title_size = 25, text_size = 5, title_size = 25,
color_header = "black", color_header = "black",
color_other = "lightblue",
color_fun = viridis::viridis color_fun = viridis::viridis
) )
} }

+ 4
- 1
man/process_data_join.Rd Просмотреть файл

\alias{process_data_join} \alias{process_data_join}
\title{Processes the data} \title{Processes the data}
\usage{ \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{ \arguments{
\item{x}{a preprocessed dataset} \item{x}{a preprocessed dataset}
\item{fill}{if missing ids should be filled} \item{fill}{if missing ids should be filled}


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

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

+ 3
- 1
man/process_join.Rd Просмотреть файл

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


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

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

+ 7
- 0
man/static_plot.Rd Просмотреть файл



\item{...}{Arguments passed on to \code{anim_options} \item{...}{Arguments passed on to \code{anim_options}
\describe{ \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 \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.} \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". \item{title_family}{Font family for the plot title, default is "Fira Mono".

Загрузка…
Отмена
Сохранить