From fa8ca6a389245e7afd81f6de6f7438b8e6c1ea3d Mon Sep 17 00:00:00 2001 From: edzer Date: Thu, 17 Aug 2023 14:47:25 +0200 Subject: [PATCH] st_rgb docs; #641 --- R/plot.R | 25 ++++++++++++------------- man/st_rgb.Rd | 3 ++- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/R/plot.R b/R/plot.R index a28af5b13..f4d610885 100644 --- a/R/plot.R +++ b/R/plot.R @@ -536,7 +536,8 @@ contour.stars = function(x, ...) { #' @param probs probability values for quantiles used for stretching by "percent". #' @seealso \link{st_apply}, \link[grDevices]{rgb} #' @details the dimension's bands are mapped to red, green, blue, alpha; if a different -#' ordering is wanted, use \link{[.stars} to reorder a dimension, see examples +#' ordering is wanted, use \link{[.stars} to reorder a dimension, see examples. +#' Alternatively, you can use \link{plot.stars} with the \code{rgb} argument to create a three-band composition. #' @examples #' tif = system.file("tif/L7_ETMs.tif", package = "stars") #' x = read_stars(tif) @@ -553,7 +554,7 @@ contour.stars = function(x, ...) { #' probs = c(0.01, 0.99), #' stretch = "histogram") #' plot(r) -st_rgb <- function (x, +st_rgb = function (x, dimension = 3, use_alpha = dim(x)[dimension] == 4, maxColorValue = 255L, @@ -573,7 +574,7 @@ st_rgb <- function (x, "should be 3 or 4")) dims = setdiff(seq_along(dim(x)), dimension) cutoff = function(x, probs, stretch.method = "percent") { - if(stretch.method == "percent"){ + if (stretch.method == "percent"){ qs = if (all(probs == c(0, 1))) range(x) else quantile(x, probs, na.rm = TRUE) @@ -590,29 +591,27 @@ st_rgb <- function (x, } } - if(is.null(stretch)) { + if (is.null(stretch)) { stretch.method = "none" stretch = FALSE } - if(is.logical(stretch)) { - if(stretch){ + if (is.logical(stretch)) { + if(stretch) stretch.method = "percent" - } else { + else maxColorValue = max(maxColorValue, max(x[[1]], na.rm = TRUE)) - } } - if(is.character(stretch)) { - if(!stretch %in% c("percent", "histogram")){ + if (is.character(stretch)) { + if (!stretch %in% c("percent", "histogram")) stretch.method = "percent" - } else { + else stretch.method = stretch - } stretch = TRUE } - if(stretch) + if (stretch) x = st_apply(x, dimension, cutoff, probs = probs, stretch.method = stretch.method) if (anyNA(x[[1]])) { diff --git a/man/st_rgb.Rd b/man/st_rgb.Rd index f7b371116..faec7740e 100644 --- a/man/st_rgb.Rd +++ b/man/st_rgb.Rd @@ -36,7 +36,8 @@ reduce dimension to rgb (alpha) hex values } \details{ the dimension's bands are mapped to red, green, blue, alpha; if a different -ordering is wanted, use \link{[.stars} to reorder a dimension, see examples +ordering is wanted, use \link{[.stars} to reorder a dimension, see examples. +Alternatively, you can use \link{plot.stars} with the \code{rgb} argument to create a three-band composition. } \examples{ tif = system.file("tif/L7_ETMs.tif", package = "stars")