Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
raacampbell committed Mar 14, 2017
2 parents d7fcd27 + 35b01d6 commit f8e4b96
Show file tree
Hide file tree
Showing 14 changed files with 680 additions and 398 deletions.
23 changes: 22 additions & 1 deletion README.md
Expand Up @@ -14,8 +14,9 @@ The function has several examples and there are various visualization possibilit
Although it's worked well for situations I've needed it, I will be happy to modify the function if users come up against problems.

## Features
- Directly plot LinearModel objects from `fitlm` [NEW]
- Easily mix a variety of plot styles on one figure
- Easy post-hod modification of plot parameters via returned function handles
- Easy post-hoc modification of plot parameters via returned function handles
- Statistics (mean, SD, etc) optionally returned
- Optional plotting of median in addition to mean
- Option to plot either a 95% confidence interval for the mean or a 95% t-interval
Expand All @@ -34,3 +35,23 @@ A: Most modifications can be done using the function handles. See the function h

## Installation
Add the ``code`` directory to your MATLAB path. Does not rely on any toolboxes.


## Changelog

**v1.2 (28-08-16)**

* Add median to plots
* Select SEM or t-interval from command line
* Return stats as second output
* Move to parameter/value pairs by default and warn user if they aren't doing this.
* Add unit tests.

**v1.3 (11-09-16)**

* Remove legacy calls
* Allow passing of a table, which automatically labels the axes
* Pass a LinearModel, which automatically labels the axes and uses the model errors
* Examples are now in separate files and doc text is neater
* User can now optionally do `notBoxPlot(y,'jitter',0.5)` instead of `notBoxPlot(y,[],'jitter',0.5)`

7 changes: 3 additions & 4 deletions code/+NBP/SEM_calc.m
@@ -1,7 +1,7 @@
function sem=SEM_calc(vect, CI)
% SEM_calc - standard error of the mean, confidence interval
%
% function sem=SEM_calc(vect, CI)
% function sem = NBP.SEM_calc(vect, CI)
%
% Purpose
% Calculate the standard error the mean to a given confidence
Expand Down Expand Up @@ -31,8 +31,10 @@
% plot([mean(r)-S,mean(r)+S], [mean(ylim),mean(ylim)],'r-')
% hold off
%
%
% Rob Campbell
%
%
% Also see - tInterval_Calc, norminv

narginchk(1,2)
Expand All @@ -51,6 +53,3 @@

sem = ( (nanstd(vect)) ./ sqrt(sum(~isnan(vect))) ) * stdCI ;




30 changes: 30 additions & 0 deletions code/+NBP/jitterExamples.m
@@ -0,0 +1,30 @@
function jitterExamples

%
% % Jitter examples
% % default jitter is 0.3
%
% clf
%
% R = randn(20,5);
%
% subplot(2,1,1)
% notBoxPlot(R,'jitter',0.15)
%
% subplot(2,1,2)
% notBoxPlot(R,'jitter',0.75);
%

help(['NBP.',mfilename])

clf

R = randn(20,5);

subplot(2,1,1)
notBoxPlot(R,'jitter',0.15)

subplot(2,1,2)
notBoxPlot(R,'jitter',0.75);


36 changes: 36 additions & 0 deletions code/+NBP/lineExamples.m
@@ -0,0 +1,36 @@
function lineExamples

% % Mixing lines and areas [note that the way notBoxPlot
% % sets the x axis limits can cause problems when combining plots
% % this way]
%
% clf
%
% subplot(1,2,1)
% h=notBoxPlot(randn(10,1)+4,5,'style','line');
% set(h.data,'color','m')
% h=notBoxPlot(randn(50,10));
% set(h(5).data,'color','m')
%
% subplot(1,2,2)
% y=randn(50,1);
% clf
% notBoxPlot(y,1,'style','sdline')
% notBoxPlot(y,2)
% xlim([0,3])

help(['NBP.',mfilename])

clf

