Skip to content

Commit

Permalink
Fix graphical parameters (again)
Browse files Browse the repository at this point in the history
  • Loading branch information
nfrerebeau committed Aug 23, 2023
1 parent 2aa06ec commit 0b502ce
Show file tree
Hide file tree
Showing 25 changed files with 790 additions and 926 deletions.
76 changes: 29 additions & 47 deletions R/AllGenerics.R
Original file line number Diff line number Diff line change
Expand Up @@ -560,38 +560,40 @@ NULL
#' @param sup A [`logical`] scalar: should the supplementary observations be
#' plotted?
#' @param labels A [`logical`] scalar: should labels be drawn?
#' @param map_color,map_shape,map_size A vector specifying the
#' information to be highlighted. It will be mapped to the corresponding
#' aesthetic (see examples and vignettes).
#' @param highlight A vector specifying the information to be highlighted.
#' If `NULL` (the default), no highlighting is applied.
#' It will only be mapped if at least one [graphical parameters][graphics::par]
#' is explicitly specified (see examples).
#' If a single `character` string is passed, it must be one of "`observation`",
#' "`mass`", "`sum`", "`contribution`" or "`cos2`" (see details).
#' "`mass`", "`sum`", "`contribution`" or "`cos2`" (see [`augment()`]).
#' Any unambiguous substring can be given.
#' If `NULL` (the default), no highlighting is applied.
#' @param main A [`character`] string giving a main title for the plot.
#' @param sub A [`character`] string giving a subtitle for the plot.
#' @param panel.first An an `expression` to be evaluated after the plot axes are
#' set up but before any plotting takes place. This can be useful for drawing
#' background grids.
#' @param panel.last An `expression` to be evaluated after plotting has taken
#' place but before the axes, title and box are added.
#' @param ... Further [graphical parameters][graphics::par] (see details).
#' @details
#' Available statistics:
#' \describe{
#' \item{`observation`}{Whether an observation is active or supplementary.}
#' \item{`mass`}{Weight/mass of each observation.}
#' \item{`sum`}{Sum of squared coordinates along `axes`.}
#' \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{`pch`}{A vector of plotting characters or symbols. This can either be
#' a single character or an integer code for one of a set of
#' graphics symbols.}
#' \item{`cex`}{A numerical vector giving the amount by which plotting
#' characters and symbols should be scaled relative to the
#' default.}
#' \item{`col`}{The colors for lines and points. Multiple colors can be
#' specified so that each point can be given its own color.}
#' \item{`bg`}{The background color for the open plot symbols given by
#' `pch = 21:25`.}
#' }
#' @return
#' `viz_*()` is called for its side-effects: it results in a graphic
#' being displayed. Invisibly returns `x`.
#' @note
#' Be careful: graphical parameters are silently recycled.
#' @example inst/examples/ex-plot.R
#' @author N. Frerebeau
#' @docType methods
Expand All @@ -612,48 +614,28 @@ setGeneric(
#' Visualize Variables Factor Map
#'
#' Plots column/variable principal coordinates.
#' @param x A [`CA-class`] or [`PCA-class`] object.
#' @param axes A length-two [`numeric`] vector giving the dimensions to be
#' plotted.
#' @param active A [`logical`] scalar: should the active observations be
#' plotted?
#' @param sup A [`logical`] scalar: should the supplementary observations be
#' plotted?
#' @param labels A [`logical`] scalar: should labels be drawn?
#' @param map_color,map_shape,map_size,map_linetype,map_linewidth A vector
#' 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 main A [`character`] string giving a main title for the plot.
#' @param sub A [`character`] string giving a subtitle for the plot.
#' @param ... Further [graphical parameters][graphics::par] (see details).
#' @inheritParams viz_individuals
#' @details
#' Available statistics:
#' \describe{
#' \item{`observation`}{Whether an observation is active or supplementary.}
#' \item{`mass`}{Weight/mass of each observation.}
#' \item{`sum`}{Sum of squared coordinates along `axes`.}
#' \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{`pch`}{A vector of plotting characters or symbols. This can either be
#' a single character or an integer code for one of a set of
#' graphics 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.}
#' \item{`col`}{The colors for lines and points. Multiple colors can be
#' specified so that each point can be given its own color.}
#' \item{`bg`}{The background color for the open plot symbols given by
#' `pch = 21:25`.}
#' }
#' @return
#' `viz_*()` is called for its side-effects: it results in a graphic
#' being displayed. Invisibly returns `x`.
#' @note
#' Be careful: graphical parameters are silently recycled.
#' @example inst/examples/ex-plot.R
#' @author N. Frerebeau
#' @docType methods
Expand Down
7 changes: 2 additions & 5 deletions R/biplot.R
Original file line number Diff line number Diff line change
Expand Up @@ -170,18 +170,15 @@ viz_biplot <- function(coord_row, coord_col, rows = TRUE, columns = TRUE,
}

## Labels
usr <- graphics::par("usr")
xlim <- usr[c(1, 2)]
ylim <- usr[c(3, 4)]
if (!is.null(labels)) {
labels <- match.arg(labels, several.ok = TRUE)
if (any(labels == "rows") | any(labels == "individuals")) {
viz_labels(x = coord_row$x, y = coord_row$y, labels = coord_row$label,
xlim = xlim, ylim = ylim, col = col.rows, ...)
col = col.rows, ...)
}
if (any(labels == "columns") | any(labels == "variables")) {
viz_labels(x = coord_col$x, y = coord_col$y, labels = coord_col$label,
xlim = xlim, ylim = ylim, col = col.columns, ...)
col = col.columns, ...)
}
}

Expand Down
16 changes: 15 additions & 1 deletion R/dimensio-internal.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
recycle <- function(x, n, verbose = getOption("dimensio.verbose")) {
if (length(x) >= n) return(x[seq_len(n)])

if (verbose) {
if (verbose && length(x) > 1) {
arg <- deparse(substitute(x))
msg <- sprintf("Note that %s was recycled to length %d.", sQuote(arg), n)
message(msg)
Expand All @@ -16,6 +16,20 @@ recycle <- function(x, n, verbose = getOption("dimensio.verbose")) {
x
}

#' Rescale Continuous Vector
#'
#' Rescales continuous vector to have specified minimum and maximum.
#' @param x A continuous `vector` of values to manipulate.
#' @param to A length-two [`numeric`] vector specifying the output range.
#' @param from A length-two [`numeric`] vector specifying the input range.
#' @return A [`numeric`] vector.
#' @keywords internal
#' @noRd
scale_range <- function(x, to = c(0, 1),
from = range(x, na.rm = TRUE, finite = TRUE)) {
(x - from[1L]) / diff(from) * diff(to) + to[1L]
}

#' Weighted Column Means and Standard Deviations
#'
#' @param x A [`numeric`] matrix.
Expand Down
Loading

0 comments on commit 0b502ce

Please sign in to comment.