Commit 49667e5b authored by Tom's avatar Tom

moved to public for teaching

parent dcefae19
File added
% barplot with raw datapoints
% usage: h = scatterbars(data)
% where data is an n x m matrix of data
% plots m bars, with bar height 'nanmean(data)'
% optional second argument jitterWidth controls x-axis spread of dots
%
% example usage
% x = rand(30,4); % generate some raw data
% x(1:20,3) = NaN; % scatterbars can handle missing data
% figure; h = scatterbars(x); % plot
function [h] = scatterbars(data, jitterWidth)
% specify dot jitter width if not already specified
if nargin < 2
jitterWidth = 0.2;
end
% random jitter in the x-dimension for the dots
jitter = (rand(size(data)) - 0.5) * jitterWidth;
[nRows, nCols] = size(data);
offsets = repmat(1:nCols,nRows,1);
hold on
% bar heights
means = nanmean(data);
% plot
for i = 1:nCols
% bars
h.bar(i) = bar(i, means(i));
% dots
h.dots(i) = scatter((jitter(:,i) + offsets(:,i)), data(:,i));
end
% apply some global properties to all dots
set(h.dots, 'MarkerFaceColor', [0.5 0.5 0.5]);
set(h.dots, 'MarkerEdgeColor', [1 1 1]);
\ No newline at end of file
function [h,h2]=scatterline(data2plot)
jit = (rand(size(data2plot))-0.5) * 0.1;
[nrows, ncolz] = size(data2plot);
offsets = repmat(1:ncolz,nrows,1);
hold on
h2 = plot(mean(data2plot));
h=scatter((jit(:) + offsets(:)), data2plot(:));
set(h,'MarkerFaceColor',[0.5 0.5 0.5]);
% set(h,'MarkerFaceAlpha',0.5);
% set(h,'MarkerEdgeAlpha',0.5);
set(h,'MarkerEdgeColor',[1 1 1]);
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment