# How to color box and whisker plot

A few days ago, my colleague told me that he had a question about the double box plot. I was very glad and welcomed his question, but soon disappointed, a little. He wanted two colored standard box plot on one graph. Not a double axes box plot.

Well, that is another good question. I had also learned how to plot a chart with R by reading web articles, so it is my turn to write some.

Let’s generate two series of random data, with an outlier.

a <- rnorm(10)
b <- c(rnorm(9), 4)

Draw a box plot without colors.

boxplot(a, b)

Fig. 1. Monochrome box plot chart

Now, color it with col= option.

boxplot(a, b, col=c('powderblue', 'mistyrose'))

Fig. 2. Two colored box plot chart

It just paints inside of boxes. What about other parts?

boxplot(a, b, col=c("#FF000099", "#FF6D0099"),
medcol=c("#FFDB00FF", "#B6FF00FF"),
whiskcol=c("#49FF00FF", "#00FF24FF"),
staplecol=c("#00FF92FF", "#00FFFFFF"),
boxcol=c("#0092FFFF", "#0024FFFF"),
outcol=c("#4900FFFF", "#B600FFFF"),
outbg=c("#FF00DB66", "#FF006D66"),
outcex=3, outpch=21)

Fig. 3. Full color box plot chart

For many (unknown) sets of data, I love using the function rainbow().

x <- rep(1:10, each=7)
y <- rnorm(10*7)
boxplot(y~x, col=rainbow(length(unique(x))))

Fig. 4. Rainbow color box plot chart

More colors.

c1 <- rainbow(10)
c2 <- rainbow(10, alpha=0.2)
c3 <- rainbow(10, v=0.7)
boxplot(y~x, col=c2, medcol=c3, whiskcol=c1, staplecol=c3, boxcol=c3, outcol=c3, pch=23, cex=2)

Fig. 5. More rainbow color box plot chart

### Like this:

Like Loading...

*Related*

## Recent Comments