Skip to content

Plotting pairs of bars

7 messages · Greg Snow, Steve Murray, Jim Lemon +1 more

#
Dear all,

I have a matrix called combine86 which looks as follows:
Sim Mean   Obs Mean  Sim Sum Obs Sum
AMAZON      1172.0424  1394.44604  553204  659573
NILE         262.4440   164.23921   67973   41881
CONGO        682.8007   722.63971  205523  214624
MISSISSIPPI  363.0758   142.59883  124535   49054
AMUR         143.5857    89.30434   36040   22594
PARANA       702.3793   388.03030  162952   89635
YENISEI      208.1396   174.52722   83464   70509
OB           197.0399   162.82697   79013   63991
LENA         118.1100    77.49638   48307   32161
NIGER        374.8258   212.25714   66719   37145
ZAMBEZI      500.0000   485.87610   57000   54904
YANGTZE      358.4172   256.80246   58422   41602


For each of the rivers (which are the row names of this matrix), I wish to plot a bar for Simulated Mean and another for the Observed Mean. So far I've only been able to get R to stack the bars (using 'barplot) on top of one another, which isn't really what I want! I was hoping more for a pairing of bars (one 'Sim' and one 'Mean') followed by a gap, then the next pair of bars for the next river, a gap, and so on. Is this possible to do in R? If so, how?!

Many thanks,

Steve


_________________________________________________________________
[[elided Hotmail spam]]
#
Look at the beside argument to the barplot function.
#
Thanks for the reply - the 'beside' argument certainly looks useful, although I'm still not getting the output I'd hoped for.

By doing: barplot(combine86[,1:2], beside = TRUE, las = 1, xlab=rownames(combine86))
...I get all the bars for the 'Sim Mean' column plotted on the left side of the graphics device and all the bars for the 'Obs Mean' clustered on the right side.

Ideally I'd like bar 1 to be from 'Sim Mean' for Amazon and then bar 2 for 'Obs Mean' for Amazon. Then there would be a small gap separating the Amazon from the next pair of bars of the next river (Nile). Then it would be the 'Sim Mean' value for Nile, followed by the 'Obs Mean' value for Nile, then a gap, then onto the next river and so on.

Thanks for any help,

Steve


_________________________________________________________________
[[elided Hotmail spam]]
#
Steve Murray wrote:
Hi Steve,
Try transposing:

barplot(t(combine86[,1:2]),...)

Jim
#
Jim and all,

Thanks for the suggestion, however, I get the following error:
Error in t(combine86[, 1:2], beside = TRUE, las = 1) : 
  unused argument(s) (beside = TRUE, las = 1)

I've looked up ?t and cannot see any extra arguments that I should be including, and the executes without the 't'.

What is it that I've omitted that I need to successfully execute the code (as previously described)?

Many thanks again,

Steve


_________________________________________________________________
[[elided Hotmail spam]]
#
Steve Murray wrote:
)

after the right square bracket, and remove the last right parenthesis.

Jim
#
Steve Murray-3 wrote:
Just misplaced parentheses:

barplot(t(combine86[,1:2]),beside=TRUE,las=1)