Skip to contents

Draws one or several line series using graphics::matplot(). The function accepts either a matrix of values or separate x and y coordinates and supports optional point symbols, grid lines, and an automatically positioned legend.

Usage

plotLines(
  x,
  y,
  main = NULL,
  xlab = "",
  ylab = "",
  xlim = NULL,
  ylim = NULL,
  xaxt = NULL,
  yaxt = NULL,
  lty = 1,
  lwd = 2,
  col = .useTheme,
  points = FALSE,
  grid = .useTheme,
  legend = TRUE,
  stamp = .useTheme,
  ...
)

Arguments

x

numeric vector, matrix or data frame. If y is missing, x is interpreted as a matrix of series where rows correspond to x positions and columns to individual lines.

y

optional numeric vector or matrix giving the y-values. If supplied, x is interpreted as the x-coordinates.

main

main title of the plot. NULL (default) derives a title from the input. "", NA, or FALSE suppress the title and compact the top margin.

xlab, ylab

labels for the axes.

xlim, ylim

limits for the axes.

xaxt, yaxt

axis specification passed to graphics::axis().

lty

line type(s).

lwd

line width(s).

col

colours for the lines. .useTheme (default) resolves to pal(getTheme()$palette), the active theme's qualitative palette.

points

controls drawing of points on the lines. FALSE (default) suppresses points; TRUE draws with theme defaults (getTheme()$points); a named list overrides individual elements (pch, col, bg, cex).

grid

controls drawing of the background grid. .useTheme (default) follows the active theme (getTheme()$grid). TRUE/FALSE/NA, or a named list, as for graphics::grid().

legend

controls the legend. TRUE (default) draws an inline legend via textLegend at the last value of each series. FALSE/NA suppresses it. A list overrides legend arguments.

stamp

controls the corner stamp. .useTheme (default) resolves to getTheme()$stamp. TRUE/FALSE/NULL, a string, or a named list for stamp().

...

additional graphical parameters passed to graphics::par() via .applyParFromDots() and to the plotting functions.

Value

Invisibly returns a list containing:

  • x the x-values used for plotting,

  • y the y-values (if supplied),

  • legend the legend specification if drawn.

Details

If y is missing, x is interpreted as a matrix and each column is drawn as a separate line. Row names are used for the x-axis labels if available. The legend labels default to the column names of the data.

Examples

m <- matrix(c(3,4,5,1,5,4,2,6,2), nrow = 3,
            dimnames = list(
              dose = c("A","B","C"),
              age  = c("2000","2001","2002")
            ))

plotLines(m, lwd = 2, main = "Dose ~ Age")


# with points
plotLines(m, points = TRUE)


# custom legend
plotLines(m, legend = list(cex = 0.8))