gpplot2相当于matplot():按列绘制矩阵/数组? [英] ggplot2 equivalent of matplot() : plot a matrix/array by columns?
问题描述
a< - 矩阵(rnorm(100),c(10,10))
matplot(a,type ='l')
使用ggplot2有什么相似之处,或者ggplot2要求数据是 另外,是否有一种方法可以使用单独的矢量( Is there something similar using ggplot2, or does ggplot2 require data to be Also, is there a way to arbitrarily color/style subsets of the matrix columns using a separate vector (of Maybe a little easier for this specific example:
这篇关于gpplot2相当于matplot():按列绘制矩阵/数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!融化$ c
length = ncol(a)
)?
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 ,值,data = sa,group = ind,color = ind,geom =line)
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')
melted
into a dataframe first?length=ncol(a)
)?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")