在x轴上绘制矩阵的所有列

时间:2022-01-31 23:45:42

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. To illustrate what I'm looking for when I create the matrix:

我想在x轴上分别绘制矩阵的所有列,y轴是矩阵列中的值。为了说明创建矩阵时我正在寻找的东西:

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. What I want is this exactly except for just dots going up the y-axis instead of the boxplot.

矩阵列的每个箱线图分别出现在x轴上。我想要的是这个,除了只是沿着y轴而不是箱形图的点。

3 个解决方案

#1


1  

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])

在x轴上绘制矩阵的所有列

#2


1  

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)))

在x轴上绘制矩阵的所有列

#3


0  

boxplot has a plot argument:

boxplot有一个绘图参数:

plot
if TRUE (the default) then a boxplot is produced. If not, the summaries which the boxplots are based on are returned.

绘制如果为TRUE(默认值),则生成一个箱线图。如果不是,则返回箱图所基于的摘要。

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')

#1


1  

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])

在x轴上绘制矩阵的所有列

#2


1  

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)))

在x轴上绘制矩阵的所有列

#3


0  

boxplot has a plot argument:

boxplot有一个绘图参数:

plot
if TRUE (the default) then a boxplot is produced. If not, the summaries which the boxplots are based on are returned.

绘制如果为TRUE(默认值),则生成一个箱线图。如果不是,则返回箱图所基于的摘要。

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')