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