Skip to content

Grouped bars in barplot

2 messages · Steve Murray, Peter Alspach

#
Dear all,
 
I am trying to make a barplot with clustered pairs of bars, using class=numeric data and the following command:
 
barplot(c(bline_precip[10,9], bline_runoff[10,9], cccma_precip[10,9], cccma_runoff[10,9], csiro_precip[10,9], csiro_runoff[10,9], ipsl_precip[10,9], ipsl_runoff[10,9], mpi_precip[10,9], mpi_runoff[10,9], ncar_precip[10,9], ncar_runoff[10,9], ukmo_precip[10,9], ukmo_runoff[10,9]), beside=TRUE, space=c(0,2))
 
This results in all bars being packed tightly together, but with no gap between each pair. I suspect the problem is something to do with the data not being a matrix, but I've tried using as.matrix for each data element and this doesn't seem to work. If any one has any suggestions I'd be very grateful to hear them.
 
Also, I'm hoping to put a label beneath each pair of bars on the x-axis, in the centre. At present I can only get labels to appear directly underneath a single bar, as opposed to the centre of the pair of bars. Does anyone have any suggestions for solving this?
 
Many thanks for any help offered.
 
Steve
#
Tena koe Steve

Convert your data into a matrix:

dataMat <- matrix(c(bline_precip[10,9], bline_runoff[10,9],
                    cccma_precip[10,9], cccma_runoff[10,9],
                    csiro_precip[10,9], csiro_runoff[10,9],
                    ipsl_precip[10,9], ipsl_runoff[10,9],
                    mpi_precip[10,9], mpi_runoff[10,9],
                    ncar_precip[10,9], ncar_runoff[10,9],
                    ukmo_precip[10,9], ukmo_runoff[10,9]), nrow=2)

Since I don't know the nature of your data I will use a simple example:

dataMat <- matrix(1:14, nrow=2)
barplot(dataMat, beside=TRUE, space=c(0,2))
tTicks <- barplot(dataMat, beside=TRUE, space=c(0,2))
tTicks <- tapply(tTicks, rep(1:7, each=2), mean)
axis(1, tTicks, letters[1:7])

Is that what you want?

HTH ....

Peter Alspach
The contents of this e-mail are confidential and may be subject to legal privilege.
 If you are not the intended recipient you must not use, disseminate, distribute or
 reproduce all or any part of this e-mail or attachments.  If you have received this
 e-mail in error, please notify the sender and delete all material pertaining to this
 e-mail.  Any opinion or views expressed in this e-mail are those of the individual
 sender and may not represent those of The New Zealand Institute for Plant and
 Food Research Limited.