Skip to content

Commit

Permalink
Added customization options for text, lines and points
Browse files Browse the repository at this point in the history
- Added set_line_options(): style, size
- Added set_point_options(): markers, size
- Added set_text_options(): font, sizes
- Corrected bug with iscategorical() on old matlab versions
  • Loading branch information
piermorel committed Aug 7, 2016
1 parent 1328702 commit 5a2ec93
Show file tree
Hide file tree
Showing 53 changed files with 597 additions and 123 deletions.
194 changes: 151 additions & 43 deletions @gramm/draw.m

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion @gramm/geom_bar.m
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@

hndl=patch([x-width/2 ; x+width/2 ; x+width/2 ; x-width/2],...
[obj.extra.stacked_bar_height(x_stack_ind) ; obj.extra.stacked_bar_height(x_stack_ind) ; obj.extra.stacked_bar_height(x_stack_ind)+y ; obj.extra.stacked_bar_height(x_stack_ind)+y],...
draw_data.color,'EdgeColor','k');
draw_data.color,...
'EdgeColor','k',...
'LineWidth',draw_data.line_size);

obj.results.geom_bar_handle{obj.result_ind,1}=hndl;

Expand Down
2 changes: 1 addition & 1 deletion @gramm/geom_jitter.m
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
end

%hndl=my_point(obj,draw_data);
hndl=line(draw_data.x,draw_data.y,'LineStyle','none','Marker',draw_data.marker,'MarkerEdgeColor','none','markerSize',draw_data.size,'MarkerFaceColor',draw_data.color);
hndl=line(draw_data.x,draw_data.y,'LineStyle','none','Marker',draw_data.marker,'MarkerEdgeColor','none','markerSize',draw_data.point_size,'MarkerFaceColor',draw_data.color);

obj.results.geom_jitter_handle{obj.result_ind,1}=hndl;
end
10 changes: 5 additions & 5 deletions @gramm/geom_line.m
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@
if iscell(x)
for k=1:length(x)
if iscell(draw_data.continuous_color) %Within-line continuous color given
hndl=patch([shiftdim(x{k}) ; flipud(shiftdim(x{k}))],[shiftdim(y{k}) ; flipud(shiftdim(y{k}))],[shiftdim(draw_data.continuous_color{k}) ; flipud(shiftdim(draw_data.continuous_color{k}))],'faceColor','none','EdgeColor','interp','lineWidth',draw_data.size/4,'LineStyle',draw_data.line_style);
hndl=patch([shiftdim(x{k}) ; flipud(shiftdim(x{k}))],[shiftdim(y{k}) ; flipud(shiftdim(y{k}))],[shiftdim(draw_data.continuous_color{k}) ; flipud(shiftdim(draw_data.continuous_color{k}))],'faceColor','none','EdgeColor','interp','lineWidth',draw_data.line_size,'LineStyle',draw_data.line_style);
else %Per-line continuous color given
hndl=patch([shiftdim(x{k}) ; flipud(shiftdim(x{k}))],[shiftdim(y{k}) ; flipud(shiftdim(y{k}))],repmat(draw_data.continuous_color(k),length(x{k})*2,1),'faceColor','none','EdgeColor','interp','lineWidth',draw_data.size/4,'LineStyle',draw_data.line_style);
hndl=patch([shiftdim(x{k}) ; flipud(shiftdim(x{k}))],[shiftdim(y{k}) ; flipud(shiftdim(y{k}))],repmat(draw_data.continuous_color(k),length(x{k})*2,1),'faceColor','none','EdgeColor','interp','lineWidth',draw_data.line_size,'LineStyle',draw_data.line_style);
end
end
else
hndl=patch([shiftdim(x) ; flipud(shiftdim(x))],[shiftdim(y) ; flipud(shiftdim(y))],[shiftdim(draw_data.continuous_color) ; flipud(shiftdim(draw_data.continuous_color))],'faceColor','none','EdgeColor','interp','lineWidth',draw_data.size/4,'LineStyle',draw_data.line_style);
hndl=patch([shiftdim(x) ; flipud(shiftdim(x))],[shiftdim(y) ; flipud(shiftdim(y))],[shiftdim(draw_data.continuous_color) ; flipud(shiftdim(draw_data.continuous_color))],'faceColor','none','EdgeColor','interp','lineWidth',draw_data.line_size,'LineStyle',draw_data.line_style);
end