subplot(1,2,1)
h=notBoxPlot(randn(10,1)+4,5,'style','line');
set(h.data,'color','m')
h=notBoxPlot(randn(50,10));
set(h(5).data,'color','m')

subplot(1,2,2)
y=randn(50,1);
notBoxPlot(y,1,'style','sdline')
notBoxPlot(y,2)
xlim([0,3])
105 changes: 105 additions & 0 deletions code/+NBP/linearModelExamples.m
@@ -0,0 +1,105 @@
function linearModelExamples

% % Linear model call format
%
%
% % Build data
% rng(555),
% n=10;
% R=rand(n,5);
% R(:,3)=R(:,3)+1;
%
% X=repmat(1:5,size(R,1),1);
% lemmings=R(:);
% group=X(:);
%
% clf
%
% % We can call notBoxPlot with just X and Y
% subplot(2,2,1)
% notBoxPlot(lemmings,group,'jitter',0.75)
% grid on, box on
% ylim([-0.5,2.2])
% title('two vectors')
%
% % We can create a table and get the same plot plus the variable names on the axes
% subplot(2,2,2)
% T = table(lemmings,group);
% notBoxPlot(T,'jitter',0.75)
% grid on, box on
% ylim([-0.5,2.2])
% title('table')
%
% % We can fit a linear model do the data and plot this
% subplot(2,2,3)
% group = categorical(group);
% T = table(lemmings,group);
% M = fitlm(T,'lemmings ~ group');
% notBoxPlot(M,'jitter',0.75)
% grid on, box on
% ylim([-0.5,2.2])
% title('model')
%
% % Increase variance of one group
% subplot(2,2,4)
% lemmings(end-n+1:end) = lemmings(end-n+1:end)*1.75;
% T = table(lemmings,group);
% M = fitlm(T,'lemmings ~ group');
% notBoxPlot(M,'jitter',0.75)
% grid on, box on
% ylim([-0.5,2.2])
% title('increased variance in group 5')

help(['NBP.',mfilename])




% Build data
rng(555),
n=10;
R=rand(n,5);
R(:,3)=R(:,3)+1;

X=repmat(1:5,size(R,1),1);
lemmings=R(:);
group=X(:);


clf

% We can call notBoxPlot with just X and Y
subplot(2,2,1)
notBoxPlot(lemmings,group,'jitter',0.75)
grid on, box on
ylim([-0.5,2.2])
title('two vectors')

% We can create a table and get the same plot plus the variable names on the axes
subplot(2,2,2)
T = table(lemmings,group);
notBoxPlot(T,'jitter',0.75)
grid on, box on
ylim([-0.5,2.2])
title('table')

% We can fit a linear model do the data and plot this
subplot(2,2,3)
group = categorical(group);
T = table(lemmings,group);
M = fitlm(T,'lemmings ~ group');
notBoxPlot(M,'jitter',0.75)
grid on, box on
ylim([-0.5,2.2])
title('model')


% Increase variance of one group
subplot(2,2,4)
lemmings(end-n+1:end) = lemmings(end-n+1:end)*1.75;
T = table(lemmings,group);
M = fitlm(T,'lemmings ~ group');
notBoxPlot(M,'jitter',0.75)
grid on, box on
ylim([-0.5,2.2])
title('increased variance in group 5')
63 changes: 39 additions & 24 deletions code/+NBP/example.m → code/+NBP/showCase.m
@@ -1,13 +1,28 @@
function example
% Pretty example use of notBoxPlot

disp('Running example')
function showCase
% Example showing a variety of effects possible with notBoxPlot
%
% function NBP.showCase
%
%
% Purpose
% Showcase notBoxPlot
%
%
% No inputs or outputs
%
%
% Rob Campbell



W=which(['NBP.',mfilename]);
fprintf('Running example located at %s\n',W)

hFig=figure(1984);

set(hFig,...
'Name','notBoxPlot example',...
'PaperPosition',[0,0,12,9]) %Just to make save to disk consistent)
'Name','notBoxPlot example',...
'PaperPosition',[0,0,12,9]) %Just to make save to disk consistent)
clf

