Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: use roxygen markdown #914

Merged
merged 3 commits into from
Apr 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@
- Color palette functions now support reversing the order in which colors are
used, via reverse=TRUE.

- `colorFactor` no longer interpolates qualitative RColorBrewer palettes,
- `colorFactor()` no longer interpolates qualitative RColorBrewer palettes,
unless the number of factor levels being mapped exceeds the number of colors
in the specified RColorBrewer palette. (Issue #300)

Expand Down
70 changes: 34 additions & 36 deletions R/colors.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,35 @@
#' Conveniently maps data values (numeric or factor/character) to colors
#' according to a given palette, which can be provided in a variety of formats.
#'
#' \code{colorNumeric} is a simple linear mapping from continuous numeric data
#' `colorNumeric()` is a simple linear mapping from continuous numeric data
#' to an interpolated palette.
#'
#' @param palette The colors or color function that values will be mapped to
#' @param domain The possible values that can be mapped.
#'
#' For \code{colorNumeric} and \code{colorBin}, this can be a simple numeric
#' range (e.g. \code{c(0, 100)}); \code{colorQuantile} needs representative
#' numeric data; and \code{colorFactor} needs categorical data.
#' For `colorNumeric()` and `colorBin()`, this can be a simple numeric
#' range (e.g. `c(0, 100)`); `colorQuantile()` needs representative
#' numeric data; and `colorFactor()` needs categorical data.
#'
#' If \code{NULL}, then whenever the resulting color function is called, the
#' \code{x} value will represent the domain. This implies that if the function
#' If `NULL`, then whenever the resulting color function is called, the
#' `x` value will represent the domain. This implies that if the function
#' is invoked multiple times, the encoding between values and colors may not
#' be consistent; if consistency is needed, you must provide a non-\code{NULL}
#' be consistent; if consistency is needed, you must provide a non-`NULL`
#' domain.
#' @param na.color The color to return for \code{NA} values. Note that
#' \code{na.color = NA} is valid.
#' @param na.color The color to return for `NA` values. Note that
#' `na.color = NA` is valid.
#' @param alpha Whether alpha channels should be respected or ignored. If
#' \code{TRUE} then colors without explicit alpha information will be treated
#' `TRUE` then colors without explicit alpha information will be treated
#' as fully opaque.
#' @param reverse Whether the colors (or color function) in \code{palette}
#' @param reverse Whether the colors (or color function) in `palette`
#' should be used in reverse order. For example, if the default order of a
#' palette goes from blue to green, then \code{reverse = TRUE} will result in
#' palette goes from blue to green, then `reverse = TRUE` will result in
#' the colors going from green to blue.
#'
#' @return A function that takes a single parameter \code{x}; when called with a
#' vector of numbers (except for \code{colorFactor}, which expects
#' @return A function that takes a single parameter `x`; when called with a
#' vector of numbers (except for `colorFactor()`, which expects
#' factors/characters), #RRGGBB color strings are returned (unless
#' \code{alpha = TRUE} in which case #RRGGBBAA may also be possible).
#' `alpha = TRUE` in which case #RRGGBBAA may also be possible).
#'
#' @export
colorNumeric <- function(palette, domain, na.color = "#808080", alpha = FALSE, reverse = FALSE) {
Expand Down Expand Up @@ -93,17 +93,17 @@ getBins <- function(domain, x, bins, pretty) {
}
}

#' @details \code{colorBin} also maps continuous numeric data, but performs
#' binning based on value (see the \code{\link[base]{cut}} function). \code{colorBin}
#' defaults for the \code{\link[base]{cut}} function are \code{include.lowest
#' = TRUE} and \code{right = FALSE}.
#' @details `colorBin()` also maps continuous numeric data, but performs
#' binning based on value (see the [base::cut()] function). `colorBin()`
#' defaults for the [base::cut()] function are `include.lowest
#' = TRUE` and `right = FALSE`.
#' @param bins Either a numeric vector of two or more unique cut points or a
#' single number (greater than or equal to 2) giving the number of intervals
#' into which the domain values are to be cut.
#' @param pretty Whether to use the function \code{\link{pretty}()} to generate
#' the bins when the argument \code{bins} is a single number. When
#' \code{pretty = TRUE}, the actual number of bins may not be the number of
#' bins you specified. When \code{pretty = FALSE}, \code{\link{seq}()} is used
#' @param pretty Whether to use the function [pretty()] to generate
#' the bins when the argument `bins` is a single number. When
#' `pretty = TRUE`, the actual number of bins may not be the number of
#' bins you specified. When `pretty = FALSE`, [seq()] is used
#' to generate the bins and the breaks may not be "pretty".
#' @param right parameter supplied to cut. See Details
#' @rdname colorNumeric
Expand Down Expand Up @@ -136,12 +136,10 @@ colorBin <- function(palette, domain, bins = 7, pretty = TRUE,
})
}

#' @details \code{colorQuantile} similarly bins numeric data, but via the
#' \code{\link[stats]{quantile}} function.
#' @details `colorQuantile()` similarly bins numeric data, but via [stats::quantile()].
#' @param n Number of equal-size quantiles desired. For more precise control,
#' use the \code{probs} argument instead.
#' @param probs See \code{\link[stats]{quantile}}. If provided, the \code{n}
#' argument is ignored.
#' use `probs` instead.
#' @param probs See [stats::quantile()]. If provided, `n` is ignored.
#' @rdname colorNumeric
#' @export
colorQuantile <- function(palette, domain, n = 4,
Expand Down Expand Up @@ -199,12 +197,12 @@ getLevels <- function(domain, x, lvls, ordered) {
}
}