Expand All @@ -50,9 +50,9 @@
x=dodger(x,draw_data,params.dodge);
[x,y]=to_polar(obj,x,y);

hndl=line(combnan(x),combnan(y),'LineStyle',draw_data.line_style,'lineWidth',draw_data.size/4,'Color',draw_data.color);
hndl=line(combnan(x),combnan(y),'LineStyle',draw_data.line_style,'lineWidth',draw_data.line_size,'Color',draw_data.color);
else
hndl=line(combnan(draw_data.x),combnan(draw_data.y),combnan(draw_data.z),'LineStyle',draw_data.line_style,'lineWidth',draw_data.size/4,'Color',draw_data.color);
hndl=line(combnan(draw_data.x),combnan(draw_data.y),combnan(draw_data.z),'LineStyle',draw_data.line_style,'lineWidth',draw_data.line_size,'Color',draw_data.color);
end
end
obj.results.geom_line_handle{obj.result_ind,1}=hndl;
Expand Down
32 changes: 27 additions & 5 deletions @gramm/geom_point.m
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,27 @@
if iscell(draw_data.x)
[x,y]=to_polar(obj,draw_data.x,draw_data.y);
if iscell(draw_data.continuous_color)
hndl=scatter(comb(x),comb(y),draw_data.size*6,comb(draw_data.continuous_color),draw_data.marker,'MarkerFaceColor','flat','MarkerEdgeColor','none');
hndl=scatter(comb(x),comb(y),...
draw_data.point_size.^2,...
comb(draw_data.continuous_color),...
draw_data.marker,...
'MarkerFaceColor','flat','MarkerEdgeColor','none');
else
for k=1:length(x)
hndl=scatter(x{k},y{k},draw_data.size*6,repmat(draw_data.continuous_color(k),length(x{k}),1),draw_data.marker,'MarkerFaceColor','flat','MarkerEdgeColor','none');
hndl=scatter(x{k},y{k},...
draw_data.point_size.^2,...
repmat(draw_data.continuous_color(k),length(x{k}),1),...
draw_data.marker,...
'MarkerFaceColor','flat','MarkerEdgeColor','none');
end
end
else
[x,y]=to_polar(obj,comb(draw_data.x),comb(draw_data.y));
hndl=scatter(x,y,draw_data.size*6,draw_data.continuous_color,draw_data.marker,'MarkerFaceColor','flat','MarkerEdgeColor','none');
hndl=scatter(x,y,...
draw_data.point_size.^2,...
draw_data.continuous_color,...
draw_data.marker,...
'MarkerFaceColor','flat','MarkerEdgeColor','none');
end
obj.plot_lim.maxc(obj.current_row,obj.current_column)=max(obj.plot_lim.maxc(obj.current_row,obj.current_column),max(comb(draw_data.continuous_color)));
obj.plot_lim.minc(obj.current_row,obj.current_column)=min(obj.plot_lim.maxc(obj.current_row,obj.current_column),min(comb(draw_data.continuous_color)));
Expand All @@ -39,9 +51,19 @@
x=dodger(x,draw_data,params.dodge);

[x,y]=to_polar(obj,x,comb(draw_data.y));
hndl=line(x,y,'LineStyle','none','Marker',draw_data.marker,'MarkerEdgeColor','none','markerSize',draw_data.size,'MarkerFaceColor',draw_data.color);
hndl=line(x,y,...
'LineStyle','none',...
'Marker',draw_data.marker,...
'MarkerEdgeColor','none',...
'MarkerSize',draw_data.point_size,...
'MarkerFaceColor',draw_data.color);
else
hndl=line(comb(draw_data.x),comb(draw_data.y),comb(draw_data.z),'LineStyle','none','Marker',draw_data.marker,'MarkerEdgeColor','none','markerSize',draw_data.size,'MarkerFaceColor',draw_data.color);
hndl=line(comb(draw_data.x),comb(draw_data.y),comb(draw_data.z),...
'LineStyle','none',...
'Marker',draw_data.marker,...
'MarkerEdgeColor','none',...
'markerSize',draw_data.point_size,...
'MarkerFaceColor',draw_data.color);
end
end

