Skip to content

Commit

Permalink
Added toggles for row/column labels, improved handling of empty subsets
Browse files Browse the repository at this point in the history
  • Loading branch information
piermorel committed Sep 8, 2017
1 parent 31fd1f3 commit db98e4b
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 9 deletions.
26 changes: 17 additions & 9 deletions @gramm/draw.m
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@
uni_fig=num2cell(uni_fig);
end
if numel(uni_fig)>1 %if multiple figures
fig_pos=get(obj.parent,'Position'); %We'll create them wirth the same location and size as the current figure
fig_pos=get(obj.parent,'Position'); %We'll create them with the same location and size as the current figure
%Convert to a cell
obj={obj};
for ind_fig=2:numel(uni_fig) %Make shallow copy of original object
Expand All @@ -116,17 +116,25 @@
%disp(['Plotting Fig ' num2str(ind_fig)])
%We plot what we want by setlecting within aes on the basis of fig
obj{ind_fig}.aes=select_aes(obj{ind_fig}.aes,multi_sel(obj{ind_fig}.aes.fig,uni_fig{ind_fig}));
%Set title
obj{ind_fig}.set_title([obj{ind_fig}.aes_names.fig ': ' num2str(uni_fig{ind_fig})]);
%Create figure and do the drawing
if ind_fig>1
obj{ind_fig}.parent=figure('Position',fig_pos);
% Skip if there is no data
if any(obj{ind_fig}.aes.subset)
%Set title
obj{ind_fig}.set_title([obj{ind_fig}.aes_names.fig ': ' num2str(uni_fig{ind_fig})]);
%Create figure and do the drawing
if ind_fig>1
obj{ind_fig}.parent=figure('Position',fig_pos);
end
obj{ind_fig}.draw();
end
obj{ind_fig}.draw();
end
return;
end

if ~any(obj.aes.subset)
disp('Empty subset, nothing to draw');
return;
end

%Apply subset
temp_aes=select_aes(obj.aes,obj.aes.subset);

Expand Down Expand Up @@ -550,7 +558,7 @@

%Show facet values in titles
if obj.updater.first_draw || obj.updater.facet_updated
if length(uni_column)>1
if length(uni_column)>1 && obj.column_labels
if ~isempty(obj.aes_names.column)
column_string=[obj.aes_names.column ': ' num2str(uni_column{ind_column})];
else
Expand All @@ -571,7 +579,7 @@
'Parent',obj.facet_axes_handles(ind_row,ind_column))];
end
end
if length(uni_row)>1
if length(uni_row)>1 && obj.row_labels
if ~isempty(obj.aes_names.row)
row_string=[obj.aes_names.row ': ' num2str(uni_row{ind_row})];
else
Expand Down
4 changes: 4 additions & 0 deletions @gramm/facet_grid.m
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,14 @@
my_addParameter(p,'scale','fixed'); %options 'free' 'free_x' 'free_y' 'independent'
my_addParameter(p,'space','fixed'); %'free_x','free_y','free'
my_addParameter(p,'force_ticks',false);
my_addParameter(p,'column_labels',true);
my_addParameter(p,'row_labels',true);
parse(p,varargin{:});

obj.facet_scale=p.Results.scale;
obj.facet_space=p.Results.space;
obj.column_labels=p.Results.column_labels;
obj.row_labels=p.Results.row_labels;

if strcmp(obj.facet_scale,'independent') %Force ticks by default in that case
obj.force_ticks=true;
Expand Down
2 changes: 2 additions & 0 deletions @gramm/facet_wrap.m
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@
my_addParameter(p,'ncols',4);
my_addParameter(p,'scale','fixed'); %options 'free' 'free_x' 'free_y'
my_addParameter(p,'force_ticks',false);
my_addParameter(p,'column_labels',true);
parse(p,varargin{:});

obj.facet_scale=p.Results.scale;
obj.column_labels=p.Results.column_labels;

if strcmp(obj.facet_scale,'independent') || strcmp(obj.facet_scale,'free') %Force ticks by default in these case
obj.force_ticks=true;
Expand Down
2 changes: 2 additions & 0 deletions @gramm/gramm.m
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@
facet_scale='fixed' %Do we have independent scales between facets ?
facet_space='fixed' %Do scale axes between facets ?
force_ticks=false %Do we force ticks on all facets
row_labels=true;
column_labels=true;

%structure containing the abline parameters
abline=struct('on',0,...
Expand Down
Binary file modified gramm cheat sheet.pdf
Binary file not shown.

0 comments on commit db98e4b

Please sign in to comment.