From 829586588f384c76f6a6d1af9c1d21fc60fab8f5 Mon Sep 17 00:00:00 2001 From: Sherry Zhang Date: Fri, 7 Jan 2022 23:18:00 +1100 Subject: [PATCH 1/7] use cubble::geom_glyph as backend for glyph related functions --- DESCRIPTION | 4 +- NAMESPACE | 12 +- R/gglyph.R | 280 ++++++++++++------------------------------ man/GGally-package.Rd | 7 +- man/add_ref_boxes.Rd | 31 ----- man/add_ref_lines.Rd | 20 --- man/ggcoef_model.Rd | 26 ---- man/glyphplot.Rd | 6 +- man/glyphs.Rd | 6 +- man/rescale01.Rd | 31 ----- 10 files changed, 95 insertions(+), 328 deletions(-) delete mode 100644 man/add_ref_boxes.Rd delete mode 100644 man/add_ref_lines.Rd delete mode 100644 man/rescale01.Rd diff --git a/DESCRIPTION b/DESCRIPTION index 62c1c9288..3d1168c7b 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -69,8 +69,10 @@ Suggests: knitr, spelling, emmeans +Remotes: + huizezhang-sherry/cubble Roxygen: list(markdown = TRUE) -RoxygenNote: 7.1.1 +RoxygenNote: 7.1.2 SystemRequirements: openssl Encoding: UTF-8 Language: en-US diff --git a/NAMESPACE b/NAMESPACE index 38b99b565..8b1fe7f1c 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -6,16 +6,14 @@ S3method("[",glyphplot) S3method("[<-",ggmatrix) S3method(grid.draw,ggmatrix) S3method(print,ggmatrix) -S3method(print,glyphplot) S3method(print,legend_guide_box) S3method(str,ggmatrix) +S3method(tbl_sum,glyphplot) export("%>%") export(StatCross) export(StatGGallyCount) export(StatProp) export(StatWeightedMean) -export(add_ref_boxes) -export(add_ref_lines) export(add_to_ggmatrix) export(brew_colors) export(broomify) @@ -103,18 +101,12 @@ export(lowertriangle) export(mapping_color_to_fill) export(mapping_string) export(mapping_swap_x_y) -export(max1) -export(mean0) -export(min0) export(model_beta_label) export(model_beta_variables) export(model_response_variables) export(print_if_interactive) export(putPlot) -export(range01) export(remove_color_unless_equal) -export(rescale01) -export(rescale11) export(scatmat) export(signif_stars) export(stat_cross) @@ -134,6 +126,7 @@ import(RColorBrewer) import(ggplot2) import(plyr) import(utils) +importFrom(cubble,geom_glyph) importFrom(dplyr,"%>%") importFrom(grDevices,colorRampPalette) importFrom(grDevices,gray.colors) @@ -169,6 +162,7 @@ importFrom(stats,spline) importFrom(stats,symnum) importFrom(stats,terms) importFrom(stats,time) +importFrom(tibble,tbl_sum) importFrom(utils,capture.output) importFrom(utils,head) importFrom(utils,installed.packages) diff --git a/R/gglyph.R b/R/gglyph.R index 14a42a8ca..4833f40cd 100644 --- a/R/gglyph.R +++ b/R/gglyph.R @@ -1,7 +1,10 @@ -#' Create \code{\link{glyphplot}} data +#' Create data for glyph map #' #' Create the data needed to generate a glyph plot. #' +#' The \code{glyphs} functions +#' now extract the data object created with \code{\link{cubble::geom_glyph}} +#' #' @param data A data frame containing variables named in \code{x_major}, #' \code{x_minor}, \code{y_major} and \code{y_minor}. #' @param x_major,x_minor,y_major,y_minor The name of the variable (as a @@ -17,7 +20,8 @@ #' minor values within a grid cell. Defaults to \code{\link{identity}} so #' that no scaling is performed. #' @export -#' @author Di Cook, Heike Hofmann, Hadley Wickham +#' @importFrom cubble geom_glyph +#' @author Di Cook, Heike Hofmann, Hadley Wickham, Sherry Zhang #' @examples #' # Small function to display plots only if it's interactive #' p_ <- GGally::print_if_interactive @@ -46,88 +50,71 @@ glyphs <- function( y_scale = identity, x_scale = identity ) { - data$gid <- interaction(data[[x_major]], data[[y_major]], drop = TRUE) + out <- glyph_layer(data, component = "glyph", + x_major, x_minor, + y_major, y_minor, + polar, height, width, y_scale, x_scale) + new_cols <- out %>% + dplyr::select(group, x, y) %>% + dplyr::rename(gid = group, gx = x, gy = y) + + data <- data %>% dplyr::bind_cols(new_cols) + + tibble::new_tibble(data, nrow = nrow(data), + width = width, height = height, polar = polar, + x_major = x_major, y_major = y_major, + x_minor = x_minor, y_minor = y_minor, + class = "glyphplot") +} - if (is.rel(width)) { - width <- resolution(data[[x_major]], zero = FALSE) * unclass(width) - message("Using width ", format(width, digits = 3)) - } - if (is.rel(height)) { - height <- resolution(data[[y_major]], zero = FALSE) * unclass(height) - message("Using height ", format(height, digits = 3)) - } - if (!identical(x_scale, identity) || !identical(y_scale, identity)) { - data <- ddply(data, "gid", function(df) { - df[[x_minor]] <- x_scale(df[[x_minor]]) - df[[y_minor]] <- y_scale(df[[y_minor]]) - df - }) - } +glyph_layer <- function(data, component = c("glyph", "line", "box"), + x_major, x_minor, y_major, y_minor, + polar, height, width, + y_scale, x_scale){ + if (missing(x_major)) x_major <- attr(data, "x_major") + if (missing(x_minor)) x_minor <- attr(data, "x_minor") + if (missing(y_major)) y_major <- attr(data, "y_major") + if (missing(y_minor)) y_minor <- attr(data, "y_minor") + if (missing(polar)) polar <- attr(data, "polar") + if (missing(width)) width <- attr(data, "width") + if (missing(height)) height <- attr(data, "height") - if (polar) { - theta <- 2 * pi * rescale01(data[[x_minor]]) - r <- rescale01(data[[y_minor]]) + p <- ggplot2::ggplot(data = data, + aes(x_major = data[[x_major]], x_minor = data[[x_minor]], + y_major = data[[y_major]], y_minor = data[[y_minor]]), + polar = polar, height = height, width = width) - data$gx <- data[[x_major]] + width / 2 * r * sin(theta) - data$gy <- data[[y_major]] + height / 2 * r * cos(theta) - data <- data[order(data[[x_major]], data[[x_minor]]), ] - } else { - data$gx <- data[[x_major]] + rescale11(data[[x_minor]]) * width / 2 - data$gy <- data[[y_major]] + rescale11(data[[y_minor]]) * height / 2 - } + out <- switch (component, + "glyph" = p + cubble::geom_glyph(), + "line" = p + cubble::geom_glyph_line(), + "box" = p + cubble::geom_glyph_box() + ) - structure(data, - width = width, height = height, polar = polar, - x_major = x_major, y_major = y_major, - class = c("glyphplot", "data.frame")) -} + res <- ggplot2::layer_data(out) -# Create reference lines for a glyph plot -ref_lines <- function(data) { - stopifnot(is.glyphplot(data)) + if (component %in% c("line", "box")) res <- res %>% dplyr::rename(gx = x, gy = y, gid = group) + res +} - glyph <- attributes(data) +add_ref_lines <- function(data, color = "white", size = 1.5, ...){ - cells <- unique(data[c(glyph$x_major, glyph$y_major, "gid")]) + data <- glyph_layer(data, component = "line") + ggplot2::geom_path(data = data, color = color, size = size, ...) +} - if (glyph$polar) { - ref_line <- function(df) { - theta <- seq(0, 2 * pi, length.out = 30) - data.frame( - gid = df$gid, - gx = df[[glyph$x_major]] + glyph$width / 4 * sin(theta), - gy = df[[glyph$y_major]] + glyph$height / 4 * cos(theta) - ) +add_ref_boxes <- function(data, var_fill = NULL, color = "white", size = 0.5, + fill = NA, ...){ - } - } else { - ref_line <- function(df) { - data.frame( - gid = df$gid, - gx = df[[glyph$x_major]] + c(-1, 1) * glyph$width / 2, - gy = df[[glyph$y_major]] - ) - } - } - ddply(cells, "gid", ref_line) -} + data <- glyph_layer(data, component = "box") + data <- data %>% dplyr::select(gid, gx, gy, xmin:ymax) -# Create reference boxes for a glyph plot -ref_boxes <- function(data, fill = NULL) { - stopifnot(is.glyphplot(data)) - glyph <- attributes(data) - cells <- data.frame(unique(data[c(glyph$x_major, glyph$y_major, "gid", fill)])) + suppressWarnings(ggplot2::geom_rect( + data = data, + aes_all(names(data)), + color = color, size = size,fill = fill, ...)) - df <- data.frame(xmin = cells[[glyph$x_major]] - glyph$width / 2, - xmax = cells[[glyph$x_major]] + glyph$width / 2, - ymin = cells[[glyph$y_major]] - glyph$height / 2, - ymax = cells[[glyph$y_major]] + glyph$height / 2) - if (!is.null(fill)){ - df$fill <- cells[[fill]] - } - df } @@ -147,12 +134,13 @@ ref_boxes <- function(data, fill = NULL) { #' string) for the major x and y axes. Together, the # combination of \code{x_major} and \code{y_major} specifies a grid cell. #' @export -#' @author Di Cook, Heike Hofmann, Hadley Wickham -glyphplot <- function(data, width, height, polar, x_major, y_major) { - structure(data, - width = width, height = height, polar = polar, - x_major = x_major, y_major = y_major, - class = c("glyphplot", "data.frame")) +#' @author Di Cook, Heike Hofmann, Hadley Wickham, Sherry Zhang +glyphplot <- function(data, width, height, polar, x_major, y_major, x_minor, y_minor) { + tibble::new_tibble(data, nrow = nrow(data), + width = width, height = height, polar = polar, + x_major = x_major, y_major = y_major, + x_minor = x_minor, y_minor = y_minor, + class = "glyphplot") } #' @export #' @rdname glyphplot @@ -163,140 +151,32 @@ is.glyphplot <- function(x) { #' @rdname glyphplot "[.glyphplot" <- function(x, ...) { glyphplot(NextMethod(), - width = attr(x, "width"), height = attr(x, "height"), - x_major = attr(x, "x_major"), y_major = attr(x, "y_major"), - polar = attr(x, "polar")) + width = attr(x, "width"), height = attr(x, "height"), + x_major = attr(x, "x_major"), y_major = attr(x, "y_major"), + x_minor = attr(x, "x_minor"), y_minor = attr(x, "y_minor"), + polar = attr(x, "polar")) } #' @param x glyphplot to be printed #' @param ... ignored #' @export #' @rdname glyphplot -#' @method print glyphplot -print.glyphplot <- function(x, ...) { - NextMethod() +#' @importFrom tibble tbl_sum +#' @method tbl_sum glyphplot +tbl_sum.glyphplot <- function(x, ...) { if (attr(x, "polar")) { - cat("Polar ") + coord <- "polar" } else { - cat("Cartesian ") + coord <- "cartesian" } + + dim <- glue::glue(nrow(x), " x ", ncol(x)) width <- format(attr(x, "width"), digits = 3) height <- format(attr(x, "height"), digits = 3) - cat("glyphplot: \n") - cat(" Size: [", width, ", ", height, "]\n", sep = "") - cat(" Major axes: ", attr(x, "x_major"), ", ", attr(x, "y_major"), "\n", - sep = "") - # cat("\n") -} - - -# Relative dimensions -------------------------------------------------------- - -# Relative dimensions -# -# @param x numeric value between 0 and 1 -# rel <- function(x) { -# structure(x, class = "rel") -# } -# @export -# rel <- ggplot2::rel - -# @rdname rel -# @param ... ignored -# print.rel <- function(x, ...) { -# print(noquote(paste(x, " *", sep = ""))) -# } -## works even though it is not exported -# @export -# ggplot2::print.rel - -# @rdname rel -# is.rel <- function(x) { -# inherits(x, "rel") -# } -## only used internally. and ggplot2 has this exported -# @export -# ggplot2:::is.rel -is.rel <- ggplot2:::is.rel - -# Rescaling functions -------------------------------------------------------- - -#' Rescaling functions -#' -#' @param x numeric vector -#' @param xlim value used in \code{range} -#' @name rescale01 - + size <- glue::glue("[", width, ", ", height, "]\n", sep = "") + axes <- glue::glue(attr(x, "x_major"), ", ", attr(x, "y_major"), "\n", + sep = "") -#' @export -#' @rdname rescale01 -range01 <- function(x) { - rng <- range(x, na.rm = TRUE) - (x - rng[1]) / (rng[2] - rng[1]) -} - -#' @export -#' @rdname rescale01 -max1 <- function(x) { - x / max(x, na.rm = TRUE) -} -#' @export -#' @rdname rescale01 -mean0 <- function(x) { - x - mean(x, na.rm = TRUE) -} -#' @export -#' @rdname rescale01 -min0 <- function(x) { - x - min(x, na.rm = TRUE) -} -#' @export -#' @rdname rescale01 -rescale01 <- function(x, xlim=NULL) { - if (is.null(xlim)) { - rng <- range(x, na.rm = TRUE) - } else { - rng <- xlim - } - (x - rng[1]) / (rng[2] - rng[1]) -} -#' @export -#' @rdname rescale01 -rescale11 <- function(x, xlim=NULL) { - 2 * rescale01(x, xlim) - 1 -} - -#' Add reference lines for each cell of the glyphmap. -#' -#' @param data A glyphmap structure. -#' @param color Set the color to draw in, default is "white" -#' @param size Set the line size, default is 1.5 -#' @param ... other arguments passed onto [ggplot2::geom_line()] -#' @export -add_ref_lines <- function(data, color = "white", size = 1.5, ...){ - rl <- ref_lines(data) - geom_path(data = rl, color = color, size = size, ...) -} - -#' Add reference boxes around each cell of the glyphmap. -#' -#' @param data A glyphmap structure. -#' @param var_fill Variable name to use to set the fill color -#' @param color Set the color to draw in, default is "white" -#' @param size Set the line size, default is 0.5 -#' @param fill fill value used if \code{var_fill} is \code{NULL} -#' @param ... other arguments passed onto [ggplot2::geom_rect()] -#' @export -add_ref_boxes <- function(data, var_fill = NULL, color = "white", size = 0.5, - fill = NA, ...){ - rb <- ref_boxes(data, var_fill) - if (!is.null(var_fill)){ - geom_rect(aes_all(names(rb)), data = rb, - color = color, size = size, inherit.aes = FALSE, ...) - } - else{ - geom_rect(aes_all(names(rb)), data = rb, - color = color, size = size, inherit.aes = FALSE, fill = fill, ...) - } + c(glyphplot = dim, coord = coord, size = size, "major axes" = axes) } diff --git a/man/GGally-package.Rd b/man/GGally-package.Rd index d6d00f708..63dcf5092 100644 --- a/man/GGally-package.Rd +++ b/man/GGally-package.Rd @@ -6,12 +6,7 @@ \alias{GGally-package} \title{GGally: Extension to 'ggplot2'} \description{ -The R package 'ggplot2' is a plotting system based on the grammar of graphics. - 'GGally' extends 'ggplot2' by adding several functions - to reduce the complexity of combining geometric objects with transformed data. - Some of these functions include a pairwise plot matrix, a two group pairwise plot - matrix, a parallel coordinates plot, a survival plot, and several functions to - plot networks. +The R package 'ggplot2' is a plotting system based on the grammar of graphics. 'GGally' extends 'ggplot2' by adding several functions to reduce the complexity of combining geometric objects with transformed data. Some of these functions include a pairwise plot matrix, a two group pairwise plot matrix, a parallel coordinates plot, a survival plot, and several functions to plot networks. } \seealso{ Useful links: diff --git a/man/add_ref_boxes.Rd b/man/add_ref_boxes.Rd deleted file mode 100644 index e78e7d6a4..000000000 --- a/man/add_ref_boxes.Rd +++ /dev/null @@ -1,31 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/gglyph.R -\name{add_ref_boxes} -\alias{add_ref_boxes} -\title{Add reference boxes around each cell of the glyphmap.} -\usage{ -add_ref_boxes( - data, - var_fill = NULL, - color = "white", - size = 0.5, - fill = NA, - ... -) -} -\arguments{ -\item{data}{A glyphmap structure.} - -\item{var_fill}{Variable name to use to set the fill color} - -\item{color}{Set the color to draw in, default is "white"} - -\item{size}{Set the line size, default is 0.5} - -\item{fill}{fill value used if \code{var_fill} is \code{NULL}} - -\item{...}{other arguments passed onto \code{\link[ggplot2:geom_tile]{ggplot2::geom_rect()}}} -} -\description{ -Add reference boxes around each cell of the glyphmap. -} diff --git a/man/add_ref_lines.Rd b/man/add_ref_lines.Rd deleted file mode 100644 index 23c65cbb8..000000000 --- a/man/add_ref_lines.Rd +++ /dev/null @@ -1,20 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/gglyph.R -\name{add_ref_lines} -\alias{add_ref_lines} -\title{Add reference lines for each cell of the glyphmap.} -\usage{ -add_ref_lines(data, color = "white", size = 1.5, ...) -} -\arguments{ -\item{data}{A glyphmap structure.} - -\item{color}{Set the color to draw in, default is "white"} - -\item{size}{Set the line size, default is 1.5} - -\item{...}{other arguments passed onto \code{\link[ggplot2:geom_path]{ggplot2::geom_line()}}} -} -\description{ -Add reference lines for each cell of the glyphmap. -} diff --git a/man/ggcoef_model.Rd b/man/ggcoef_model.Rd index f52323e1d..c6bc21f4c 100644 --- a/man/ggcoef_model.Rd +++ b/man/ggcoef_model.Rd @@ -108,10 +108,6 @@ ggcoef_plot( \arguments{ \item{model}{a regression model object} -\item{tidy_fun}{option to specify a custom tidier function} - -\item{conf.int}{should confidence intervals be computed? (see \code{\link[broom:reexports]{broom::tidy()}})} - \item{conf.level}{the confidence level to use for the confidence interval if \code{conf.int = TRUE}; must be strictly greater than 0 and less than 1; defaults to 0.95, which corresponds to a 95 @@ -120,28 +116,6 @@ percent confidence interval} \item{exponentiate}{if \code{TRUE} a logarithmic scale will be used for x-axis} -\item{variable_labels}{a named list or a named vector of custom variable labels} - -\item{term_labels}{a named list or a named vector of custom term labels} - -\item{interaction_sep}{separator for interaction terms} - -\item{categorical_terms_pattern}{a \link[glue:glue]{glue pattern} for -labels of categorical terms with treatment or sum contrasts -(see \code{\link[broom.helpers:model_list_terms_levels]{model_list_terms_levels()}})} - -\item{add_reference_rows}{should reference rows be added?} - -\item{no_reference_row}{variables (accepts \link[dplyr:select]{tidyselect} notation) -for those no reference row should be added, when \code{add_reference_rows = TRUE}} - -\item{intercept}{should the intercept(s) be included?} - -\item{include}{variables to include. Accepts \link[dplyr:select]{tidyselect} -syntax. Use \code{-} to remove a variable. Default is \code{everything()}. -See also \code{\link[broom.helpers:select_helpers]{all_continuous()}}, \code{\link[broom.helpers:select_helpers]{all_categorical()}}, \code{\link[broom.helpers:select_helpers]{all_dichotomous()}} -and \code{\link[broom.helpers:select_helpers]{all_interaction()}}} - \item{significance}{level (between 0 and 1) below which a coefficient is consider to be significantly different from 0 (or 1 if \code{exponentiate = TRUE}), \code{NULL} for not highlighting diff --git a/man/glyphplot.Rd b/man/glyphplot.Rd index 8eeb73920..b0d469d05 100644 --- a/man/glyphplot.Rd +++ b/man/glyphplot.Rd @@ -4,16 +4,16 @@ \alias{glyphplot} \alias{is.glyphplot} \alias{[.glyphplot} -\alias{print.glyphplot} +\alias{tbl_sum.glyphplot} \title{Glyph plot class} \usage{ -glyphplot(data, width, height, polar, x_major, y_major) +glyphplot(data, width, height, polar, x_major, y_major, x_minor, y_minor) is.glyphplot(x) \method{[}{glyphplot}(x, ...) -\method{print}{glyphplot}(x, ...) +\method{tbl_sum}{glyphplot}(x, ...) } \arguments{ \item{data}{A data frame containing variables named in \code{x_major}, diff --git a/man/glyphs.Rd b/man/glyphs.Rd index e2534f74a..26eef5c56 100644 --- a/man/glyphs.Rd +++ b/man/glyphs.Rd @@ -2,7 +2,7 @@ % Please edit documentation in R/gglyph.R \name{glyphs} \alias{glyphs} -\title{Create \code{\link{glyphplot}} data} +\title{Create data for glyph map} \usage{ glyphs( data, @@ -38,6 +38,10 @@ that no scaling is performed.} \description{ Create the data needed to generate a glyph plot. } +\details{ +The \code{glyphs} functions +now extract the data object created with \code{\link{cubble::geom_glyph}} +} \examples{ # Small function to display plots only if it's interactive p_ <- GGally::print_if_interactive diff --git a/man/rescale01.Rd b/man/rescale01.Rd deleted file mode 100644 index a60e70170..000000000 --- a/man/rescale01.Rd +++ /dev/null @@ -1,31 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/gglyph.R -\name{rescale01} -\alias{rescale01} -\alias{range01} -\alias{max1} -\alias{mean0} -\alias{min0} -\alias{rescale11} -\title{Rescaling functions} -\usage{ -range01(x) - -max1(x) - -mean0(x) - -min0(x) - -rescale01(x, xlim = NULL) - -rescale11(x, xlim = NULL) -} -\arguments{ -\item{x}{numeric vector} - -\item{xlim}{value used in \code{range}} -} -\description{ -Rescaling functions -} From bb63a6af64a83bf662a4bafb9f2dad46242c304b Mon Sep 17 00:00:00 2001 From: Sherry Zhang Date: Fri, 7 Jan 2022 23:43:12 +1100 Subject: [PATCH 2/7] add cubble and tibble as import --- DESCRIPTION | 7 ++++--- NAMESPACE | 2 ++ R/gglyph.R | 5 +++-- man/glyphplot.Rd | 2 +- man/glyphs.Rd | 2 +- tests/testthat/test-gglyph.R | 26 -------------------------- 6 files changed, 11 insertions(+), 33 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 3d1168c7b..604431ab2 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -41,10 +41,13 @@ Imports: progress, RColorBrewer, reshape (>= 0.8.5), + tibble, rlang, scales (>= 1.1.0), tidyr, - utils + utils, + cubble, + glue Suggests: broom (>= 0.7.0), broom.helpers (>= 1.1.0), @@ -69,8 +72,6 @@ Suggests: knitr, spelling, emmeans -Remotes: - huizezhang-sherry/cubble Roxygen: list(markdown = TRUE) RoxygenNote: 7.1.2 SystemRequirements: openssl diff --git a/NAMESPACE b/NAMESPACE index 8b1fe7f1c..12db129e1 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -127,6 +127,8 @@ import(ggplot2) import(plyr) import(utils) importFrom(cubble,geom_glyph) +importFrom(cubble,geom_glyph_box) +importFrom(cubble,geom_glyph_line) importFrom(dplyr,"%>%") importFrom(grDevices,colorRampPalette) importFrom(grDevices,gray.colors) diff --git a/R/gglyph.R b/R/gglyph.R index 4833f40cd..82032f449 100644 --- a/R/gglyph.R +++ b/R/gglyph.R @@ -20,7 +20,7 @@ #' minor values within a grid cell. Defaults to \code{\link{identity}} so #' that no scaling is performed. #' @export -#' @importFrom cubble geom_glyph +#' @importFrom cubble geom_glyph geom_glyph_line geom_glyph_box #' @author Di Cook, Heike Hofmann, Hadley Wickham, Sherry Zhang #' @examples #' # Small function to display plots only if it's interactive @@ -110,6 +110,7 @@ add_ref_boxes <- function(data, var_fill = NULL, color = "white", size = 0.5, data <- glyph_layer(data, component = "box") data <- data %>% dplyr::select(gid, gx, gy, xmin:ymax) + if (!is.null(var_fill)) data$fill <- var_fill suppressWarnings(ggplot2::geom_rect( data = data, aes_all(names(data)), @@ -130,7 +131,7 @@ add_ref_boxes <- function(data, var_fill = NULL, color = "white", size = 0.5, # resolution of the data by using \code{\link[ggplot2]{rel}}. #' @param polar A logical of length 1, specifying whether the glyphs should #' be drawn in polar coordinates. Defaults to \code{FALSE}. -#' @param x_major,y_major The name of the variable (as a +#' @param x_major,x_minor,y_major,y_minorm The name of the variable (as a #' string) for the major x and y axes. Together, the # combination of \code{x_major} and \code{y_major} specifies a grid cell. #' @export diff --git a/man/glyphplot.Rd b/man/glyphplot.Rd index b0d469d05..ff10a60e7 100644 --- a/man/glyphplot.Rd +++ b/man/glyphplot.Rd @@ -37,5 +37,5 @@ string) for the major x and y axes. Together, the} Glyph plot class } \author{ -Di Cook, Heike Hofmann, Hadley Wickham +Di Cook, Heike Hofmann, Hadley Wickham, Sherry Zhang } diff --git a/man/glyphs.Rd b/man/glyphs.Rd index 26eef5c56..b6c1152dd 100644 --- a/man/glyphs.Rd +++ b/man/glyphs.Rd @@ -63,5 +63,5 @@ p_(ggplot2::ggplot(temp.gly, ggplot2::aes(gx, gy, group = gid)) + ggplot2::labs(x = "", y = "")) } \author{ -Di Cook, Heike Hofmann, Hadley Wickham +Di Cook, Heike Hofmann, Hadley Wickham, Sherry Zhang } diff --git a/tests/testthat/test-gglyph.R b/tests/testthat/test-gglyph.R index 04dc69702..e018ad070 100644 --- a/tests/testthat/test-gglyph.R +++ b/tests/testthat/test-gglyph.R @@ -44,13 +44,6 @@ test_that("examples", { }) -test_that("message", { - - expect_message(glyphs(nasaLate, "long", "day", "lat", "surftemp", height = 1), "Using width 2.38") - expect_message(glyphs(nasaLate, "long", "day", "lat", "surftemp", width = 1), "Using height 2.37") -}) - - test_that("scales", { dt <- do_glyph(x_scale = log) @@ -120,22 +113,3 @@ test_that("fill", { expect_equal(mapping_string(get("mapping", envir = p$layers[[2]])$fill), "fill") }) - -test_that("print", { - - dt <- do_glyph() - txt <- capture.output(print(dt)) - expect_equal(txt[length(txt) - 2], "Cartesian glyphplot: ") - expect_equal(txt[length(txt) - 1], " Size: [2.38, 2.37]") - expect_equal(txt[length(txt) - 0], " Major axes: long, lat" ) - - dt <- do_glyph(polar = TRUE) - txt <- capture.output(print(dt)) - expect_equal(txt[length(txt) - 2], "Polar glyphplot: ") - expect_equal(txt[length(txt) - 1], " Size: [2.38, 2.37]") - expect_equal(txt[length(txt) - 0], " Major axes: long, lat" ) - - txt <- capture.output(print(rel(0.95))) - expect_equal(txt, "[1] 0.95 *") - -}) From de6b87d18e9af607b3df893f3eb1b33b4bf24b1c Mon Sep 17 00:00:00 2001 From: Sherry Zhang Date: Sun, 9 Jan 2022 13:14:30 +1100 Subject: [PATCH 3/7] add scaling for minor axes --- R/gglyph.R | 21 +++++++++++++++------ tests/testthat/test-gglyph.R | 19 ------------------- 2 files changed, 15 insertions(+), 25 deletions(-) diff --git a/R/gglyph.R b/R/gglyph.R index 82032f449..aa3316941 100644 --- a/R/gglyph.R +++ b/R/gglyph.R @@ -50,16 +50,23 @@ glyphs <- function( y_scale = identity, x_scale = identity ) { + + x_scale <- enquo(x_scale) + y_scale <- enquo(y_scale) out <- glyph_layer(data, component = "glyph", - x_major, x_minor, - y_major, y_minor, - polar, height, width, y_scale, x_scale) + x_major, x_minor, y_major, y_minor, + polar, height, width, x_scale, y_scale) new_cols <- out %>% dplyr::select(group, x, y) %>% dplyr::rename(gid = group, gx = x, gy = y) data <- data %>% dplyr::bind_cols(new_cols) + if (!identical(x_scale, identity) || !identical(y_scale, identity)){ + data[[x_minor]] <- out$x_minor + data[[y_minor]] <- out$y_minor + } + tibble::new_tibble(data, nrow = nrow(data), width = width, height = height, polar = polar, x_major = x_major, y_major = y_major, @@ -71,8 +78,8 @@ glyphs <- function( glyph_layer <- function(data, component = c("glyph", "line", "box"), x_major, x_minor, y_major, y_minor, - polar, height, width, - y_scale, x_scale){ + polar, height, width, x_scale, y_scale){ + if (missing(x_major)) x_major <- attr(data, "x_major") if (missing(x_minor)) x_minor <- attr(data, "x_minor") if (missing(y_major)) y_major <- attr(data, "y_major") @@ -83,7 +90,9 @@ glyph_layer <- function(data, component = c("glyph", "line", "box"), p <- ggplot2::ggplot(data = data, aes(x_major = data[[x_major]], x_minor = data[[x_minor]], - y_major = data[[y_major]], y_minor = data[[y_minor]]), + y_major = data[[y_major]], y_minor = data[[y_minor]], + x_scale = rlang::quo_name(x_scale), + y_scale = rlang::quo_name(y_scale)), polar = polar, height = height, width = width) out <- switch (component, diff --git a/tests/testthat/test-gglyph.R b/tests/testthat/test-gglyph.R index e018ad070..11655979b 100644 --- a/tests/testthat/test-gglyph.R +++ b/tests/testthat/test-gglyph.R @@ -58,25 +58,6 @@ test_that("scales", { dtm <- merge(dt, nasaLate) expect_true(all(dtm$surftempLog == log(dtm$surftemp))) - for (scale_fn in c(range01, max1, mean0, min0, rescale01, rescale11)) { - dt <- do_glyph(y_scale = scale_fn) - dt$surftempScaled <- dt$surftemp - dt$surftemp <- NULL - dtm <- merge(dt, nasaLate) - expect_true(all(dtm$surftempScaled != dtm$surftemp)) - } - - - for (scale_fn in c(rescale01, rescale11)) { - scale_fn2 <- function(x) { - scale_fn(x, xlim = c(1 / 4, 3 / 4)) - } - dt <- do_glyph(y_scale = scale_fn2) - dt$surftempScaled <- dt$surftemp - dt$surftemp <- NULL - dtm <- merge(dt, nasaLate) - expect_true(all(dtm$surftempScaled != dtm$surftemp)) - } }) From 08e46e91b2785c95c34ebc746baef0e4799046f8 Mon Sep 17 00:00:00 2001 From: Barret Schloerke Date: Fri, 14 Jan 2022 11:53:22 -0500 Subject: [PATCH 4/7] Add `huizezhang-sherry/cubble` remote --- DESCRIPTION | 2 ++ 1 file changed, 2 insertions(+) diff --git a/DESCRIPTION b/DESCRIPTION index 604431ab2..aa8c8497e 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -72,6 +72,8 @@ Suggests: knitr, spelling, emmeans +Remotes: + huizezhang-sherry/cubble Roxygen: list(markdown = TRUE) RoxygenNote: 7.1.2 SystemRequirements: openssl From 62bf0dccddf4d24e97570c8ebf75db01daa59453 Mon Sep 17 00:00:00 2001 From: Sherry Zhang Date: Sat, 15 Jan 2022 21:00:38 +1100 Subject: [PATCH 5/7] fix CMD checks --- R/gglyph.R | 10 +++++----- man/glyphplot.Rd | 2 +- man/glyphs.Rd | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/R/gglyph.R b/R/gglyph.R index aa3316941..1f5dc21fc 100644 --- a/R/gglyph.R +++ b/R/gglyph.R @@ -3,7 +3,7 @@ #' Create the data needed to generate a glyph plot. #' #' The \code{glyphs} functions -#' now extract the data object created with \code{\link{cubble::geom_glyph}} +#' now extract the data object created with \code{\link[cubble]{geom_glyph}} #' #' @param data A data frame containing variables named in \code{x_major}, #' \code{x_minor}, \code{y_major} and \code{y_minor}. @@ -89,8 +89,8 @@ glyph_layer <- function(data, component = c("glyph", "line", "box"), if (missing(height)) height <- attr(data, "height") p <- ggplot2::ggplot(data = data, - aes(x_major = data[[x_major]], x_minor = data[[x_minor]], - y_major = data[[y_major]], y_minor = data[[y_minor]], + aes(x_major = .data[[x_major]], x_minor = .data[[x_minor]], + y_major = .data[[y_major]], y_minor = .data[[y_minor]], x_scale = rlang::quo_name(x_scale), y_scale = rlang::quo_name(y_scale)), polar = polar, height = height, width = width) @@ -117,7 +117,7 @@ add_ref_boxes <- function(data, var_fill = NULL, color = "white", size = 0.5, fill = NA, ...){ data <- glyph_layer(data, component = "box") - data <- data %>% dplyr::select(gid, gx, gy, xmin:ymax) + data <- data %>% dplyr::select(.data$gid, .data$gx, .data$gy, .data$xmin:.data$ymax) if (!is.null(var_fill)) data$fill <- var_fill suppressWarnings(ggplot2::geom_rect( @@ -140,7 +140,7 @@ add_ref_boxes <- function(data, var_fill = NULL, color = "white", size = 0.5, # resolution of the data by using \code{\link[ggplot2]{rel}}. #' @param polar A logical of length 1, specifying whether the glyphs should #' be drawn in polar coordinates. Defaults to \code{FALSE}. -#' @param x_major,x_minor,y_major,y_minorm The name of the variable (as a +#' @param x_major,x_minor,y_major,y_minor The name of the variable (as a #' string) for the major x and y axes. Together, the # combination of \code{x_major} and \code{y_major} specifies a grid cell. #' @export diff --git a/man/glyphplot.Rd b/man/glyphplot.Rd index ff10a60e7..538e66dbf 100644 --- a/man/glyphplot.Rd +++ b/man/glyphplot.Rd @@ -26,7 +26,7 @@ absolutely by supplying a numeric vector of length 1, or relative to the} \item{polar}{A logical of length 1, specifying whether the glyphs should be drawn in polar coordinates. Defaults to \code{FALSE}.} -\item{x_major, y_major}{The name of the variable (as a +\item{x_major, x_minor, y_major, y_minor}{The name of the variable (as a string) for the major x and y axes. Together, the} \item{x}{glyphplot to be printed} diff --git a/man/glyphs.Rd b/man/glyphs.Rd index b6c1152dd..1d74f17af 100644 --- a/man/glyphs.Rd +++ b/man/glyphs.Rd @@ -40,7 +40,7 @@ Create the data needed to generate a glyph plot. } \details{ The \code{glyphs} functions -now extract the data object created with \code{\link{cubble::geom_glyph}} +now extract the data object created with \code{\link[cubble]{geom_glyph}} } \examples{ # Small function to display plots only if it's interactive From 532d44f7ae53027e9a064f90eb3363111d9da719 Mon Sep 17 00:00:00 2001 From: Sherry Zhang Date: Thu, 20 Jan 2022 21:44:37 +1100 Subject: [PATCH 6/7] fix review comments --- DESCRIPTION | 9 ++++----- NAMESPACE | 6 ++++++ R/gglyph.R | 52 ++++++++++++++++++++++++++++++++++++++++++++-------- 3 files changed, 54 insertions(+), 13 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index aa8c8497e..04f627910 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -41,13 +41,10 @@ Imports: progress, RColorBrewer, reshape (>= 0.8.5), - tibble, rlang, scales (>= 1.1.0), tidyr, - utils, - cubble, - glue + utils Suggests: broom (>= 0.7.0), broom.helpers (>= 1.1.0), @@ -71,7 +68,9 @@ Suggests: crosstalk, knitr, spelling, - emmeans + emmeans, + tibble, + cubble Remotes: huizezhang-sherry/cubble Roxygen: list(markdown = TRUE) diff --git a/NAMESPACE b/NAMESPACE index 12db129e1..825c3e86b 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -101,12 +101,18 @@ export(lowertriangle) export(mapping_color_to_fill) export(mapping_string) export(mapping_swap_x_y) +export(max1) +export(mean0) +export(min0) export(model_beta_label) export(model_beta_variables) export(model_response_variables) export(print_if_interactive) export(putPlot) +export(range01) export(remove_color_unless_equal) +export(rescale01) +export(rescale11) export(scatmat) export(signif_stars) export(stat_cross) diff --git a/R/gglyph.R b/R/gglyph.R index 1f5dc21fc..4dfd0c169 100644 --- a/R/gglyph.R +++ b/R/gglyph.R @@ -90,13 +90,12 @@ glyph_layer <- function(data, component = c("glyph", "line", "box"), p <- ggplot2::ggplot(data = data, aes(x_major = .data[[x_major]], x_minor = .data[[x_minor]], - y_major = .data[[y_major]], y_minor = .data[[y_minor]], - x_scale = rlang::quo_name(x_scale), - y_scale = rlang::quo_name(y_scale)), + y_major = .data[[y_major]], y_minor = .data[[y_minor]]), polar = polar, height = height, width = width) out <- switch (component, - "glyph" = p + cubble::geom_glyph(), + "glyph" = p + cubble::geom_glyph(x_scale = rlang::quo_name(x_scale), + y_scale = rlang::quo_name(y_scale)), "line" = p + cubble::geom_glyph_line(), "box" = p + cubble::geom_glyph_box() ) @@ -127,6 +126,43 @@ add_ref_boxes <- function(data, var_fill = NULL, color = "white", size = 0.5, } +#' @export +#' @rdname rescale01 +range01 <- function(x) { + rng <- range(x, na.rm = TRUE) + (x - rng[1]) / (rng[2] - rng[1]) +} + +#' @export +#' @rdname rescale01 +max1 <- function(x) { + x / max(x, na.rm = TRUE) +} +#' @export +#' @rdname rescale01 +mean0 <- function(x) { + x - mean(x, na.rm = TRUE) +} +#' @export +#' @rdname rescale01 +min0 <- function(x) { + x - min(x, na.rm = TRUE) +} +#' @export +#' @rdname rescale01 +rescale01 <- function(x, xlim=NULL) { + if (is.null(xlim)) { + rng <- range(x, na.rm = TRUE) + } else { + rng <- xlim + } + (x - rng[1]) / (rng[2] - rng[1]) +} +#' @export +#' @rdname rescale01 +rescale11 <- function(x, xlim=NULL) { + 2 * rescale01(x, xlim) - 1 +} # Glyph plot class ----------------------------------------------------------- @@ -180,13 +216,13 @@ tbl_sum.glyphplot <- function(x, ...) { coord <- "cartesian" } - dim <- glue::glue(nrow(x), " x ", ncol(x)) + dim <- paste0(nrow(x), " x ", ncol(x)) width <- format(attr(x, "width"), digits = 3) height <- format(attr(x, "height"), digits = 3) - size <- glue::glue("[", width, ", ", height, "]\n", sep = "") - axes <- glue::glue(attr(x, "x_major"), ", ", attr(x, "y_major"), "\n", + size <- paste0("[", width, ", ", height, "]\n", sep = "") + axes <- paste0(attr(x, "x_major"), ", ", attr(x, "y_major"), "\n", sep = "") - c(glyphplot = dim, coord = coord, size = size, "major axes" = axes) + c(glyphplot = dim, coord = coord, size = size, "major_axes" = axes) } From 8736b17cad4e2b60512c153f7a80d9858ea1a120 Mon Sep 17 00:00:00 2001 From: Barret Schloerke Date: Wed, 12 Oct 2022 12:29:09 -0400 Subject: [PATCH 7/7] restore scale functions. Use PR changes from huizezhang-sherry/cubble#13 --- DESCRIPTION | 2 + NAMESPACE | 2 + R/gglyph.R | 98 +++++++++++++++++++++++++++++--------------- man/add_ref_boxes.Rd | 31 ++++++++++++++ man/add_ref_lines.Rd | 20 +++++++++ man/rescale01.Rd | 50 ++++++++++++++++++++++ 6 files changed, 171 insertions(+), 32 deletions(-) create mode 100644 man/add_ref_boxes.Rd create mode 100644 man/add_ref_lines.Rd create mode 100644 man/rescale01.Rd diff --git a/DESCRIPTION b/DESCRIPTION index 1e35031fa..f270d651c 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -72,6 +72,8 @@ Suggests: tibble, cubble, vdiffr +Remotes: + huizezhang-sherry/cubble Roxygen: list(markdown = TRUE) RoxygenNote: 7.2.1 SystemRequirements: openssl diff --git a/NAMESPACE b/NAMESPACE index 825c3e86b..7817d2d1f 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -14,6 +14,8 @@ export(StatCross) export(StatGGallyCount) export(StatProp) export(StatWeightedMean) +export(add_ref_boxes) +export(add_ref_lines) export(add_to_ggmatrix) export(brew_colors) export(broomify) diff --git a/R/gglyph.R b/R/gglyph.R index 0eacc9963..f9fb00bbf 100644 --- a/R/gglyph.R +++ b/R/gglyph.R @@ -50,9 +50,6 @@ glyphs <- function( y_scale = identity, x_scale = identity ) { - - x_scale <- enquo(x_scale) - y_scale <- enquo(y_scale) out <- glyph_layer(data, component = "glyph", x_major, x_minor, y_major, y_minor, polar, height, width, x_scale, y_scale) @@ -62,7 +59,7 @@ glyphs <- function( data <- data %>% dplyr::bind_cols(new_cols) - if (!identical(x_scale, identity) || !identical(y_scale, identity)){ + if (!identical(x_scale, identity) || !identical(y_scale, identity)) { data[[x_minor]] <- out$x_minor data[[y_minor]] <- out$y_minor } @@ -76,77 +73,112 @@ glyphs <- function( -glyph_layer <- function(data, component = c("glyph", "line", "box"), - x_major, x_minor, y_major, y_minor, - polar, height, width, x_scale, y_scale){ - - if (missing(x_major)) x_major <- attr(data, "x_major") - if (missing(x_minor)) x_minor <- attr(data, "x_minor") - if (missing(y_major)) y_major <- attr(data, "y_major") - if (missing(y_minor)) y_minor <- attr(data, "y_minor") - if (missing(polar)) polar <- attr(data, "polar") - if (missing(width)) width <- attr(data, "width") - if (missing(height)) height <- attr(data, "height") - - p <- ggplot2::ggplot(data = data, - aes(x_major = .data[[x_major]], x_minor = .data[[x_minor]], - y_major = .data[[y_major]], y_minor = .data[[y_minor]]), - polar = polar, height = height, width = width) +glyph_layer <- function( + data, + component = c("glyph", "line", "box"), + x_major = attr(data, "x_major"), + x_minor = attr(data, "x_minor"), + y_major = attr(data, "y_major"), + y_minor = attr(data, "y_minor"), + polar = attr(data, "polar"), + height = attr(data, "height"), + width = attr(data, "width"), + x_scale = identity, + y_scale = identity +) { + p <- + ggplot2::ggplot( + data = data, + aes_string( + x_major = x_major, + x_minor = x_minor, + y_major = y_major, + y_minor = y_minor + ), + polar = polar, + height = height, + width = width + ) - out <- switch (component, - "glyph" = p + cubble::geom_glyph(x_scale = rlang::quo_name(x_scale), - y_scale = rlang::quo_name(y_scale)), + out <- switch( + component, + "glyph" = p + cubble::geom_glyph(x_scale = x_scale, y_scale = y_scale), "line" = p + cubble::geom_glyph_line(), "box" = p + cubble::geom_glyph_box() ) res <- ggplot2::layer_data(out) - if (component %in% c("line", "box")) res <- res %>% dplyr::rename(gx = x, gy = y, gid = group) + if (component %in% c("line", "box")) { + res <- res %>% dplyr::rename(gx = x, gy = y, gid = group) + } res } + +#' Add reference lines for each cell of the glyphmap. +#' +#' @param data A glyphmap structure. +#' @param color Set the color to draw in, default is "white" +#' @param size Set the line size, default is 1.5 +#' @param ... other arguments passed onto [ggplot2::geom_line()] +#' @export add_ref_lines <- function(data, color = "white", size = 1.5, ...) { data <- glyph_layer(data, component = "line") ggplot2::geom_path(data = data, color = color, size = size, ...) } +#' Add reference boxes around each cell of the glyphmap. +#' +#' @param data A glyphmap structure. +#' @param var_fill Variable name to use to set the fill color +#' @param color Set the color to draw in, default is "white" +#' @param size Set the line size, default is 0.5 +#' @param fill fill value used if \code{var_fill} is \code{NULL} +#' @param ... other arguments passed onto [ggplot2::geom_rect()] +#' @export add_ref_boxes <- function(data, var_fill = NULL, color = "white", size = 0.5, fill = NA, ...) { data <- glyph_layer(data, component = "box") - data <- data %>% dplyr::select(.data$gid, .data$gx, .data$gy, .data$xmin:.data$ymax) + data <- data %>% dplyr::select(gid, gx, gy, xmin:ymax) if (!is.null(var_fill)) data$fill <- var_fill suppressWarnings(ggplot2::geom_rect( data = data, aes_all(names(data)), - color = color, size = size,fill = fill, ...)) + color = color, size = size, fill = fill, ...)) } +#' Rescaling functions +#' +#' @param x numeric vector +#' @param xlim value used in \code{range} #' @export -#' @rdname rescale01 +#' @describeIn rescale01 Rescale all values to [0, 1] range01 <- function(x) { rng <- range(x, na.rm = TRUE) (x - rng[1]) / (rng[2] - rng[1]) } #' @export -#' @rdname rescale01 +#' @describeIn rescale01 Divide by the maximum value max1 <- function(x) { x / max(x, na.rm = TRUE) } #' @export -#' @rdname rescale01 +#' @describeIn rescale01 Subtract the mean value mean0 <- function(x) { x - mean(x, na.rm = TRUE) } #' @export -#' @rdname rescale01 +#' @describeIn rescale01 Subtract the minimum value min0 <- function(x) { x - min(x, na.rm = TRUE) } #' @export -#' @rdname rescale01 +#' @describeIn rescale01 Rescale all values given a range. If no range is +#' provided, the min and max values are used. By default, this will result in +#' values from `[0, 1]`. rescale01 <- function(x, xlim = NULL) { if (is.null(xlim)) { rng <- range(x, na.rm = TRUE) @@ -156,7 +188,9 @@ rescale01 <- function(x, xlim = NULL) { (x - rng[1]) / (rng[2] - rng[1]) } #' @export -#' @rdname rescale01 +#' @describeIn rescale01 Rescale all values given a range. If no range is +#' provided, the min and max values are used. By default, this will result in +#' values from `[-1, 1]`. rescale11 <- function(x, xlim = NULL) { 2 * rescale01(x, xlim) - 1 } diff --git a/man/add_ref_boxes.Rd b/man/add_ref_boxes.Rd new file mode 100644 index 000000000..e78e7d6a4 --- /dev/null +++ b/man/add_ref_boxes.Rd @@ -0,0 +1,31 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/gglyph.R +\name{add_ref_boxes} +\alias{add_ref_boxes} +\title{Add reference boxes around each cell of the glyphmap.} +\usage{ +add_ref_boxes( + data, + var_fill = NULL, + color = "white", + size = 0.5, + fill = NA, + ... +) +} +\arguments{ +\item{data}{A glyphmap structure.} + +\item{var_fill}{Variable name to use to set the fill color} + +\item{color}{Set the color to draw in, default is "white"} + +\item{size}{Set the line size, default is 0.5} + +\item{fill}{fill value used if \code{var_fill} is \code{NULL}} + +\item{...}{other arguments passed onto \code{\link[ggplot2:geom_tile]{ggplot2::geom_rect()}}} +} +\description{ +Add reference boxes around each cell of the glyphmap. +} diff --git a/man/add_ref_lines.Rd b/man/add_ref_lines.Rd new file mode 100644 index 000000000..23c65cbb8 --- /dev/null +++ b/man/add_ref_lines.Rd @@ -0,0 +1,20 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/gglyph.R +\name{add_ref_lines} +\alias{add_ref_lines} +\title{Add reference lines for each cell of the glyphmap.} +\usage{ +add_ref_lines(data, color = "white", size = 1.5, ...) +} +\arguments{ +\item{data}{A glyphmap structure.} + +\item{color}{Set the color to draw in, default is "white"} + +\item{size}{Set the line size, default is 1.5} + +\item{...}{other arguments passed onto \code{\link[ggplot2:geom_path]{ggplot2::geom_line()}}} +} +\description{ +Add reference lines for each cell of the glyphmap. +} diff --git a/man/rescale01.Rd b/man/rescale01.Rd new file mode 100644 index 000000000..e8aa3b678 --- /dev/null +++ b/man/rescale01.Rd @@ -0,0 +1,50 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/gglyph.R +\name{range01} +\alias{range01} +\alias{max1} +\alias{mean0} +\alias{min0} +\alias{rescale01} +\alias{rescale11} +\title{Rescaling functions} +\usage{ +range01(x) + +max1(x) + +mean0(x) + +min0(x) + +rescale01(x, xlim = NULL) + +rescale11(x, xlim = NULL) +} +\arguments{ +\item{x}{numeric vector} + +\item{xlim}{value used in \code{range}} +} +\description{ +Rescaling functions +} +\section{Functions}{ +\itemize{ +\item \code{range01()}: Rescale all values to \link{0, 1} + +\item \code{max1()}: Divide by the maximum value + +\item \code{mean0()}: Subtract the mean value + +\item \code{min0()}: Subtract the minimum value + +\item \code{rescale01()}: Rescale all values given a range. If no range is +provided, the min and max values are used. By default, this will result in +values from \verb{[0, 1]}. + +\item \code{rescale11()}: Rescale all values given a range. If no range is +provided, the min and max values are used. By default, this will result in +values from \verb{[-1, 1]}. + +}}