File Exchange

image thumbnail

superbar

version 1.5.0.0 (104 KB) by Scott Lowe
Have no fear. Superbar is here!

36 Downloads

Updated 11 Nov 2016

GitHub view license on GitHub

Bars! Bars! Bars!
Make bar charts rammed full of extra features:
- in full technicolor, with a unique colour for every bar if that's what you're into
- showing errors on the values using errorbars, with many styles available
- with statistical significance of each bar indicated with stars above them
- with statistical significance of comparisons between pairs of bars shown with lines between the pairs and stars above them
- and all this in either horizontal or vertical orientations
Have no fear. Superbar is here!
And that's not all! It comes with a free copy of SUPERERR, which you can use to plot error bars not on bar charts. Plot errors in both X and Y with lots of style options for capped, uncapped, one-directional, symmetric, asymmetric errorbars. It can do everything you want, just as long as what you want is to plot errorbars on a set of linear-linear axes!

If you want to help make SUPERBAR even more super, you can report bugs and suggest new features on GitHub:
https://github.com/scottclowe/superbar

Tested in R2011a (Windows) and R2016a (Windows & Ubuntu).

Comments and Ratings (27)

chaodadi

Powerful and robust.

Aiyush

This function just saved my life. Being able to put error bars as well as the significance level stars above, is ideal. This is what people want for a publishable figure. Also, as the comments suggested, the legend colors can be fixed by doing ax(1,:) as a parameter. The customizability for this function is incredible.

zhiyo

i found a workable solution. somehow the list of bar handles from superbar is transposed, such that legend operates along the first column of handles when what one wants for group-corresponding legend colors would be operating along the first row. set ax = superbar(...); when setting legend, use the first row of ax - that is, ax(1,:) - to set the subset for legend.

ax = superbar(...);
legend(ax(1,:),lgd_names)

hi scott. this is great. my only issue is the one mentioned below: the legend colors do not come out correctly. for me, they typically come out all as the same color as the first bar group.

is there a workaround this issue, or is it a known bug?

Almost perfect. Only two things lacking. 1) ability to rename x-axis of grouped bars (i.e. Time 1, Time 2, Time 3) and 2) the legend colors don't match the bar colors of grouped bars.

Regarding the comment made inside ‘superbar’ by the author: “If you see boxes showing a rectangle with a cross through them instead of stars … “

I encountered this issue, but it is easily resolved. Simply set ‘string’ and ‘interpreter’ properties of HPT handles returned by ‘superbar’ to ‘\ast’ and ‘tex’, respectively.

This is one of the best plotting utilities on FEX. Thanks for sharing!

Z Z

Hi Scott, how to plot upward errorbars for positive means, and downward errorbars for negative means at the same time?

JWall

Thanks for this - I'm finding it really useful!
One question - I'm making a grouped bar plot (ie two different bars for each value on the x axis), and I want the colors to be different for each group. I can't seem to figure out how to do this - no matter how I set the color matrix up with 'BarFaceColor,' it seems that the two bars for each x axis value are always the same color rather than a unique color for each group, as I want them to be. Can anyone help? Thanks!

Thanks Scott for this great function! The lines for pairwise comparison don't work when using asymmetric error bars. I've added the following line at the beginning of the function 'plot_p_values_pairs', which does the trick:
if size(E,2)==2 ; E=E(:,2); end

Zaki Molvi

Daili

66666666

Martin

Aaaah this is exactly what I needed. It's so pretty and easy!
I've got one question though: I have plots where all values are negative - is there a way to make the main lines start at the zero point instead of the top of the highest bar? Or to put them below the bars? So that they're not overlapping with the bars themselves?
Cudos!

Matt Flood

This should replace the current 'bar' function supplied by Matlab.
Brilliant work!

Abby Hill

Scott Lowe

Hi Michael, I've added a 'BarLineWidth' input to SUPERBAR now, so you can change the width of the bar edges more easily, and the default width is wider than it used to be.
Thanks for your feedback!

Scott Lowe

Hi, Michael! I'm glad to hear you found superbar easy to set up and use, especially since the documentation isn't finished yet! It is currently not possible to pass arbitrary inputs to bar via superbar (though I do intend to add this at some point in the future). For the time being, you have to change the properties of the bars created by superbar using the first set of handles it returns. For example,
`h = superbar(Y, 'BarEdgeColor', 'k'); set(h, 'LineWidth', 2);`. Hope that helps!

Great tool! Had it up and integrated in couple minutes. One question: is there an easy way to control the line-thickness of bars?

Jmpp

Excellent! So many customizations. I've been waiting a long time for someone to do all this work for me.

Updates

1.5.0.0

- PStarLatex option allows changing whether significance text is rendered using the LaTeX interpreter, with the default now as `'off'`.
- PStarIcon option allows changing the symbol used for stars.

1.4.1.0

- Support for older version of inputParser in R2007a-R2013a with `addParamValue` instead of `addParameter` method.
- Avoid using `narginchk` in versions pre-2011b before it was introduced.

1.4.0.0

Added support for cell array colour inputs.
Added BarLineWidth input.
BarFaceColor default changed to transparent if a BarEdgeColor isn't.
Default errorbar colour inherited from BarFaceColor will now be lighter for dark bars.

1.3.2.0

Added README, tutorial, logo.
Changed default PLineSourceRelativeSpacing, PStarThreshold now `[0.05, 0.01, 0.001, 0.0001]`.
Fixed behaviour of > sign when showing significance; now > appears instead of a star when all thresholds are exceeded.

1.3.1.0

Add unit tests for SUPERBAR.
Fix bug when plotting into non-current axes.

1.3.0.0

When there is no source separation, offset line starts.
Add unit tests for supererr.

1.2.1.0

Change output shapes of HB, HPT, HPL, HPB to match the shape of Y.

1.2.0.0

- Avoid axes input to text and line fns, supporting <R2016a (tested in R2015b)
- P-value text in LaTeX mode, "n.s." when not significant, bg colour
- Change shape of outputs hpl, hpt, hpb
- Update defaults for p thresholds, errorbar widths, fontsize

1.1.1.0

Change default orientation of star text for horizontal bars; now normal for single p-values and sideways for pair-wise p-values.

1.1.0.0

Show pairwise comparison lines on horizontally oriented plots.

1.0.1.0

Bug fixes

MATLAB Release Compatibility
Created with R2011a
Compatible with any release
Platform Compatibility
Windows macOS Linux