如何在R中对行矩阵进行箱图绘制? [英] How to boxplot row-wise matrix in R?
本文介绍了如何在R中对行矩阵进行箱图绘制?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个8列的matrix
.对于每一行,我想绘制一个箱形图.我更喜欢将箱线图放在一个图中.因此,以下示例应在单个图像中产生4个箱形图(每个8个值).
I have a matrix
with 8 columns. For each row I'd like to a plot a single boxplot. I prefer the boxplots to be in a single plot. So the following example should produce 4 boxplots (8 values each) - all in a single image.
数据示例:
> data[2:5,]
[,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8]
[1,] 0.6 0.5 0.5357143 0.5357143 0.5357143 0.5357143 0.5357143 0.5185185
[2,] 0.5 0.5 0.5357143 2.5357143 0.5357143 0.5357143 0.5357143 0.5185185
[3,] 0.5 0.7 0.5357143 0.5357143 0.5357143 0.5357143 0.5357143 0.5185185
[4,] 0.5 0.5 1.5357143 0.5357143 0.5357143 0.5357143 0.5357143 0.5185185
到目前为止,我已经尝试过:
So far I've tried:
> boxplot(data[2:5,])
Error in sort.int(x, na.last = na.last, decreasing = decreasing, ...) :
'x' must be atomic
和这篇SO帖子:
> boxplot(as.list(as.data.frame(data[2:5,])))
Error in sort.int(x, na.last = na.last, decreasing = decreasing, ...) :
'x' must be atomic
我已经奋斗了很久了.你能给我提示吗?
I've been struggling for ages. Could you please give me hint?
> dput(data[2:5,])
structure(list(0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.535714285714286,
0.535714285714286, 0.535714285714286, 0.535714285714286,
0.535714285714286, 0.535714285714286, 0.535714285714286,
0.535714285714286, 0.535714285714286, 0.535714285714286,
0.535714285714286, 0.535714285714286, 0.535714285714286,
0.535714285714286, 0.535714285714286, 0.535714285714286,
0.535714285714286, 0.535714285714286, 0.535714285714286,
0.535714285714286, 0.518518518518518, 0.518518518518518,
0.518518518518518, 0.518518518518518), .Dim = c(4L, 8L))
推荐答案
要从矩阵中绘制箱线图,我们可以使用boxplot.matrix
函数:
To draw boxplots out of matrices, we can use the boxplot.matrix
function:
boxplot.matrix(data, use.cols = FALSE)
这篇关于如何在R中对行矩阵进行箱图绘制?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文