-
Notifications
You must be signed in to change notification settings - Fork 0
/
drawStars.m
59 lines (49 loc) · 2.12 KB
/
drawStars.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
function [ ] = drawStars( y_values,p_values,thresh,shift,x_position,show_stars,text_varargin)
% [ ] = drawStars( y_values,p_values,thresh,shift,x_position,show_stars,text_varargin)
% - y_values: values of y as returned by UnivarScatter
% - p_values: p-values for each category, as indicated by the columns in
% y
% - thresh: array containing the threshold of significance, for example
% [0.05, 0.005] if you want * if p<0.05 and ** p<0.005.
% - shift: distance from the maximum point of each category where you
% want the star to be
% - x_position: the position of the center of each category on the
% x-axis, this should go from 1 to size(y,2) if you use the default
% version of UnivarScatter.
% - show_stars: boolean variable, true if you want significance to be
% represented by stars, false if you want to have "p<0.05" or whatever
% you introduced in the variable thresh.
% - text_varargin: varargin argument to the text function that will
% draw the stars or write the text (you can specify font, size etc.)
% We assume that using univarscatter, the x positions are 1:size(y_values,2)
if nargin<5||isempty(x_position)
x_stars = 1:size(y_values,2);
end
if nargin<6||isempty(show_stars)
show_stars = true;
end
if nargin<7||isempty(text_varargin)
text_varargin = {};
end
y_stars = max(y_values)+shift;
if numel(p_values)~=size(y_values,2)
error('Number of p_values differ from number of observations');
end
for i = 1:numel(p_values)
stars='';
for j = 1:numel(thresh)
if p_values(i)<thresh(j)
if show_stars == 1
stars = [stars '*'];
elseif show_stars == 2
stars = sprintf('p=%.1E',p_values(i));
else
stars = sprintf('p<%.4f',thresh(j));
end
end
end
if ~isempty(stars)
text(x_stars(i),y_stars(i),stars,'HorizontalAlignment','Center',text_varargin{:});
end
end
end