I am trying to make a (1 row, 3 column) array of barplots that all have the same bar width.

All three bar plots have a different number of observations and hence the width of the bars end up different for each plot (i.e. plot with the most observations has the narrowest bars and the plot with the fewest observations has the widest bars). I understand from the barplot {graphics}R documentation that,

"Specifying a single value will have no visible effect unless xlim is specified"

However, my x labels are strings, so I'm not sure how to specify xlim. I don't mind if my plots are different widths, but do I need to specify this somehow?

Here is some fake data and the code I am using... thank you for your help.

2 Answers
2

Without the variables like height4plot1 etc. it is harder to test your code and modifications, but here are some possibilities:

You can specify width=0.8 for each plot and xlim=c(0,maxnum) where maxnum is the maximum numbers of bars in the different plots. This will leave an empty section in each of the smaller bar plots.

You could pad the shorter vectors of heights with NA until they are all the same length (this would still give the empty sections).

You could concatenate your 3 vectors together and make a single boxplot, possibly coloring the 3 groups differently to help distinquish them. The abline function can be used to add divider lines between the groups (and see the space argument to barplot, or include an 'NA' as divider to give more space between the groups). You can use the return value to help in placing titles above each group.

You can use layout instead of par to set up your 3 plotting areas to have different widths, but getting the exact ratios of widths to give the exact same size bars will not be simple (you may get close with trial and error though). If you really want this route then grconvertX and optim may help.

Thank you for your suggestions Greg. I tried to include 'NA' as a divider between the three groups of data, but I get an error message about the 'height' of the bars not being a vector or matrix.
–
CJONov 13 '12 at 14:54

Concatenating the three vectors works and the abline is helpful. Now I just need to figure out how to add extra titles above each group and colour code the groups.
–
CJONov 13 '12 at 14:56