Skip to content

Commit

Permalink
st_rgb docs; #641
Browse files Browse the repository at this point in the history
  • Loading branch information
edzer committed Aug 17, 2023
1 parent 6919bfb commit fa8ca6a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
25 changes: 12 additions & 13 deletions R/plot.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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,
Expand All @@ -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)
Expand All @@ -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]])) {
Expand Down
3 changes: 2 additions & 1 deletion man/st_rgb.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit fa8ca6a

Please sign in to comment.