[英]Plotting all columns of a matrix on the x-axis
I would like to plot all the columns of a matrix separately on the x-axis with the y-axis being the values in the columns of the matrix. 我想在x轴上分别绘制矩阵的所有列,y轴是矩阵列中的值。 To illustrate what I'm looking for when I create the matrix:
为了说明创建矩阵时我正在寻找的东西:
test=matrix(c(1,4,3,2,3),ncol=5,nrow=5)
and plot it using 并使用它绘制它
boxplot(test)
each boxplot of the columns of the matrix appears separately on the x-axis. 矩阵列的每个箱线图分别出现在x轴上。 What I want is this exactly except for just dots going up the y-axis instead of the boxplot.
我想要的是这个,除了只有点在y轴而不是箱线图上。
Not that it makes much sense to have data laid out this way, but here it is: 并不是说以这种方式布局数据是有意义的,但这里是:
test=matrix(c(1,4,3,2,3),ncol=5,nrow=5)
plot(rep(1:5, 5), c(t(test)))
using reshape2
library to melt data 使用
reshape2
库来融化数据
library(reshape2)
test = matrix(c(1, 4, 3, 2, 3), ncol = 5, nrow = 5)
plot(melt(test)[, 2:3])
boxplot
has a plot
argument: boxplot
有一个plot
参数:
plot
ifTRUE
(the default) then a boxplot is produced.如果为
TRUE
(默认值),则生成一个boxplot。 If not, the summaries which the boxplots are based on are returned.如果不是,则返回箱图所基于的摘要。
The results you are interested in are in the stats
component. 您感兴趣的结果位于
stats
组件中。
You could then use matpoints
or matplot(..., type = 'p')
然后你可以使用
matpoints
或matplot(..., type = 'p')
Note that you must transpose the results to get your desired plot 请注意,您必须转置结果以获得所需的绘图
matpoints(t(boxplot(test, plot = FALSE)$stats), pch = 19, col = 'black')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.