mplot: Plot multiple data series

Description Usage Arguments Details See Also Examples

View source: R/mplot.R

Description

Given a list of objects, extracts an x-axis and a y-axis element from each object, joins them together in a matrix, and passes them to matplot.

Usage

1
mplot(list, x = "x", y = "y", ...)

Arguments

list

A list of objects, each with elements named 'x' and 'y'.

x

The name of the element to use for the X axis; defaults to "x".

y

The name of the element to use for the Y axis; defaults to "y".

...

Arguments to matplot

Details

This is a convenience function used primarily for plotting multiple PDFs (from, e.g., stats::density or KernSmooth::bkde) on the same graph.

Each object must be a list with elements named "x" and "y", and all x and y elements must be the same length. (The elements are merged into matrices via calls to sapply.) These restrictions make the function not terribly useful in the general case, but it works fine on PDFs.

See Also

matplot

Examples

1
2
3
4
5
6
7
8
mu <- rnorm(5, sd=5)
sigma <- rgamma(5, shape=10, scale=0.25)
x <- mapply(function(m,s){rnorm(10000,m,s)}, mu, sigma, SIMPLIFY=FALSE)
d1 <- lapply(x, density)
d2 <- lapply(x, bkde)
## Note that the length of x & y differ for bkde & density
d <- c(d1, d2)
mplot(d, type="l")

sethmcg/climod documentation built on Nov. 19, 2021, 11:12 p.m.