#' @details \code{colorFactor} maps factors to colors. If the palette is
#' @details `colorFactor()` maps factors to colors. If the palette is
#' discrete and has a different number of colors than the number of factors,
#' interpolation is used.
#' @param levels An alternate way of specifying levels; if specified, domain is
#' ignored
#' @param ordered If \code{TRUE} and \code{domain} needs to be coerced to a
#' @param ordered If `TRUE` and `domain` needs to be coerced to a
#' factor, treat it as already in the correct order
#' @rdname colorNumeric
#' @export
Expand Down Expand Up @@ -249,12 +247,12 @@ colorFactor <- function(palette, domain, levels = NULL, ordered = FALSE,
})
}

#' @details The \code{palette} argument can be any of the following:
#' @details The `palette` argument can be any of the following:
#' \enumerate{
#' \item{A character vector of RGB or named colors. Examples: \code{palette()}, \code{c("#000000", "#0000FF", "#FFFFFF")}, \code{topo.colors(10)}}
#' \item{The name of an RColorBrewer palette, e.g. \code{"BuPu"} or \code{"Greens"}.}
#' \item{The full name of a viridis palette: \code{"viridis"}, \code{"magma"}, \code{"inferno"}, or \code{"plasma"}.}
#' \item{A function that receives a single value between 0 and 1 and returns a color. Examples: \code{colorRamp(c("#000000", "#FFFFFF"), interpolate = "spline")}.}
#' \item{A character vector of RGB or named colors. Examples: `palette()`, `c("#000000", "#0000FF", "#FFFFFF")`, `topo.colors(10)`}
#' \item{The name of an RColorBrewer palette, e.g. `"BuPu"` or `"Greens"`.}
#' \item{The full name of a viridis palette: `"viridis"`, `"magma"`, `"inferno"`, or `"plasma"`.}
#' \item{A function that receives a single value between 0 and 1 and returns a color. Examples: `colorRamp(c("#000000", "#FFFFFF"), interpolate = "spline")`.}
#' }
#' @examples
#' pal <- colorBin("Greens", domain = 0:100)
Expand Down Expand Up @@ -355,7 +353,7 @@ toPaletteFunc.function <- function(pal, alpha, nlevels) {

#' Color previewing utility
#'
#' @param pal A color mapping function, like those returned from \code{\link{colorNumeric}}, et al
#' @param pal A color mapping function, like those returned from [colorNumeric()], et al
#' @param values A set of values to preview colors for
#' @return An HTML-based list of the colors and values
#' @export
Expand Down
4 changes: 2 additions & 2 deletions R/controls.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#' @param html the content of the control. May be provided as string or as HTML
#' generated with Shiny/htmltools tags
#' @param position position of control: "topleft", "topright", "bottomleft", or
#' "bottomright"
#' @param position position of control: `"topleft"`, `"topright"`,
#' `"bottomleft"`, or `"bottomright"`.
#' @param className extra CSS classes to append to the control, space separated
#'
#' @describeIn map-layers Add arbitrary HTML controls to the map
Expand Down
20 changes: 10 additions & 10 deletions R/data.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
#' Intercensal estimates of the resident population for Incorporated Places and
#' Minor Civil Divisions: April 1, 2000 to July 1, 2010.
#' @docType data
#' @format A data frame containing \code{City}, \code{State}, \code{Lat},
#' \code{Long}, and population estimates from 2000 to 2010 (columns
#' \code{Pop2000} to \code{Pop2010}).
#' @format A data frame containing `City`, `State`, `Lat`,
#' `Long`, and population estimates from 2000 to 2010 (columns
#' `Pop2000` to `Pop2010`).
#' @source The US Census Bureau:
#' \url{https://www.census.gov/data/datasets/time-series/demo/popest/intercensal-2000-2010-cities-and-towns.html}
#' <https://www.census.gov/data/datasets/time-series/demo/popest/intercensal-2000-2010-cities-and-towns.html>
#' @noRd
#' @examples
#' str(uspop2000)
Expand All @@ -31,18 +31,18 @@ if (file.exists("inst/csv/uspop2000.csv")) {
#' @description Atlantic Ocean storms 2005
#' @details This dataset contains storm tracks for selected storms
#' in the Atlantic Ocean basin for the year 2005
#' @format \code{sp::SpatialLinesDataFrame}
#' @format `sp::SpatialLinesDataFrame`
NULL

#' @docType data
#' @name gadmCHE
#' @title Administrative borders of Switzerland (level 1)
#' @description Administrative borders of Switzerland (level 1)
#' @details This dataset comes from \url{https://gadm.org}.
#' It was downloaded using \code{\link{getData}}.
#' @format \code{sp::SpatialPolygonsDataFrame}
#' @details This dataset comes from <https://gadm.org>.
#' It was downloaded using [getData()].
#' @format `sp::SpatialPolygonsDataFrame`
#' @source
#' \url{https://gadm.org}
#' <https://gadm.org>
NULL

#'
Expand All @@ -54,5 +54,5 @@ NULL
#' subset of a larger database that was compiled by students at the
#' University of Marburg for a seminar called
#' "The Geography of Beer, sustainability in the food industry"
#' @format \code{sp::SpatialPointsDataFrame}
#' @format `sp::SpatialPointsDataFrame`
NULL
Loading