Expand Down
8 changes: 4 additions & 4 deletions @gramm/geom_raster.m
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,20 @@
%Fast version
allx=[temp_x(:) temp_x(:) temp_x(:)]';
ally=[temp_y(:) temp_y(:)+0.9 NaN(numel(temp_x),1)]';
hndl=line(allx(:),ally(:),'color',draw_data.color,'lineWidth',draw_data.size/4);
hndl=line(allx(:),ally(:),'color',draw_data.color,'lineWidth',draw_data.line_size);
else
hndl=line(temp_x,temp_y,'o','MarkerEdgeColor','none','markerSize',draw_data.size,'MarkerFaceColor',draw_data.color);
hndl=line(temp_x,temp_y,'LineStyle','none','Marker','o','MarkerEdgeColor','none','markerSize',draw_data.point_size,'MarkerFaceColor',draw_data.color);
end

else

if strcmp(params.geom,'line')
allx=[shiftdim(draw_data.x) shiftdim(draw_data.x) nan(length(draw_data.x),1)]';
ally=repmat([obj.extra.raster_position obj.extra.raster_position+0.9 NaN ],length(draw_data.x),1)';
hndl=line(allx(:),ally(:),'color',draw_data.color,'lineWidth',draw_data.size/4);
hndl=line(allx(:),ally(:),'color',draw_data.color,'lineWidth',draw_data.line_size);
else
hndl=line(shiftdim(draw_data.x),repmat(obj.extra.raster_position,1,length(draw_data.x)),...
'LineStyle','none','Marker','o','MarkerEdgeColor','none','markerSize',draw_data.size,'MarkerFaceColor',draw_data.color);
'LineStyle','none','Marker','o','MarkerEdgeColor','none','markerSize',draw_data.point_size,'MarkerFaceColor',draw_data.color);
end
obj.extra.raster_position=obj.extra.raster_position+1;

Expand Down
37 changes: 20 additions & 17 deletions @gramm/gramm.m
Original file line number Diff line number Diff line change
Expand Up @@ -87,23 +87,15 @@

continuous_color_colormap=[];

%Store options for generating colors
color_options =struct('lightness_range',[85 15],...
'chroma_range',[30 90],...
'hue_range',[25 385],...
'lightness',65,...
'chroma',75,...
'map','lch')

%Store options for sorting data/categories
order_options=struct('x',1,...
'color',1,...
'marker',1,...
'linestyle',1,...
'size',1,...
'row',1,...
'column',1,...
'lightness',1)
color_options %Structure holding color options

order_options %Structure holding order options

text_options %Structure holding text options

line_options %Structure holding line options

point_options %Structure holding point options

with_legend=true %Do we have a side legend for colors etc. ?

Expand Down Expand Up @@ -175,6 +167,14 @@

obj.aes=parse_aes(varargin{:});
obj.handle_graphics=~verLessThan('matlab','8.4.0');

%Run the set_xx_options() functions without arguments to set
%defaults
set_order_options(obj);
set_color_options(obj);
set_text_options(obj);
set_line_options(obj);
set_point_options(obj);
end

obj=update(obj,varargin)
Expand All @@ -188,6 +188,9 @@
% Customization methods
obj=set_polar(obj,varargin)
obj=set_color_options(obj,varargin)
obj=set_text_options(obj,varargin)
obj=set_line_options(obj,varargin)
obj=set_point_options(obj,varargin)
obj=set_order_options(obj,varargin)
obj=set_continuous_color(obj,varargin)
obj=no_legend(obj)
Expand Down
6 changes: 3 additions & 3 deletions @gramm/private/my_histplot.m
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@
xtemp=bar_mid;
ytemp=bincounts(1:end)';
[xtemp,ytemp]=to_polar(obj,xtemp,ytemp);
results.line_handle=plot(xtemp,ytemp,'LineStyle',draw_data.line_style,'Color',edge_color,'lineWidth',draw_data.size/4);
results.line_handle=plot(xtemp,ytemp,'LineStyle',draw_data.line_style,'Color',edge_color,'lineWidth',draw_data.line_size);
xpatch=[bar_mid(1:end-1) ; bar_mid(2:end) ; bar_mid(2:end);bar_mid(1:end-1)];
ypatch=[zeros(1,length(bincounts)-1) ; zeros(1,length(bincounts)-1) ; bincounts(2:end)' ; bincounts(1:end-1)'];
[xpatch,ypatch]=to_polar(obj,xpatch,ypatch);
Expand All @@ -171,7 +171,7 @@
xtemp=[binranges(1:end-1) ; binranges(2:end)];
ytemp=[bincounts' ; bincounts'];
[xtemp,ytemp]=to_polar(obj,xtemp(:),ytemp(:));
results.line_handle=plot(xtemp,ytemp,'LineStyle',draw_data.line_style,'Color',edge_color,'lineWidth',draw_data.size/4);
results.line_handle=plot(xtemp,ytemp,'LineStyle',draw_data.line_style,'Color',edge_color,'lineWidth',draw_data.line_size);