W=0.45; %image width
Expand Down Expand Up @@ -38,33 +53,33 @@

%higher means as green
set([H(find(IND)).data],'MarkerSize',4,...
'markerFaceColor',[1,1,1]*0.25,...
'markerEdgeColor', 'none')
'markerFaceColor',[1,1,1]*0.25,...
'markerEdgeColor', 'none')
set([H(find(IND)).semPtch],...
'FaceColor',[0,0.75,0],...
'EdgeColor','none')
'FaceColor',[0,0.75,0],...
'EdgeColor','none')
set([H(find(IND)).sdPtch],...
'FaceColor',[0.6,1,0.6],...
'EdgeColor','none')
'FaceColor',[0.6,1,0.6],...
'EdgeColor','none')
set([H(find(IND)).mu],...
'Color',[0,0.4,0])
'Color',[0,0.4,0])


set(gca,'XTick',[])


%lower means as gray
set([H(find(~IND)).data],'MarkerSize',4,...
'markerFaceColor',[1,1,1]*0.5,...
'markerEdgeColor', 'none')
'markerFaceColor',[1,1,1]*0.5,...
'markerEdgeColor', 'none')
set([H(find(~IND)).semPtch],...
'FaceColor',[1,1,1]*0.25,...
'EdgeColor','none')
'FaceColor',[1,1,1]*0.25,...
'EdgeColor','none')
set([H(find(~IND)).sdPtch],...
'FaceColor',[1,1,1]*0.75,...
'EdgeColor','none')
'FaceColor',[1,1,1]*0.75,...
'EdgeColor','none')
set([H(find(~IND)).mu],...
'Color','b')
'Color','b')

box on

Expand All @@ -79,7 +94,7 @@

H=notBoxPlot(y,x,'jitter',0.6,'style','sdline');
set(H(end).data,'Marker','^',...
'MarkerSize',5)
'MarkerSize',5)
set([H.sd],'LineWidth',4)
box on
grid on
Expand All @@ -97,9 +112,9 @@

H=notBoxPlot(r,[],'jitter',0.5);
set([H.data],...
'MarkerFaceColor',[1,1,1]*0.35,....
'markerEdgeColor',[1,1,1]*0.35,...
'MarkerSize',3)
'MarkerFaceColor',[1,1,1]*0.35,...
'markerEdgeColor',[1,1,1]*0.35,...
'MarkerSize',3)

set([H.mu],'color','w')
J=jet(length(H));
Expand Down
44 changes: 44 additions & 0 deletions code/+NBP/simpleExamples.m
@@ -0,0 +1,44 @@
function simpleExamples
%
% clf
%
% subplot(2,2,1)
% notBoxPlot(randn(20,5));
%
% subplot(2,2,2)
% notBoxPlot(randn(20,5),[1:4,7]);
%
% subplot(2,2,3)
% h=notBoxPlot(randn(10,20));
% d=[h.data];
% set(d(1:4:end),'markerfacecolor',[0.4,1,0.4],'color',[0,0.4,0])
%
% subplot(2,2,4)
% x=[1,2,3,4,5,5];
% y=randn(20,length(x));
% y(:,end)=y(:,end)+3;
% y(:,end-1)=y(:,end-1)-1;
% notBoxPlot(y,x);

help(['NBP.',mfilename])

clf

subplot(2,2,1)
notBoxPlot(randn(20,5));

subplot(2,2,2)
notBoxPlot(randn(20,5),[1:4,7]);

subplot(2,2,3)
h=notBoxPlot(randn(10,20));
d=[h.data];
set(d(1:4:end),'markerfacecolor',[0.4,1,0.4],'color',[0,0.4,0])


subplot(2,2,4)
x=[1,2,3,4,5,5];
y=randn(20,length(x));
y(:,end)=y(:,end)+3;
y(:,end-1)=y(:,end-1)-1;
notBoxPlot(y,x);

0 comments on commit f8e4b96

Please sign in to comment.