Skip to content

Commit

Permalink
Added option to give desired ordering more intuitively
Browse files Browse the repository at this point in the history
  • Loading branch information
piermorel committed Mar 21, 2016
1 parent da4dedc commit 761872d
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 12 deletions.
23 changes: 16 additions & 7 deletions examples.m
Original file line number Diff line number Diff line change
Expand Up @@ -595,24 +595,33 @@
g(1,2)=gramm('x',x,'y',y,'lightness',x)
g(1,2).stat_summary('geom','bar')


%By using set_order_options('x',0), x are presented in the raw input order. The
%color is still sorted

g(2,1)=gramm('x',x,'y',y,'lightness',x)
g(2,1).stat_summary('geom','bar')
g(2,1).set_order_options('x',0)

%By using set_order_options('x',0,'lightness',0), both x and lightness are
%presented in the raw input order
%By using set_order_options('x',0,'lightness',{'XS' 'S' 'M' 'L' 'XL'
%'XXL'}), we also order lightness in the desired order, here by
%directly providing the desired order.
g(2,2)=gramm('x',x,'y',y,'lightness',x)
g(2,2).stat_summary('geom','bar')
g(2,2).set_order_options('x',0,'lightness',0)

%It is possible to set up a custom order (indices within the sorted
%input), here used to inverse lightness map
g(2,2).set_order_options('x',0,'lightness',{'XS' 'S' 'M' 'L' 'XL' 'XXL'})
%Examples below properly fail
%g(2,2).set_order_options('x',0,'lightness',{'XXL' 'XL' 'L' 'M' 'S' 'B'})
%g(2,2).set_order_options('x',0,'lightness',{'XXL' 'XL' 'L' 'M' 'S' 1})
%g(2,2).set_order_options('x',0,'lightness',{'XXL' 'XL' 'L' 'M' 'S'})

%It is also possible to set up a custom order (indices within the sorted
%input), here used to inverse lightness map. This way is a bit more
%practical for floating point numerical variables. For cells of string, the
%way above is easier.
g(2,3)=gramm('x',x,'y',y,'lightness',x)
g(2,3).stat_summary('geom','bar')
g(2,3).set_order_options('x',0,'lightness',[6 4 1 2 3 5])
%Exampel below properly fail
%g(2,3).set_order_options('x',0,'lightness',[6 4 1 2 3 3])

g.set_names('x','US size','y','EU size','lightness','US size')
g.draw()
Expand Down
25 changes: 20 additions & 5 deletions gramm.m
Original file line number Diff line number Diff line change
Expand Up @@ -3803,15 +3803,30 @@ function my_addParameter(parser,name,value)
sortopts=shiftdim(sortopts);
%Do checks on sorting array
if length(sortopts)==length(y) %Correct length ?
if sum(sort(sortopts)==(1:length(y))')~=numel(y) %All indices ?
warning('Improper order array indices: using default order');
return
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
else
warning('Improper order arrray size: using default order');
warning('Improper order array size: using default order');
return;
end
y=y(sortopts);


else %Other orderings
switch sortopts
Expand Down

0 comments on commit 761872d

Please sign in to comment.