Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R boxplot: How to customize the appearance of the box-and-whisker plots (e.g., remove lines or borders, change symbol of outliers)

Today, I was wondering how to customize the appearance of the box-and-whisker plots. E.g., I wanted to remove the line around the box. However, the problem is, that the border argument changes the color of all lines of the box-and-whisker plots simultaneously. So, if one has the great idea to set border = "white" then the whiskers are also going to “disappear” and you have a white line representing your median.

As I could not find a solution on the internet dealing with exactly my problem, I fiddled around a little and figured some mighty settings which seem to be nearly undocumented as a whole. These settings allow you to customize the appearance of your box-and-whisker plots to a large extend. I know, some of the features have already been unveiled on stackoverflow (e.g. here). However, I could not find a complete documentation. Thus, this post.

like image 977
ToJo Avatar asked Mar 05 '15 23:03

ToJo


2 Answers

In order to customize the appearance of the box-and-whisker plots, you have to change the med[…], box[…], whisk[…], or staple[…] argument for adjusting the line settings, or the out[…] argument for outliers.

enter image description here

[…] needs to be replaced by one of the following line or point arguments:

Arguments for the appearance of line elements (for more information see ?par in R):

  • lty: line style (e.g.,= 0 to remove the line,= 1 for solid line)
  • lwd: line width
  • col: line color

Arguments for the appearance of outliers (for more information see ?points in R):

  • pch: symbol style
  • lwd: line width
  • cex: size of symbol
  • col: color
  • bg: background color

So, here is an example of how the above boxplot might be "customized":

boxplot( … , medcol = "red", boxlty = 0, whisklty = 1, staplelwd = 4, outpch = 8, outcex = 3)

This leads to the following boxplot:

enter image description here

like image 140
ToJo Avatar answered Sep 18 '22 14:09

ToJo


For complete documentation you should look at ?bxp (linked from the ... description in ?boxplot, and in the "See Also" in ?boxplot, and in the pars description in ?boxplot.). It documents that outpch can change the shape of the outliers (though pch works fine too). It also has boxlty, boxlwd, boxcol and boxfill for the box, and many others for the whiskers, the staples, median line...

like image 43
Gregor Thomas Avatar answered Sep 19 '22 14:09

Gregor Thomas