0

I am a new user of R. • I would like to combine the results of these two groups and still maintain their labels as two groups. When I combine, they yield a figure, which has lost the labels. • I would also like to label number 1 and 2 (for both groups) as “falling” and “falling-rising”. respectively and with “black” and “grey” color to show difference easily. • I am working with summary results

This is the formula I have used so far to create the figure:

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)
Didzis Elferts
  • 95,661
  • 14
  • 264
  • 201

1 Answers1

0

Like this?

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

To get labels other than x, y use data.frame(...) instead of matrix(...). To get colors use boxfill=... in the call to bxp(...). Note, though, that to get colors in boxplot(...) the arguments are different, sadly.

jlhoward
  • 58,004
  • 7
  • 97
  • 140
  • Thank you for this. It has really been helpful. I can now plot them exactly like this. I might have not been too clear on one question though. How do I also show the labels (result1 and result2), which are the names of the two groups? Notice that after binding the two, their labels disappear. Is there a way to maybe draw a line to mark this too? Can I also give the colours a key. e.g where each shade of grey has been assigned its representative name; falling or falling.rising? – user3437736 Mar 21 '14 at 12:30