R/olines.R

Defines functions olines

Documented in olines

#' Add (Sorted) Connected Line Segments to a Plot
#' 
#' @param x,y   coordinate vectors of points to join.
#' @param type  character indicating the type of plotting;
#'              actually any of the types as in plot.default.
#' @param \dots Further graphical parameters (see par)
#'              may also be supplied as arguments, particularly,
#'              line type, lty, line width, lwd, color, col and
#'              for type = "b", pch. Also the line characteristics
#'              lend, ljoin and lmitre.
#'              
#' @examples
#' 
#' set.seed(123)
#' x <- rnorm(15)
#' y <- x * 5 + rnorm(15, 0, 3)
#' 
#' par(mfrow=c(1,2))
#' plot(x, y, main = "lines")
#' lines(x, y)
#' 
#' plot(x, y, main = "olines")
#' olines(x, y)
#' par(mfrow=c(1,1))
#'              
#' @export

olines <- function(x, y = NULL, type = "l", ...) {
  if (is.null(y)) {
    lines(x, type = type, ...)
  } else {
    i <- order(x)
    lines(x[i], y[i], type = type, ...)
  }
}
twolodzko/twextras documentation built on May 3, 2019, 1:52 p.m.