Code covered by the BSD License  

Highlights from
sigstar - add signifiance stars to bar charts, box plots, etc

4.83333

4.8 | 6 ratings Rate this file 94 Downloads (last 30 days) File Size: 5.12 KB File ID: #39696
image thumbnail

sigstar - add signifiance stars to bar charts, box plots, etc

by

 

02 Jan 2013 (Updated )

Add significance bars and asterisks to various plot types

| Watch this File

File Information
Description

Lines and asterisks indicating significant differences between two groups on a plot are commonly used in the life and social sciences. To my knowledge, no MATLAB function for adding these is openly available.

sigstar makes it easy to add lines and significance asterisks joing one or more pairs of groups on bar charts, box plots, and even line plots. The user simply supplies the identities of the two groups and the p-value (which the user has calculated using an appropriate test). Group identity is defined as x-axis locations or, optionally, group names (if the x-axis labels are strings). sigstar converts the supplied p-values to the appropriate number of asterisks and plots these over the lines that link the pair of groups.

sigstar attempts to intelligently place lines and asterisks so that they do not overlie existing plot elements. By default, bars with longer horizontal extents are plotted above shorter bars. This is the convention and it looks neater. The user has control over the order in which significance bars are added. Modifying the order provides control over the vertical position of the bars. This is important for obtaining a neat result in a cluttered plot. See examples in "help sigstar" for details.

The handles of the added plot elements are returned by default, providing the user with fine control of the plot's appearance. See demo_sigstar for examples of advanced customisations.

I seldom use significance bars and so have not tested this function extensively. It should produce publication quality results, but you may need to play with the figure size and asterisk font size. I am happy to tweak the code if you find it doesn't work for you: please e-mail me.

MATLAB release MATLAB 7.13 (R2011b)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (15)
03 Jul 2014 Rob Campbell

I don't think I understand. This function is just a way of reporting statistical results that you have already calculated. So it's up to you to do your stats appropriately if your groups have different sizes.

03 Jul 2014 Andreas

Very great tool!

Is there an easy way to use "sigstar" for groups of different size, for example 10 and 20 subjects

15 Apr 2014 Dimitrios Korkinof  
31 Mar 2014 Rob Campbell

Look through the examples, it should be clear(ish). You manually choose the x values want and tell it to draw the bar across those positions. This is pretty much the only way of doing it since there's no way for the function to know which locations you want to link. It can't know this because it doesn't know the structure of your data.

31 Mar 2014 Mech Princess

how do I do this if my bar plot has more than one bar per x axis value?

15 Feb 2014 Rob Campbell

Daniel,

The answer is "sort of." On the one hand, yes, you can significance indicators however you want on a line plot. I think Maria's example and those in the function show how to this. On the other hand, *should* you be doing it? What do you mean by "significance of two lines"? In most cases, if you have data that can be plotted along a line, then you should be doing a regression of some sort and reporting the relevant coefficients in the text. It is easy to over-use the graphical significance indicators. To be honest, I myself have never used the sigstar for anything. :)

Rob

15 Feb 2014 Daniel

great tool. Is there any chance to check significance of to line plots?

I'd like to check out the significance of to lines at -10:5:10. So above the lines a star or two would represent significance. Is this possible?

Maybe this works very similar to Maria's group comparison solution, but I was not able to modify it the right way...

05 Feb 2014 Seban

Thanks to the creater of the script and to Maria, too.

18 Oct 2013 Jeroen Aeles  
27 Mar 2013 Rob Campbell

Awesome graph! I'm glad the function can cope with this sort of thing.

27 Mar 2013 Maria

Thank you for your quick answer!

I was able to figure out how. Here is my example for within groups and between groups comparisons :

figure
barvalues=rand(3,5);
errorsL=zeros(3,5);
errorsU=ones(3,5)*0.05;
handles.bars=bar(barvalues);
hold on
numgroups=size(barvalues, 1);
numbars=size(barvalues, 2);

for i=1:numbars
x=get(get(handles.bars(i), 'children'), 'xdata');
x=mean(x([1 3],:));
pos_bars(i,:)=x;
handles.errors(i)=errorbar(x,barvalues(:,i), errorsL(:,i), errorsU(:,i), 'k', 'linestyle', 'none', 'linewidth', 1);
end
handles.pos_bars=pos_bars;
comp_wgroups={ [handles.pos_bars(1),handles.pos_bars(2)], ...
[handles.pos_bars(1),handles.pos_bars(3)], ...
[handles.pos_bars(1),handles.pos_bars(4)], ...
[handles.pos_bars(2),handles.pos_bars(3)], ...
[handles.pos_bars(2),handles.pos_bars(4)], ...
[handles.pos_bars(3),handles.pos_bars(4)]};
sigstar(comp_wgroups)

comp_bgroups={ [handles.pos_bars(5),handles.pos_bars(6)], ...
[handles.pos_bars(5),handles.pos_bars(7)], ...
[handles.pos_bars(5),handles.pos_bars(8)]};
sigstar(comp_bgroups)

27 Mar 2013 Rob Campbell

Sure, here's an example:
>> clf
>> bar(rand(3,5))
>> sigstar([1,2])

I just tested it, it works.

27 Mar 2013 Maria

This function is great, exactly what I was looking for!

But I am still not able to make it work with a grouped bar graph. Can you please provide an example?

25 Jan 2013 Rob Campbell

Felix, I have submitted an update that should fix the issue with the grouped error bars.

25 Jan 2013 Felix

Unfortunately it doesn't work with grouped bar charts.
It' like to add lines and asteriks between two groups of bars, but it gives the error:
"Undefined function or method 'lt' for input arguments of type 'cell'." in findMinY...
would it be difficult to add this functionality?

Updates
16 Jan 2013

Add the ability to label data as being not significantly different. Example 2 in the function's help text shows how to do this.

25 Jan 2013

Update to work with grouped error bars.

17 Oct 2013

Update code to no longer call the range function, which is part of the stats toolbox.

Contact us