diff --git a/R/AllGenerics.R b/R/AllGenerics.R index 35c675a..a1f8531 100644 --- a/R/AllGenerics.R +++ b/R/AllGenerics.R @@ -559,21 +559,15 @@ NULL #' plotted? #' @param labels A [`logical`] scalar: should labels be drawn? #' @param map_alpha,map_color,map_shape,map_size A vector specifying the -#' information to be highlighted. -#' It will be mapped to the corresponding aesthetic, according to the -#' corresponding `scale` argument (see examples and vignettes). +#' information to be highlighted. It will be mapped to the corresponding +#' aesthetic (see examples and vignettes). #' If a single `character` string is passed, it must be one of "`observation`", #' "`mass`", "`sum`", "`contribution`" or "`cos2`" (see details). #' Any unambiguous substring can be given. #' If `NULL` (the default), no highlighting is applied. -#' @param scale_color The colors for points. Multiple colors can be -#' specified so that each point can be given its own color. -#' @param scale_shape A vector of plotting characters or symbols. -#' @param scale_size A `numeric` vector giving the amount by which plotting -#' characters and symbols should be scaled relative to the default. #' @param main A [`character`] string giving a main title for the plot. #' @param sub A [`character`] string giving a subtitle for the plot. -#' @param ... Currently not used. +#' @param ... Further [graphical parameters][graphics::par] (see details). #' @details #' Available statistics: #' \describe{ @@ -583,6 +577,16 @@ NULL #' \item{`contribution`}{Joint contributions to the definition of `axes`.} #' \item{`cos2`}{Joint \eqn{cos^2}{cos2} along `axes`.} #' } +#' +#' Commonly used [graphical parameters][graphics::par] are: +#' \describe{ +#' \item{`col`}{The colors for lines and points. Multiple colors can be +#' specified so that each point can be given its own color.} +#' \item{`pch`}{A vector of plotting characters or symbols.} +#' \item{`cex`}{A numerical vector giving the amount by which plotting +#' characters and symbols should be scaled relative to the +#' default.} +#' } #' @return #' `viz_*()` is called for its side-effects: it results in a graphic #' being displayed. Invisibly returns `x`. @@ -615,22 +619,15 @@ setGeneric( #' plotted? #' @param labels A [`logical`] scalar: should labels be drawn? #' @param map_alpha,map_color,map_linetype,map_shape,map_size A vector -#' specifying the information to be highlighted. -#' It will be mapped to the corresponding aesthetic, according to the -#' corresponding `scale` argument (see examples and vignettes). +#' specifying the information to be highlighted. It will be mapped to the +#' corresponding aesthetic (see examples and vignettes). #' If a single `character` string is passed, it must be one of "`observation`", #' "`mass`", "`sum`", "`contribution`" or "`cos2`" (see details). #' Any unambiguous substring can be given. #' If `NULL` (the default), no highlighting is applied. -#' @param scale_color The colors for points. Multiple colors can be -#' specified so that each point can be given its own color. -#' @param scale_linetype A vector of line type specification. -#' @param scale_shape A vector of plotting characters or symbols. -#' @param scale_size A `numeric` vector giving the amount by which plotting -#' characters and symbols should be scaled relative to the default. #' @param main A [`character`] string giving a main title for the plot. #' @param sub A [`character`] string giving a subtitle for the plot. -#' @param ... Currently not used. +#' @param ... Further [graphical parameters][graphics::par] (see details). #' @details #' Available statistics: #' \describe{ @@ -640,6 +637,18 @@ setGeneric( #' \item{`contribution`}{Joint contributions to the definition of `axes`.} #' \item{`cos2`}{Joint \eqn{cos^2}{cos2} along `axes`.} #' } +#' +#' Commonly used [graphical parameters][graphics::par] are: +#' \describe{ +#' \item{`col`}{The colors for lines and points. Multiple colors can be +#' specified so that each point can be given its own color.} +#' \item{`pch`}{A vector of plotting characters or symbols.} +#' \item{`cex`}{A numerical vector giving the amount by which plotting +#' characters and symbols should be scaled relative to the +#' default.} +#' \item{`lty`}{A vector of line types.} +#' \item{`lwd`}{A vector of line widths.} +#' } #' @return #' `viz_*()` is called for its side-effects: it results in a graphic #' being displayed. Invisibly returns `x`. diff --git a/R/biplot.R b/R/biplot.R index c7c4ffd..31ec0f3 100644 --- a/R/biplot.R +++ b/R/biplot.R @@ -12,7 +12,7 @@ setMethod( definition = function(x, axes = c(1, 2), type = c("rows", "columns", "contributions"), active = TRUE, sup = TRUE, - labels = c("rows", "columns"), + labels = "columns", col.rows = "#004488", col.columns = "#BB5566", pch.rows = 16, pch.columns = 17, main = NULL, sub = NULL, ...) { diff --git a/R/dimensio-internal.R b/R/dimensio-internal.R index 7039740..5a8137b 100644 --- a/R/dimensio-internal.R +++ b/R/dimensio-internal.R @@ -6,6 +6,18 @@ `%notin%` <- Negate(`%in%`) +recycle <- function(x, n, verbose = getOption("dimensio.verbose")) { + if (length(x) == n) return(x) + + if (verbose) { + arg <- deparse(substitute(x)) + msg <- sprintf("Note that %s was recycled to length %d.", sQuote(arg), n) + message(msg) + } + x <- rep_len(x, length.out = n) + x +} + #' Weighted Column Means and Standard Deviations #' #' @param x A [`numeric`] matrix. diff --git a/R/viz_coordinates.R b/R/viz_coordinates.R index 0c4288d..4371a64 100644 --- a/R/viz_coordinates.R +++ b/R/viz_coordinates.R @@ -13,16 +13,11 @@ setMethod( labels = FALSE, map_alpha = NULL, map_color = NULL, map_shape = NULL, map_size = NULL, - scale_color = NULL, scale_shape = NULL, - scale_size = NULL, main = NULL, sub = NULL, ...) { viz_points(x, margin = 1, axes = axes, active = active, sup = sup, labels = labels, map_alpha = map_alpha, map_color = map_color, map_shape = map_shape, map_size = map_size, - scale_color = scale_color, - scale_shape = scale_shape, - scale_size = scale_size, main = main, sub = sub, ...) invisible(x) } @@ -34,13 +29,11 @@ setMethod( setMethod( f = "viz_rows", signature = c(x = "BootstrapCA"), - definition = function(x, axes = c(1, 2), scale_color = NULL, - scale_shape = NULL, ...) { + definition = function(x, axes = c(1, 2), ...) { group <- get_groups(x, margin = 1) viz_points(x, margin = 1, axes = axes, active = TRUE, sup = TRUE, labels = FALSE, - map_color = group, scale_color = scale_color, - map_shape = group, scale_shape = scale_shape, ...) + map_color = group, map_shape = group, ...) invisible(x) } ) @@ -55,13 +48,11 @@ setMethod( definition = function(x, axes = c(1, 2), active = TRUE, sup = TRUE, labels = FALSE, map_alpha = NULL, map_color = NULL, map_shape = NULL, map_size = NULL, - scale_color = NULL, scale_shape = NULL, - scale_size = NULL, main = NULL, sub = NULL, ...) { + main = NULL, sub = NULL, ...) { viz_rows(x, axes = axes, active = active, sup = sup, labels = labels, map_alpha = map_alpha, map_color = map_color, map_shape = map_shape, map_size = map_size, - scale_color = scale_color, scale_shape = scale_shape, - scale_size = scale_size, main = main, sub = sub, ...) + main = main, sub = sub, ...) invisible(x) } ) @@ -77,15 +68,11 @@ setMethod( definition = function(x, axes = c(1, 2), active = TRUE, sup = TRUE, labels = FALSE, map_alpha = NULL, map_color = NULL, map_shape = NULL, map_size = NULL, - scale_color = NULL, scale_shape = NULL, - scale_size = NULL, main = NULL, sub = NULL, ...) { + main = NULL, sub = NULL, ...) { viz_points(x, margin = 2, axes = axes, active = active, sup = sup, labels = labels, map_alpha = map_alpha, map_color = map_color, map_shape = map_shape, map_size = map_size, - scale_color = scale_color, - scale_shape = scale_shape, - scale_size = scale_size, main = main, sub = sub, ...) invisible(x) } @@ -97,12 +84,10 @@ setMethod( setMethod( f = "viz_columns", signature = c(x = "BootstrapCA"), - definition = function(x, axes = c(1, 2), scale_color = NULL, - scale_shape = NULL, ...) { + definition = function(x, axes = c(1, 2), ...) { group <- get_groups(x, margin = 2) viz_points(x, margin = 2, axes = axes, active = TRUE, sup = TRUE, - labels = FALSE, map_color = group, scale_color = scale_color, - map_shape = group, scale_shape = scale_shape, ...) + labels = FALSE, map_color = group, map_shape = group, ...) invisible(x) } ) @@ -117,17 +102,16 @@ setMethod( definition = function(x, axes = c(1, 2), active = TRUE, sup = TRUE, labels = TRUE, map_alpha = NULL, map_color = NULL, map_linetype = NULL, map_size = NULL, - scale_color = NULL, scale_linetype = NULL, - scale_size = NULL, main = NULL, sub = NULL, ...) { + main = NULL, sub = NULL, ...) { ## Prepare data coord <- prepare_coord(x, margin = 2, axes = axes, active = active, sup = sup) ## Graphical parameters param <- prepare_param(coord, map_alpha = map_alpha, - map_color = map_color, scale_color = scale_color, - map_linetype = map_linetype, scale_linetype = scale_linetype, - map_size = map_size, scale_size = scale_size) + map_color = map_color, + map_linetype = map_linetype, + map_size = map_size, ...) ## Open new window grDevices::dev.hold() @@ -159,9 +143,8 @@ setMethod( ## Labels if (labels && nrow(coord) > 1) { - usr <- graphics::par("usr") viz_labels(x = coord$x, y = coord$y, labels = coord$label, - xlim = usr[c(1, 2)], ylim = usr[c(3, 4)], col = param$col) + col = param$col) } ## Evaluate post-plot and pre-axis expressions @@ -197,31 +180,25 @@ setMethod( setMethod( f = "viz_variables", signature = c(x = "BootstrapPCA"), - definition = function(x, axes = c(1, 2), scale_color = NULL, - scale_shape = NULL, ...) { + definition = function(x, axes = c(1, 2), ...) { group <- get_groups(x, margin = 2) viz_points(x, margin = 2, axes = axes, active = TRUE, sup = TRUE, - labels = FALSE, map_color = group, scale_color = scale_color, - map_shape = group, scale_shape = scale_shape, ...) + labels = FALSE, map_color = group, map_shape = group, ...) invisible(x) } ) # Helpers ====================================================================== viz_points <- function(x, margin, axes, active = TRUE, sup = TRUE, labels = FALSE, - map_alpha = NULL, map_color = NULL, scale_color = NULL, - map_shape = NULL, scale_shape = NULL, - map_size = NULL, scale_size = NULL, - main = NULL, sub = NULL, ...) { + map_alpha = NULL, map_color = NULL, map_shape = NULL, + map_size = NULL, main = NULL, sub = NULL, ...) { ## Prepare data coord <- prepare_coord(x, margin = margin, axes = axes, active = active, sup = sup) ## Graphical parameters - param <- prepare_param(coord, map_alpha = map_alpha, - map_color = map_color, scale_color = scale_color, - map_shape = map_shape, scale_shape = scale_shape, - map_size = map_size, scale_size = scale_size) + param <- prepare_param(coord, map_alpha = map_alpha, map_color = map_color, + map_shape = map_shape, map_size = map_size, ...) ## Open new window grDevices::dev.hold() @@ -229,8 +206,8 @@ viz_points <- function(x, margin, axes, active = TRUE, sup = TRUE, labels = FALS graphics::plot.new() ## Set plotting coordinates - xlim <- range(coord$x) - ylim <- range(coord$y) + xlim <- range(coord$x, na.rm = TRUE) + ylim <- range(coord$y, na.rm = TRUE) graphics::plot.window(xlim = xlim, ylim = ylim, asp = 1) ## Evaluate pre-plot expressions @@ -244,9 +221,8 @@ viz_points <- function(x, margin, axes, active = TRUE, sup = TRUE, labels = FALS ## Labels if (labels) { - usr <- graphics::par("usr") viz_labels(x = coord$x, y = coord$y, labels = coord$label, - xlim = usr[c(1, 2)], ylim = usr[c(3, 4)], col = param$col, ...) + col = param$col, ...) } ## Evaluate post-plot and pre-axis expressions @@ -339,19 +315,17 @@ prepare_coord <- function(object, margin, axes = c(1, 2), active = TRUE, data } -prepare_param <- function(x, map_alpha = NULL, - map_color = NULL, scale_color = NULL, - map_size = NULL, scale_size = NULL, - map_linetype = NULL, scale_linetype = NULL, - map_shape = NULL, scale_shape = NULL) { +prepare_param <- function(x, map_alpha = NULL, map_color = NULL, + map_size = NULL, map_linetype = NULL, + map_shape = NULL, ...) { n <- nrow(x) ## Graphical parameters - col <- scale_color - pch <- scale_shape - lty <- scale_linetype - cex <- scale_size %||% graphics::par("cex") - lwd <- scale_size %||% graphics::par("lwd") + col <- list(...)$col + pch <- list(...)$pch + lty <- list(...)$lty + cex <- list(...)$cex %||% graphics::par("cex") + lwd <- list(...)$lwd %||% graphics::par("lwd") choices <- c("observation", "mass", "sum", "contribution", "cos2") @@ -371,12 +345,13 @@ prepare_param <- function(x, map_alpha = NULL, } else { ## Discrete scale n_col <- length(unique(map_color)) - if (is.null(col)) col <- grDevices::hcl.colors(n_col, "viridis") - if (length(col) < n_col) assert_length(col, n_col) + if (is.null(col)) + col <- grDevices::hcl.colors(n_col, "viridis") + col <- recycle(col, n_col) col <- col[as.factor(map_color)] } } else { - col <- rep(col %||% graphics::par("col"), n) + col <- rep_len(col %||% graphics::par("col"), n) } if (!is.null(map_alpha)) { @@ -397,10 +372,11 @@ prepare_param <- function(x, map_alpha = NULL, } n_lty <- length(unique(map_linetype)) - if (is.null(lty)) lty <- seq_along(unique(map_linetype)) + if (is.null(lty)) lty <- seq_len(n_lty) + lty <- recycle(lty, n_lty) lty <- lty[as.factor(map_linetype)] } else { - lty <- rep(lty %||% graphics::par("lty"), n) + lty <- rep_len(lty %||% graphics::par("lty"), n) } if (!is.null(map_shape)) { @@ -409,10 +385,12 @@ prepare_param <- function(x, map_alpha = NULL, map_shape <- x[[map_shape]] } - if (is.null(pch)) pch <- seq_along(unique(map_shape)) + n_pch <- length(unique(map_shape)) + if (is.null(pch)) pch <- seq_len(n_pch) + pch <- recycle(pch, n_pch) pch <- pch[as.factor(map_shape)] } else { - pch <- rep(pch %||% graphics::par("pch"), n) + pch <- rep_len(pch %||% graphics::par("pch"), n) } if (!is.null(map_size)) { @@ -424,8 +402,8 @@ prepare_param <- function(x, map_alpha = NULL, cex <- cex + map_size / max(map_size) lwd <- lwd + map_size / max(map_size) } else { - cex <- rep(cex, n) - lwd <- rep(lwd, n) + cex <- rep_len(cex, n) + lwd <- rep_len(lwd, n) } data.frame(col = col, pch = pch, cex = cex, lty = lty, lwd = lwd) diff --git a/R/viz_ellipse.R b/R/viz_ellipse.R index ff97f2f..9be24c5 100644 --- a/R/viz_ellipse.R +++ b/R/viz_ellipse.R @@ -14,6 +14,20 @@ setMethod( } ) +#' @export +#' @rdname viz_wrap +#' @aliases viz_tolerance,BootstrapCA-method +setMethod( + f = "viz_tolerance", + signature = c(x = "BootstrapCA"), + definition = function(x, margin = 1, axes = c(1, 2), level = 0.95, ...) { + group <- get_groups(x, margin = margin) + methods::callNextMethod(x, margin = margin, axes = axes, group = group, + level = level, ...) + invisible(x) + } +) + #' @export #' @rdname viz_wrap #' @aliases viz_confidence,MultivariateAnalysis-method @@ -26,6 +40,20 @@ setMethod( } ) +#' @export +#' @rdname viz_wrap +#' @aliases viz_confidence,BootstrapCA-method +setMethod( + f = "viz_confidence", + signature = c(x = "BootstrapCA"), + definition = function(x, margin = 1, axes = c(1, 2), level = 0.95, ...) { + group <- get_groups(x, margin = margin) + methods::callNextMethod(x, margin = margin, axes = axes, group = group, + level = level, ...) + invisible(x) + } +) + .viz_ellipse <- function(x, type = c("tolerance", "confidence"), level = 0.95, margin = 1, axes = c(1, 2), group = NULL, ...) { fun <- switch( diff --git a/R/viz_hull.R b/R/viz_hull.R index e9574aa..716645f 100644 --- a/R/viz_hull.R +++ b/R/viz_hull.R @@ -30,3 +30,16 @@ setMethod( invisible(x) } ) + +#' @export +#' @rdname viz_wrap +#' @aliases viz_hull,BootstrapCA-method +setMethod( + f = "viz_hull", + signature = c(x = "BootstrapCA"), + definition = function(x, margin = 1, axes = c(1, 2), ...) { + group <- get_groups(x, margin = margin) + methods::callNextMethod(x, margin = margin, axes = axes, group = group, ...) + invisible(x) + } +) diff --git a/R/wrap_ellipses.R b/R/wrap_ellipses.R index 1f20d69..59eed44 100644 --- a/R/wrap_ellipses.R +++ b/R/wrap_ellipses.R @@ -72,6 +72,10 @@ setMethod( lapply( X = data, FUN = function(x, level) { + ## Drop NAs + x <- stats::na.omit(x) + if (nrow(x) < 3) return(NULL) + df <- ncol(x) - 1 radius <- sqrt(stats::qchisq(p = level, df = df)) wrap_ellipse(x[, 1], x[, 2], radius = radius) diff --git a/R/wrap_hull.R b/R/wrap_hull.R index 8203b71..2f462eb 100644 --- a/R/wrap_hull.R +++ b/R/wrap_hull.R @@ -29,6 +29,10 @@ setMethod( lapply( X = data, FUN = function(x) { + ## Drop NAs + x <- stats::na.omit(x) + if (nrow(x) == 0) return(NULL) + i <- grDevices::chull(x[, c(1, 2)]) x[c(i, i[1]), , drop = FALSE] } diff --git a/README.Rmd b/README.Rmd index a9bf0e2..e8c025e 100644 --- a/README.Rmd +++ b/README.Rmd @@ -113,8 +113,8 @@ biplot(X, type = "form") viz_individuals( x = X, map_color = iris$Species, - scale_color = khroma::color("high contrast")(3), - scale_shape = 16 + col = khroma::color("high contrast")(3), + pch = 16 ) ## Add ellipses viz_tolerance( @@ -129,8 +129,8 @@ viz_individuals( x = X, map_color = iris$Petal.Length, map_size = iris$Petal.Length, - scale_color = khroma::color("iridescent")(255), - scale_shape = 16 + col = khroma::color("iridescent")(255), + pch = 16 ) ``` diff --git a/README.md b/README.md index 0e1e31d..83ef10e 100644 --- a/README.md +++ b/README.md @@ -157,8 +157,8 @@ biplot(X, type = "form") viz_individuals( x = X, map_color = iris$Species, - scale_color = khroma::color("high contrast")(3), - scale_shape = 16 + col = khroma::color("high contrast")(3), + pch = 16 ) ## Add ellipses viz_tolerance( @@ -173,8 +173,8 @@ viz_individuals( x = X, map_color = iris$Petal.Length, map_size = iris$Petal.Length, - scale_color = khroma::color("iridescent")(255), - scale_shape = 16 + col = khroma::color("iridescent")(255), + pch = 16 ) ``` diff --git a/inst/examples/ex-plot.R b/inst/examples/ex-plot.R index b1a205f..f59d38e 100644 --- a/inst/examples/ex-plot.R +++ b/inst/examples/ex-plot.R @@ -9,8 +9,7 @@ viz_individuals(X, map_color = iris$Species, map_shape = iris$Species) viz_individuals(X, map_color = iris$Sepal.Width, map_size = "cos2") -viz_individuals(X, map_color = "contribution", map_size = "contribution", - scale_shape = 16) +viz_individuals(X, map_color = "contrib", map_size = "contrib", pch = 16) ## Plot variables viz_variables(X) diff --git a/inst/examples/ex-wrap.R b/inst/examples/ex-wrap.R index af0b735..1b0e1b2 100644 --- a/inst/examples/ex-wrap.R +++ b/inst/examples/ex-wrap.R @@ -16,5 +16,5 @@ conf <- wrap_confidence(X, margin = 1, group = iris$Species, level = 0.95) ## Plot with convex hulls col <- c(blue = "#004488", yellow = "#DDAA33", red = "#BB5566") -viz_rows(X, map_color = iris$Species, scale_color = col) +viz_rows(X, map_color = iris$Species, col = col) viz_hull(X, group = iris$Species, border = col) diff --git a/man/biplot.Rd b/man/biplot.Rd index 7356755..0437292 100644 --- a/man/biplot.Rd +++ b/man/biplot.Rd @@ -13,7 +13,7 @@ type = c("rows", "columns", "contributions"), active = TRUE, sup = TRUE, - labels = c("rows", "columns"), + labels = "columns", col.rows = "#004488", col.columns = "#BB5566", pch.rows = 16, diff --git a/man/figures/README-biplot-1.png b/man/figures/README-biplot-1.png index 08bccb9..7fa35eb 100644 Binary files a/man/figures/README-biplot-1.png and b/man/figures/README-biplot-1.png differ diff --git a/man/figures/README-plot-var-1.png b/man/figures/README-plot-var-1.png index b48df2c..ff3c19d 100644 Binary files a/man/figures/README-plot-var-1.png and b/man/figures/README-plot-var-1.png differ diff --git a/man/viz_individuals.Rd b/man/viz_individuals.Rd index 8dfe0ce..67e860a 100644 --- a/man/viz_individuals.Rd +++ b/man/viz_individuals.Rd @@ -25,15 +25,12 @@ viz_rows(x, ...) map_color = NULL, map_shape = NULL, map_size = NULL, - scale_color = NULL, - scale_shape = NULL, - scale_size = NULL, main = NULL, sub = NULL, ... ) -\S4method{viz_rows}{BootstrapCA}(x, axes = c(1, 2), scale_color = NULL, scale_shape = NULL, ...) +\S4method{viz_rows}{BootstrapCA}(x, axes = c(1, 2), ...) \S4method{viz_individuals}{PCA}( x, @@ -45,9 +42,6 @@ viz_rows(x, ...) map_color = NULL, map_shape = NULL, map_size = NULL, - scale_color = NULL, - scale_shape = NULL, - scale_size = NULL, main = NULL, sub = NULL, ... @@ -56,7 +50,7 @@ viz_rows(x, ...) \arguments{ \item{x}{A \code{\linkS4class{CA}} or \code{\linkS4class{PCA}} object.} -\item{...}{Currently not used.} +\item{...}{Further \link[graphics:par]{graphical parameters} (see details).} \item{axes}{A length-two \code{\link{numeric}} vector giving the dimensions to be plotted.} @@ -70,22 +64,13 @@ plotted?} \item{labels}{A \code{\link{logical}} scalar: should labels be drawn?} \item{map_alpha, map_color, map_shape, map_size}{A vector specifying the -information to be highlighted. -It will be mapped to the corresponding aesthetic, according to the -corresponding \code{scale} argument (see examples and vignettes). +information to be highlighted. It will be mapped to the corresponding +aesthetic (see examples and vignettes). If a single \code{character} string is passed, it must be one of "\code{observation}", "\code{mass}", "\code{sum}", "\code{contribution}" or "\code{cos2}" (see details). Any unambiguous substring can be given. If \code{NULL} (the default), no highlighting is applied.} -\item{scale_color}{The colors for points. Multiple colors can be -specified so that each point can be given its own color.} - -\item{scale_shape}{A vector of plotting characters or symbols.} - -\item{scale_size}{A \code{numeric} vector giving the amount by which plotting -characters and symbols should be scaled relative to the default.} - \item{main}{A \code{\link{character}} string giving a main title for the plot.} \item{sub}{A \code{\link{character}} string giving a subtitle for the plot.} @@ -106,6 +91,16 @@ Available statistics: \item{\code{contribution}}{Joint contributions to the definition of \code{axes}.} \item{\code{cos2}}{Joint \eqn{cos^2}{cos2} along \code{axes}.} } + +Commonly used \link[graphics:par]{graphical parameters} are: +\describe{ +\item{\code{col}}{The colors for lines and points. Multiple colors can be +specified so that each point can be given its own color.} +\item{\code{pch}}{A vector of plotting characters or symbols.} +\item{\code{cex}}{A numerical vector giving the amount by which plotting +characters and symbols should be scaled relative to the +default.} +} } \examples{ ## Load data @@ -119,8 +114,7 @@ viz_individuals(X, map_color = iris$Species, map_shape = iris$Species) viz_individuals(X, map_color = iris$Sepal.Width, map_size = "cos2") -viz_individuals(X, map_color = "contribution", map_size = "contribution", - scale_shape = 16) +viz_individuals(X, map_color = "contrib", map_size = "contrib", pch = 16) ## Plot variables viz_variables(X) diff --git a/man/viz_variables.Rd b/man/viz_variables.Rd index df59783..6d7581b 100644 --- a/man/viz_variables.Rd +++ b/man/viz_variables.Rd @@ -26,15 +26,12 @@ viz_columns(x, ...) map_color = NULL, map_shape = NULL, map_size = NULL, - scale_color = NULL, - scale_shape = NULL, - scale_size = NULL, main = NULL, sub = NULL, ... ) -\S4method{viz_columns}{BootstrapCA}(x, axes = c(1, 2), scale_color = NULL, scale_shape = NULL, ...) +\S4method{viz_columns}{BootstrapCA}(x, axes = c(1, 2), ...) \S4method{viz_variables}{PCA}( x, @@ -46,20 +43,17 @@ viz_columns(x, ...) map_color = NULL, map_linetype = NULL, map_size = NULL, - scale_color = NULL, - scale_linetype = NULL, - scale_size = NULL, main = NULL, sub = NULL, ... ) -\S4method{viz_variables}{BootstrapPCA}(x, axes = c(1, 2), scale_color = NULL, scale_shape = NULL, ...) +\S4method{viz_variables}{BootstrapPCA}(x, axes = c(1, 2), ...) } \arguments{ \item{x}{A \code{\linkS4class{CA}} or \code{\linkS4class{PCA}} object.} -\item{...}{Currently not used.} +\item{...}{Further \link[graphics:par]{graphical parameters} (see details).} \item{axes}{A length-two \code{\link{numeric}} vector giving the dimensions to be plotted.} @@ -73,27 +67,16 @@ plotted?} \item{labels}{A \code{\link{logical}} scalar: should labels be drawn?} \item{map_alpha, map_color, map_linetype, map_shape, map_size}{A vector -specifying the information to be highlighted. -It will be mapped to the corresponding aesthetic, according to the -corresponding \code{scale} argument (see examples and vignettes). +specifying the information to be highlighted. It will be mapped to the +corresponding aesthetic (see examples and vignettes). If a single \code{character} string is passed, it must be one of "\code{observation}", "\code{mass}", "\code{sum}", "\code{contribution}" or "\code{cos2}" (see details). Any unambiguous substring can be given. If \code{NULL} (the default), no highlighting is applied.} -\item{scale_color}{The colors for points. Multiple colors can be -specified so that each point can be given its own color.} - -\item{scale_shape}{A vector of plotting characters or symbols.} - -\item{scale_size}{A \code{numeric} vector giving the amount by which plotting -characters and symbols should be scaled relative to the default.} - \item{main}{A \code{\link{character}} string giving a main title for the plot.} \item{sub}{A \code{\link{character}} string giving a subtitle for the plot.} - -\item{scale_linetype}{A vector of line type specification.} } \value{ \verb{viz_*()} is called for its side-effects: it results in a graphic @@ -111,6 +94,18 @@ Available statistics: \item{\code{contribution}}{Joint contributions to the definition of \code{axes}.} \item{\code{cos2}}{Joint \eqn{cos^2}{cos2} along \code{axes}.} } + +Commonly used \link[graphics:par]{graphical parameters} are: +\describe{ +\item{\code{col}}{The colors for lines and points. Multiple colors can be +specified so that each point can be given its own color.} +\item{\code{pch}}{A vector of plotting characters or symbols.} +\item{\code{cex}}{A numerical vector giving the amount by which plotting +characters and symbols should be scaled relative to the +default.} +\item{\code{lty}}{A vector of line types.} +\item{\code{lwd}}{A vector of line widths.} +} } \examples{ ## Load data @@ -124,8 +119,7 @@ viz_individuals(X, map_color = iris$Species, map_shape = iris$Species) viz_individuals(X, map_color = iris$Sepal.Width, map_size = "cos2") -viz_individuals(X, map_color = "contribution", map_size = "contribution", - scale_shape = 16) +viz_individuals(X, map_color = "contrib", map_size = "contrib", pch = 16) ## Plot variables viz_variables(X) diff --git a/man/viz_wrap.Rd b/man/viz_wrap.Rd index ecd911c..ba1512a 100644 --- a/man/viz_wrap.Rd +++ b/man/viz_wrap.Rd @@ -10,8 +10,11 @@ \alias{viz_tolerance} \alias{viz_tolerance-method} \alias{viz_tolerance,MultivariateAnalysis-method} +\alias{viz_tolerance,BootstrapCA-method} \alias{viz_confidence,MultivariateAnalysis-method} +\alias{viz_confidence,BootstrapCA-method} \alias{viz_hull,MultivariateAnalysis-method} +\alias{viz_hull,BootstrapCA-method} \title{Plot Envelopes} \usage{ viz_hull(x, ...) @@ -22,9 +25,15 @@ viz_tolerance(x, ...) \S4method{viz_tolerance}{MultivariateAnalysis}(x, margin = 1, axes = c(1, 2), group = NULL, level = 0.95, ...) +\S4method{viz_tolerance}{BootstrapCA}(x, margin = 1, axes = c(1, 2), level = 0.95, ...) + \S4method{viz_confidence}{MultivariateAnalysis}(x, margin = 1, axes = c(1, 2), group = NULL, level = 0.95, ...) +\S4method{viz_confidence}{BootstrapCA}(x, margin = 1, axes = c(1, 2), level = 0.95, ...) + \S4method{viz_hull}{MultivariateAnalysis}(x, margin = 1, axes = c(1, 2), group = NULL, ...) + +\S4method{viz_hull}{BootstrapCA}(x, margin = 1, axes = c(1, 2), ...) } \arguments{ \item{x}{An object from which to wrap observations (a \code{\linkS4class{CA}} or @@ -70,7 +79,7 @@ conf <- wrap_confidence(X, margin = 1, group = iris$Species, level = 0.95) ## Plot with convex hulls col <- c(blue = "#004488", yellow = "#DDAA33", red = "#BB5566") -viz_rows(X, map_color = iris$Species, scale_color = col) +viz_rows(X, map_color = iris$Species, col = col) viz_hull(X, group = iris$Species, border = col) } \seealso{ diff --git a/man/wrap.Rd b/man/wrap.Rd index 81964e6..8b4aff1 100644 --- a/man/wrap.Rd +++ b/man/wrap.Rd @@ -75,7 +75,7 @@ conf <- wrap_confidence(X, margin = 1, group = iris$Species, level = 0.95) ## Plot with convex hulls col <- c(blue = "#004488", yellow = "#DDAA33", red = "#BB5566") -viz_rows(X, map_color = iris$Species, scale_color = col) +viz_rows(X, map_color = iris$Species, col = col) viz_hull(X, group = iris$Species, border = col) } \seealso{ diff --git a/vignettes/pca.Rmd b/vignettes/pca.Rmd index 2def2f1..9376be5 100644 --- a/vignettes/pca.Rmd +++ b/vignettes/pca.Rmd @@ -107,7 +107,7 @@ viz_variables(X) viz_variables( x = X, map_color = "cos2", - scale_color = khroma::color("YlOrBr")(12) + col = khroma::color("YlOrBr")(12) ) ``` @@ -121,8 +121,8 @@ viz_individuals( x = X, map_color = iris$Species, map_shape = iris$Species, - scale_color = khroma::color("bright")(3), # Custom color scale - scale_shape = c(15, 16, 17) # Custom symbols + col = khroma::color("bright")(3), # Custom color scale + pch = c(15, 16, 17) # Custom symbols ) ``` @@ -143,8 +143,8 @@ viz_hull(x = X, group = iris$Species, level = 0.95, viz_individuals( x = X, map_color = iris$Petal.Length, - scale_color = khroma::color("YlOrBr")(12), # Custom color scale - scale_shape = 16 + col = khroma::color("YlOrBr")(12), # Custom color scale + pch = 16 ) ``` @@ -154,8 +154,8 @@ viz_individuals( x = X, map_color = "contrib", map_size = "contrib", - scale_color = khroma::color("iridescent")(12), # Custom color scale - scale_shape = 16 + col = khroma::color("iridescent")(12), # Custom color scale + pch = 16 ) ```