2

来自矩阵的 R 中的多个箱线图,按特定列的值分组。

例如。

M= matrix(c(1,2,1,3,2,3,1,4,2,5,3,5,2,6),ncol=2)

IE。

   [,1] [,2]
[1,]    1    4
[2,]    2    2
[3,]    1    5
[4,]    3    3
[5,]    2    5
[6,]    3    2
[7,]    1    6

现在我想要一个图表,其中包含第一列的每个不同值的箱线图。即应该有三个箱线图,即。对于 1,2,3(不同的 col. 1 值)

谢谢。

4

2 回答 2

3
M <- as.data.frame(M)
boxplot(M$V2~M$V1)
于 2013-05-22T09:37:41.400 回答
1

您可以使用ggplot2: 来执行此操作,例如:

library(ggplot2)
df = as.data.frame(M)
ggplot = ggplot(df, aes(as.factor(V1), V2)) + geom_boxplot()
于 2013-05-22T09:39:41.443 回答