R/plot.R

Defines functions plot.attractor

Documented in plot.attractor

#' Plot a strange attractor.
#'
#' @inheritParams recolour
#' @inheritParams discretize
#' @param x Attractor, generated by [attractor_sprott_7e()]
#' @param trim_quantiles Numeric value, indicating a trim value. Quantiles below this value, as well as higher than `(1 - trim_quantiles` will be removed from data prior to plotting.
#' @param trans Transforming function
#' @param ... Other options passed to [plot()]
#'
#' @return Raster, invisibly
#' @family attractor
#' @export
#'
#' @importFrom graphics plot
#'
plot.attractor <- function(x, palette = "BuPu", invert = FALSE,
                           dims = c(600, 600), zero_colour = NA,
                           trim_quantiles = 0, trans = "log1p", ...){
  if (any(is.infinite(x[[1]])) || any(is.infinite(x[[2]]))) {
    message("Infinite values")
    return(NULL)
  }

  if (trim_quantiles > 0) {
    x <- trim_quantiles(x, q = trim_quantiles)
  }

  if (nrow(x) == 0) return(invisible(as.raster(matrix(0, nrow = dims[1], ncol = dims[2]))))

  z <- discretize(x, dims = dims)
  z <- match.fun(trans)(z)
  z <- recolour(z, palette = palette, invert = invert, zero_colour = zero_colour)
  plot(z, ...)
  invisible(z)
}
andrie/attractor documentation built on May 13, 2019, 11:56 p.m.