xpatch=[binranges(1:end-1) ; binranges(2:end) ; binranges(2:end) ; binranges(1:end-1)];
ypatch=[obj.extra.stacked_bar_height ; obj.extra.stacked_bar_height ; obj.extra.stacked_bar_height+bincounts' ; obj.extra.stacked_bar_height+bincounts'];
Expand All @@ -183,7 +183,7 @@
xtemp=bar_mid;
ytemp=bincounts(1:end)';
[xtemp,ytemp]=to_polar(obj,xtemp,ytemp);
results.point_handle=plot(xtemp,ytemp,draw_data.marker,'MarkerEdgeColor','none','markerSize',draw_data.size,'MarkerFaceColor',draw_data.color);
results.point_handle=plot(xtemp,ytemp,draw_data.marker,'MarkerEdgeColor','none','markerSize',draw_data.point_size,'MarkerFaceColor',draw_data.color);
end


Expand Down
68 changes: 54 additions & 14 deletions @gramm/private/plotci.m
Original file line number Diff line number Diff line change
Expand Up @@ -59,32 +59,72 @@
for k=1:length(geom)
switch geom{k}
case 'line'
hndl.line_handle=plot(x,y,'LineStyle',draw_data.line_style,'Color',draw_data.color,'LineWidth',draw_data.size/4);
hndl.extra_point_handle=plot(x(real_neighbors==0),y(real_neighbors==0),'o','Color',draw_data.color,'MarkerSize',draw_data.size/3,'MarkerFaceColor',draw_data.color);
hndl.line_handle=plot(x,y,...
'LineStyle',draw_data.line_style,...
'Color',draw_data.color,...
'LineWidth',draw_data.line_size);

hndl.extra_point_handle=plot(x(real_neighbors==0),y(real_neighbors==0),'o',...
'Color',draw_data.color,...
'MarkerSize',draw_data.point_size,...
'MarkerFaceColor',draw_data.color);

case 'lines'
hndl.line_handle=plot(x,y,'LineStyle',draw_data.line_style,'Color',draw_data.color,'LineWidth',draw_data.size/4);
hndl.extra_point_handle=plot(x(real_neighbors==0),y(real_neighbors==0),'o','Color',draw_data.color,'MarkerSize',draw_data.size/3,'MarkerFaceColor',draw_data.color);
hndl.line_handle=plot(x,y,...
'LineStyle',draw_data.line_style,...
'Color',draw_data.color,...
'LineWidth',draw_data.line_size);

