ggplot2 equivalent of matplot() : plot a matrix/array by columns?

ggplot2, matrix, plot, r

Solution

Maybe a little easier for this specific example:

library(ggplot2)
a <- matrix (rnorm(100), c(10,10))
sa <- stack(as.data.frame(a))
sa$x <- rep(seq_len(nrow(a)), ncol(a))
qplot(x, values, data = sa, group = ind, colour = ind, geom = "line")

Problem

`matplot()` makes it easy to plot a matrix/two dimensional array by columns (also works on data frames): ``` a <- matrix (rnorm(100), c(10,10)) matplot(a, type='l') ``` Is there something similar using ggplot2, or does ggplot2 require data to be `melted` into a dataframe first? Also, is there a way to arbitrarily color/style subsets of the matrix columns using a separate vector (of `length=ncol(a)`)?

Original source