tinyplot Method for Plotting Matrices

Description

Convenience interface for visualizing matrix objects with tinyplot.

Usage

## S3 method for class 'matrix'
tinyplot(
  x,
  type = NULL,
  legend = NULL,
  facet = NULL,
  xlab = NULL,
  ylab = NULL,
  ...
)

Arguments

x an object of class “matrix”.
type plot type passed on to tinyplot. Defaults to “p” (points).
legend specification passed on to tinyplot. The default is to draw a legend when the matrix has named columns, and to suppress it otherwise.
facet specification of facet passed on to tinyplot. The only accepted non-NULL value is the “by” convenience string, which facets the plot by matrix column.
xlab, ylab axis labels passed on to tinyplot. ylab defaults to the deparsed matrix name. xlab defaults to “Index” when the matrix has no row names; when it does, the row names already label the ticks so the x-axis title is suppressed.
further arguments passed to tinyplot.

Details

Internally the matrix is converted to long form and visualized as a scatter (or other type) of each column’s values against their row index. Each column is mapped to a separate by category, so a matrix with multiple columns produces a grouped plot. Optionally, it can also be faceted via facet = “by”. This mirrors the base R matplot convention of plotting the columns of a matrix against the row numbers. If the matrix has column names, these are used as the group (and legend) labels. Single-column matrices are drawn as a simple index plot with no grouping or legend.

Value

No return value, called for the side effect of producing a plot.

See Also

matplot

Examples

library("tinyplot")

# basic use
tinyplot(VADeaths)

tinyplot(VADeaths, type = "b")

tinyplot(VADeaths, type = "b", legend = "direct", theme = "socviz")

tinyplot(VADeaths, type = "b", legend = FALSE, facet = "by", theme = "socviz")

# equivalent plot to an example in `?matplot`
sines = outer(1:20, 1:4, function(x, y) sin(x / 20 * pi * y))
tinyplot(sines, type = "o", pch = "by", lty = "by", col = rainbow(ncol(sines)))