hndl.extra_point_handle=plot(x(real_neighbors==0),y(real_neighbors==0),'o',...
'Color',draw_data.color,...
'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);

case 'area'
%Transparent area (This does what we want but prevents a correct eps
hndl.area_handle=patch('Vertices',vertices,'Faces',faces,'FaceColor',draw_data.color,'FaceAlpha',0.2,'EdgeColor','none');
hndl.line_handle=plot(x,y,'LineStyle',draw_data.line_style,'Color',draw_data.color,'LineWidth',draw_data.size/4);
hndl.extra_point_handle=plot(x(real_neighbors==0),y(real_neighbors==0),'o','Color',draw_data.color,'MarkerSize',draw_data.size/3,'MarkerFaceColor',draw_data.color);
%plot([x(real_neighbors==0) ; x(real_neighbors==0)], [yci(1,real_neighbors==0) ; yci(2,real_neighbors==0)],'Color',draw_data.color)
hndl.area_handle=patch('Vertices',vertices,...
'Faces',faces,...
'FaceColor',draw_data.color,...
'FaceAlpha',0.2,...
'EdgeColor','none');

hndl.line_handle=plot(x,y,...
'LineStyle',draw_data.line_style,...
'Color',draw_data.color,...
'LineWidth',draw_data.line_size);

hndl.extra_point_handle=plot(x(real_neighbors==0),y(real_neighbors==0),'o',...
'Color',draw_data.color,...
'MarkerSize',draw_data.point_size,...
'MarkerFaceColor',draw_data.color);

case 'area_only'
hndl.area_handle=patch('Vertices',vertices,'Faces',faces,'FaceColor',draw_data.color,'FaceAlpha',0.2,'EdgeColor','none');

case 'solid_area'
%Solid area (no alpha)
hndl.area_handle=patch('Vertices',vertices,'Faces',faces,'FaceColor',draw_data.color,'EdgeColor','none');
hndl.line_handle=plot(x,y,'LineStyle',draw_data.line_style,'Color',draw_data.color,'LineWidth',draw_data.size/4);
hndl.extra_point_handle=plot(x(real_neighbors==0),y(real_neighbors==0),'o','Color',draw_data.color,'MarkerSize',draw_data.size/3,'MarkerFaceColor',draw_data.color);
hndl.area_handle=patch('Vertices',vertices,...
'Faces',faces,...
'FaceColor',draw_data.color,...
'EdgeColor','none');

hndl.line_handle=plot(x,y,...
'LineStyle',draw_data.line_style,...
'Color',draw_data.color,...
'LineWidth',draw_data.line_size);

hndl.extra_point_handle=plot(x(real_neighbors==0),y(real_neighbors==0),'o',...
'Color',draw_data.color,...
'MarkerSize',draw_data.point_size,...
'MarkerFaceColor',draw_data.color);

case 'errorbar'
hndl.errorbar_handle=my_errorbar(x,yci(1,:),yci(2,:),bar_width/4,draw_data.color,draw_data.size/4);
hndl.errorbar_handle=my_errorbar(x,yci(1,:),yci(2,:),bar_width/4,draw_data.color,draw_data.line_size);

case 'black_errorbar'
hndl.errorbar_handle=my_errorbar(x,yci(1,:),yci(2,:),bar_width/4,'k',draw_data.size/4);
hndl.errorbar_handle=my_errorbar(x,yci(1,:),yci(2,:),bar_width/4,'k',draw_data.line_size);

case 'bar'
barleft=x-bar_width/2;
Expand All @@ -101,7 +141,7 @@
[xpatch,ypatch]=to_polar(obj,xpatch,ypatch);
hndl.bar_handle=patch(xpatch,ypatch,[1 1 1],'FaceColor',draw_data.color,'EdgeColor','k');
case 'point'
hndl.point_handle=plot(x,y,draw_data.marker,'MarkerEdgeColor','none','markerSize',draw_data.size,'MarkerFaceColor',draw_data.color);
hndl.point_handle=plot(x,y,draw_data.marker,'MarkerEdgeColor','none','markerSize',draw_data.point_size,'MarkerFaceColor',draw_data.color);
end

end
Expand Down
17 changes: 12 additions & 5 deletions @gramm/private/unique_and_sort.m
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,20 @@
% Unique() function that ignores NaNs in arrays and empty values as well as 'NA' in
% cellstrs, and sorts according to sortopts

persistent old_matlab
if isempty(old_matlab)
old_matlab=verLessThan('matlab','7.14');
%For unique() options
persistent old_matlab_2012
if isempty(old_matlab_2012)
old_matlab_2012=verLessThan('matlab','7.14');
end

%For iscategorical()
persistent old_matlab_2013
if isempty(old_matlab_2013)
old_matlab_2013=verLessThan('matlab','8.2');
end

%Create unique in original order
if old_matlab
if old_matlab_2012
[y,ia,~]=unique(x);
[~,ind]=sort(ia); %Trick to get the original order in older matlab versions
y=y(ind);
Expand All @@ -18,7 +25,7 @@

%Clean up uniques
if ~iscell(x)
if ~iscategorical(y)
if ~old_matlab_2013 && ~iscategorical(y)
y(isnan(y)) = []; % remove all nans
end
else
Expand Down
Loading

0 comments on commit 5a2ec93

Please sign in to comment.