Skip to content

Instantly share code, notes, and snippets.

@FFroehlich
Created December 6, 2016 17:23
Show Gist options
  • Save FFroehlich/e76e713e201ec243a21490bfebdfd7c7 to your computer and use it in GitHub Desktop.
Save FFroehlich/e76e713e201ec243a21490bfebdfd7c7 to your computer and use it in GitHub Desktop.
gramm order example
% goal: plot barplots sorted according to their y value
xx = {'C','C','C','B','B','B','A','A','A'};
yy = [ 2 , 1 , 3 , 3 , 2 , 1 , 1 , 3 , 2 ];
type = [ 1 , 2 , 3 , 1 , 2 , 3 , 1 , 2 , 3 ];
subset = type==1;
subx = xx(subset);
suby = yy(subset);
disp(['expected outcome' subx(order) ': ' num2str(suby(order))])
g(1,1) = gramm('x',xx,'y',yy,'subset',subset);
g(1,1).geom_bar();
% ideally I would like to use [~,order] = sort(yy); here
[~,order] = sort(yy(subset));
g(1,2) = gramm('x',xx,'y',yy,'subset',subset);
g(1,2).geom_bar();
% I was expecting to be able to do g(1,2).set_order_options('y',1)
g(1,2).set_order_options('x',order);
% the gramm cheat sheet states "Values ordered according as in the provided array/cell (all unique values have to be
% present in the array/cell)"
% but in line 38 of unique_and_sort.m "y=sort(y)" is applied which shuffles the provided order
[~,reorder] = sort(subx);
disp(['outcome' subx(reorder(order)) ': ' num2str(suby(reorder(order)))])
figure
g.draw()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment