Code covered by the BSD License  

Highlights from
barwebpairs (pair bars within groups and between groups)

4.0

4.0 | 2 ratings Rate this file 19 Downloads (last 30 days) File Size: 2.92 KB File ID: #27494
image thumbnail

barwebpairs (pair bars within groups and between groups)

by

 

Add pairing brackets to a bar plot (e.g. to indicate statically significant differences)

| Watch this File

File Information
Description

Use 'barweb' function by Bolu Ajiboye (submitted to file exchange on Oct 1 2009) to generate a bar plot with error bars.

Usage: barwebpairs(h, pairsBG, pairsWG)
* h: handle returned by barweb
* pairsBG: between groups pairs: 1 x n cell array (where n is number of subgroups), each cell contains p x 2 matrix with pairings (where p is the number of pairings for the subgroup, may differ in each cell). The bracket will be drawn in color of subgroup
Ex. PairsBG = {[1 2; 1 3; 2 4] , [2 3]}
 pairs groups 1->2, 1->3, and 2->4 for subgroup1
 and groups 2->3 for subgroup2
 * pairsWG: within group pairs: 1 x m cell array (where m is number of groups), each cell contains p x 2 matrix with pairings where p is the number of pairings in the group, may differ in each cell). The bracket will be drawn in black

NOTES:
1. Groups are labeled by group names and clustered together. Subgroups are different colors (according to the colormap).
2. The barweb plot must be the active axis
3. The axes will be adjusted to fit the brackets
4. To only include within group pairings set pairsBG = []
5. Within group brackets are plotted first. Each bracket is plotted at the minimum y-value (above bars and errorbars between the paired subgroups). No two brackets within the same group will be plotted at the same y-value. They will be plotted in the order of the pairing matrix, with row 1 lowest. 6. Between group brackets are plotted second. Each bracket is drawn at the minimum y-value (above any within-group brackets, bars, and errorbars between the paired groups). No two brackets will be plotted at the same y-value; they are plotted in the order of the pairing matrix, with row1 lowest.
7. Use barweb ver 2.3 by Bolu Ajiboye (also on Matlab Central)

Acknowledgements

Barweb (Ba Rgraph With Error Bars) inspired this file.

MATLAB release MATLAB 7.5 (R2007b)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (5)
10 Jun 2014 Chris McGraw

Nice code, just what I was looking for.

I noted a bug, using Matlab 2013b 64-bit on Windows 7, also Barweb v2.3. The function doesn't accurately target the 'within-group' bars that I wanted. I tracked it down to the fact that the variable 'posX' which is received from the handles object generated by the barweb function appears to be corrupted -- the matrix is twice as long as necessary and every other element is something that the author of barwebpairs must not have intended.

I corrected it by adding 'posX = posX(1:2:end);' after the initial posX declaration, and everything worked fine after that. I did not test out 'between-group' pairs, so I can't say whether it broke something else, but it certainly fixed something that wasn't working.

Again, otherwise very nice and convenient.

05 Aug 2013 Plamen

How did you get the handle after plotting data using barweb?

27 Feb 2013 Tim

would it be possible to add * to the pair bars as in http://www.nature.com/srep/2012/120621/srep00459/images_article/srep00459-f6.jpg ?

30 Mar 2011 Casey Ta

Thanks for this implementation, this and barweb are exactly what I needed. However, I had a minor problem with this function:

line 149-50: color(iColor,:) can cause an error for me since iColor was calculated out to a fractional value. I replaced this with color(j,:), and now the function seems to work correctly.

30 Mar 2011 Casey Ta  

Contact us