[R] Controlling size of boxplot when it is added in a plot

Charilaos Skiadas skiadas at hanover.edu
Sun Jan 14 22:33:54 CET 2007


Sorry, meant to send this to the list.

On Jan 14, 2007, at 4:28 PM, Charilaos Skiadas wrote:

> On Jan 14, 2007, at 5:50 AM, Chuck Cleland wrote:
>
>>   Try setting the boxwex argument instead:
>
> Thanks Chuck, that does indeed seem to work pretty well. I'm not  
> quite sure what the best way to determine an appropriate size for  
> the boxplot would be, but the following kind of works, at least for  
> the cases I tried. Though I'm not entirely happy with it. And I'm  
> sure I've made a bunch of errors along the way, that someone more  
> experienced in R could spot easily. Feel free to criticize the  
> code. the boxwex default I guess is probably terribly named. One  
> over it is supposed to be the size of the boxplot over the size of  
> the histogram.
>
> force.odd <- function(x) {
> 	x + 1 - x %% 2;
> }
> boxhist <- function(x, boxwex = 8, ...) {
> 	hs <- hist(x, breaks = 20, plot = F)
> 	space <- force.odd(max(floor(hs$counts / boxwex), 1))
> 	plot(hs, main = NULL, ylim = c(-space, max(hs$counts)), ...)
> 	boxplot(x, horizontal = T, axes = T, add = T, at = -space/2,  
> boxwex = space)
> }
> x <- rweibull(300,1,1); boxhist(x)
>
> Haris

Haris



More information about the R-help mailing list