[R] side by side boxplots

Phillip Porter philnotfil at gmail.com
Fri Nov 28 19:55:05 CET 2008


Good Morning,
	I am trying to get side by side boxplots of two groups on the 
same variable.  The last item under ?boxplot led me to some useful 
code.
	I use "boxwex" to make the boxes narrower, "at" to shift them 
over and "add" to draw them both on the same graph.  Something along 
the lines of:

attach(group1)
boxplot(Y~X, col="blue", boxwex=.4, at=1:n+.2)
attach(group2)
boxplot(Y~X, col="red", boxwex=.4, at=1:n-.2, add=TRUE)

	When I just make up a small dataset to try this out on it 
works great.  My problem is that I don't have completely matching 
data in the real dataset.  Every instance of the variable does not 
have data present from both groups.  When they get put on top of each 
other they don't line up.
	Can I do something with my data to make it line up correctly 
using this approach?  Is there another way of getting the same 
results?

Thanks,
Phillip



More information about the R-help mailing list