在一个箱线图中标记两个汇总数据

时间:2014-03-20 16:45:50

标签: r boxplot group-summaries

我是R的新用户 •我想结合这两组的结果,并仍将其标签保持为两组。当我结合时,它们会产生一个数字,这个数字已经丢失了标签。 •我还想将第1和第2(两组)标记为“下降”和“下降 - 上升”。分别用“黑色”和“灰色”颜色轻松显示差异。 •我正在处理摘要结果

这是我到目前为止使用的公式来创建数字:

d0<-matrix(c(x1,x2), ncol=2)
d1<-matrix(c(y1,y2), ncol=2)
lmts<-range(d0,d1)
par(mfrow = c(1, 2))
boxplot(d0, ylim=lmts, xlab="x")
boxplot(d1, ylim=lmts, xlab="y")
result1 <-boxplot(d0, ylim=lmts, xlab="x")
result2<- boxplot(d1, ylim=lmts, xlab="y")
mylist <- list(result1, result2)
groupbxp <- do.call(mapply, c(cbind, mylist))
bxp(groupbxp)

1 个答案:

答案 0 :(得分:0)

喜欢这个吗?

set.seed(1)   # so example is reproduceable
# create example
x1=sample(50,100,10)
x2=sample(50,100,10)
y1=sample(50,100,10)
y2=sample(50,100,10)
d0<-data.frame(falling=x1,"falling-rising"=x2)  # note use of data.frame(...)
d1<-data.frame(falling=y1,"falling-rising"=y2)
lmts<-range(d0,d1)
par(mfrow = c(1, 2))
boxplot(d0, ylim=lmts, xlab="x", col=c("grey80","grey50"))
boxplot(d1, ylim=lmts, xlab="y", col=c("grey80","grey50"))
result1 <-boxplot(d0, ylim=lmts, xlab="x", plot=F)
result2<- boxplot(d1, ylim=lmts, xlab="y", plot=F)
mylist <- list(result1, result2)
groupbxp <- do.call(mapply, c(cbind, mylist))
par(mfrow=c(1,1))
bxp(groupbxp,fill=T,boxfill=c("grey80","grey50","grey80","grey50"))

要获取x, y以外的标签,请使用data.frame(...)而不是matrix(...)。要获得颜色,请在boxfill=...的调用中使用bxp(...)。但是请注意,为了获得boxplot(...)中的颜色,参数是不同的,遗憾的是。