Skip to content

Commit

Permalink
Enhancements in stat_smooth() and bug fixes
Browse files Browse the repository at this point in the history
- stat_smooth() includes more smoothing algorithms, better
documentation and more conservative CI estimates
- Enhancements and better documentation for set_order_options()
- Bug fixes in edge cases (empty elements in cells, etc.)
  • Loading branch information
piermorel committed Feb 21, 2017
1 parent 914eba4 commit c0f115b
Show file tree
Hide file tree
Showing 50 changed files with 520 additions and 160 deletions.
8 changes: 7 additions & 1 deletion @gramm/draw.m
Original file line number Diff line number Diff line change
Expand Up @@ -1137,7 +1137,7 @@
%hline
plot(xl,[obj.abline.yintercept(line_ind) obj.abline.yintercept(line_ind)],obj.abline.style{line_ind},'Parent',ca);
else
temp_x=linspace(xl(1),xl(2),100);
temp_x=linspace(xl(1),xl(2),500);
plot(temp_x,obj.abline.fun{line_ind}(temp_x),obj.abline.style{line_ind},'Parent',ca);
end
end
Expand Down Expand Up @@ -1196,6 +1196,9 @@
%Return maximum of an array or of a cell of arrays
if iscell(in)
out=max(cellfun(@max,in(~cellfun(@isempty,in)))); %Cellfun on non empty cells
if isempty(out)
out=NaN;
end
else
out=max(in);
end
Expand All @@ -1205,6 +1208,9 @@
%Return minimum of an array or of a cell of arrays
if iscell(in)
out=min(cellfun(@min,in(~cellfun(@isempty,in)))); %Cellfun on non empty cells
if isempty(out)
out=NaN;
end
else
out=min(in);
end
Expand Down
9 changes: 8 additions & 1 deletion @gramm/private/combnan.m
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
function res=combnan(dat)
%Combines data in single array with NaNs separating original arrays if originally in cells
if iscell(dat)
if iscell(dat)
%Remove empty cells
dat = dat(~cellfun(@isempty,dat));
if isempty(dat)
res = NaN;
return;
end

if ~iscellstr(dat)
if size(dat{1},1)==1
dat=cellfun(@(c)[c NaN],dat,'uniformOutput',false);
Expand Down
19 changes: 19 additions & 0 deletions @gramm/private/get_colormap.m
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,25 @@
230 171 2
166 118 29
102 102 102]/255;
case 'pm'
cmap= [255 205 1
0 108 184
155 153 59
109 197 224 %3bis
187 75 156
246 143 75
119 198 150
245 159 179
197 164 205
206 201 43
224 176 59
144 96 48
0 139 90
135 211 223 %Close to 3bis
101 44 144
169 15 50
236 124 174
149 191 50]/255;
otherwise
% Generate colormap using low-level function found on https://code.google.com/p/p-and-a/
if nl==1
Expand Down
5 changes: 4 additions & 1 deletion @gramm/private/plotci.m
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,10 @@
'MarkerSize',draw_data.point_size,...
'MarkerFaceColor',draw_data.color);

hndl.lines_handle=plot(xci',yci','-','Color',draw_data.color+([1 1 1]-draw_data.color)*0.5);
%hndl.lines_handle=plot(xci',yci','-','Color',draw_data.color+([1 1 1]-draw_data.color)*0.5);
hndl.lines_handle=plot(xci',yci','LineStyle',draw_data.line_style,...
'Color',draw_data.color,...
'LineWidth',draw_data.line_size/3);

case 'area'
%Transparent area (This does what we want but prevents a correct eps
Expand Down
39 changes: 15 additions & 24 deletions @gramm/private/unique_and_sort.m
Original file line number Diff line number Diff line change
Expand Up @@ -38,38 +38,29 @@
y=sort(y);%Sort first

sortopts=shiftdim(sortopts);
%Do checks on sorting array
if length(sortopts)==length(y) %Correct length ?
if isnumeric(sortopts) && sum(sort(sortopts)==(1:length(y))')==numel(y) %If we have integers and all numbers from 1 to N are there we probably have indices
disp('ordering given as indices')
y=y(sortopts);
else
%warning('Improper order array indices: using default order');
%return
disp('ordering given as values')
try
[present,order]=ismember(sortopts,y);
if sum(present)==length(y)
y=y(order);
else
warning('Improper ordering values')
end
catch
warning('Improper ordering values')
end

end
%If correct lengt and we have integers and all numbers from 1 to N are there we probably have indices
if length(sortopts)==length(y) && isnumeric(sortopts) && sum(sort(sortopts)==(1:length(y))')==numel(y)
disp('ordering given as indices')
y=y(sortopts);
else
warning('Improper order array size: using default order');
return;
disp('ordering given as values')
try
%This should work whatever the lengths of either array
[present,order]=ismember(sortopts,y);
y=y(order(present));
catch
warning('Improper ordering values')
end
end

else %Other orderings
switch sortopts
case 1
y=sort(y);
y=sort(y); %default
case -1
y=flipud(sort(y)); %We use flipud instead of the 'descend' option because somehow it isn't supported for cellstr.
end
%case 0 does nothing (keep original ordering)
end

end
15 changes: 8 additions & 7 deletions @gramm/set_order_options.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,18 @@
% 'color',-1 Orders variable in descending order
% (alphabetical or numerical)
%
% 'color',[10 34 20 5], or 'color',{'S' 'M' 'L' 'XL'} Allows to directly describe
% the desired order by giving an array or a cell array.
% The values in the array should correspond to the unique
% values of the variable used for grouping. This case is robust to
% missing unique values (data can be truncated when categories are missing)
%
% 'color',[4 3 5 1 2] Uses a custom order provided with
%indices provided as an array. The indices are indices
%corresponding to unique values in sorted in ascending order
% indices provided as an array. The indices are indices
% corresponding to unique values in sorted in ascending order
% The array length must be equal to the number of unique
% values for the variable and must contain all the integers
% between 1 and the number of unique values.
%
% 'color',[10 34 20 5], or 'color',{'S' 'M' 'L' 'XL'} Allows to directly describe
% the desired order by givin an array or a cell array.
% The values in the array should correspond to the unique
% values of the variable used for grouping.

p=inputParser;
my_addParameter(p,'x',1);
Expand Down
Loading

0 comments on commit c0f115b

Please sign in to comment.