Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change width of individual boxes in boxplot in R

How can I reduce the width of each individual boxplot in Base R?

I do not want to change the relative sizes of the boxplots, which I understand can be done with the width argument

(this is not the same question as this post, which asks about removing whitespace)

boxplot(mpg ~ cyl,
        data=mtcars)

enter image description here

like image 715
Brigadeiro Avatar asked Sep 11 '25 12:09

Brigadeiro


2 Answers

You can set the default width using the boxwex= parameter. More information on these parameters are actually found in the ?bxp help page which does the boxplot drawing. There's a mention of this when describing the ... parameter in the ?boxplot help page.

boxplot(mpg ~ cyl, data=mtcars, boxwex=.2)

narrow box plots

like image 53
MrFlick Avatar answered Sep 13 '25 03:09

MrFlick


The graphic parameter you want is boxwex, see help("bxp"), the function that does the plotting part of the box-and-whiskers plot.

old_par <- par(mfrow = c(3, 1))
boxplot(mpg ~ cyl, data=mtcars, boxwex = 0.1)
boxplot(mpg ~ cyl, data=mtcars, boxwex = 0.4)
boxplot(mpg ~ cyl, data=mtcars, boxwex = 0.8)
par(old_par)

enter image description here

like image 44
Rui Barradas Avatar answered Sep 13 '25 03:09

Rui Barradas