Commit 81ee4801 authored by Tom Marshall's avatar Tom Marshall

some tweaks thanks to Jacob Bellmund

parent deb13204
......@@ -2,6 +2,7 @@
% https://data.bris.ac.uk/datasets/112g2vkxomjoo1l26vjmvnlexj/2016.08.14_AnxietyPaper_Data%20Sheet.csv
mydir = 'insert path here';
mydir = '/Users/marshall/Desktop';
myfile = '2016.08.14_AnxietyPaper_Data Sheet.csv';
f = fopen(fullfile(mydir,myfile));
......
%% raincloud_plot - plots a combination of half-violin, boxplot, and raw
% datapoints (1d scatter).
% Use as h = raincloud_plot(X, cl), where X is a data vector and cl is an
% RGB value. h is a cell array of handles for the various figure parts.
% Based on https://micahallen.org/2018/03/15/introducing-raincloud-plots/
% Inspired by https://m.xkcd.com/1967/
function h = raincloud_plot(X, cl)
% calculate kernel density
[f, Xi] = ksdensity(X);
% width of boxplot
wdth = 0.8;
% TODO, should probably be some percentage of max height of kernel density plot
% density plot
h{1} = area(Xi, f); hold on
set(h{1}, 'FaceColor', cl);
set(h{1}, 'EdgeColor', [0.1 0.1 0.1]);
set(h{1}, 'LineWidth', 2);
% make some space under the density plot for the boxplot
yl = get(gca, 'YLim');
set(gca, 'YLim', [-2 yl(2)]);
% jitter for raindrops
jit = (rand(size(X)) - 0.5) * wdth;
% info for making boxplot
Y = quantile(X, [0.25 0.75 0.5 0.02 0.98]);
% raindrops
h{2} = scatter(X, jit - 1);
h{2}.SizeData = 10;
h{2}.MarkerFaceColor = cl;
h{2}.MarkerEdgeColor = 'none';
% 'box' of 'boxplot'
h{3} = rectangle('Position', [Y(1) -1-(wdth*0.5) Y(2)-Y(1) wdth]);
set(h{3}, 'EdgeColor', 'k')
set(h{3}, 'LineWidth', 2);
% could also set 'FaceColor' here as Micah does, but I prefer without
% mean line
h{4} = line([Y(3) Y(3)], [-1-(wdth*0.5) -1+(wdth*0.5)], 'col', 'k', 'LineWidth', 2);
% whiskers
h{5} = line([Y(2) Y(5)], [-1 -1], 'col', 'k', 'LineWidth', 2);
h{6} = line([Y(1) Y(4)], [-1 -1], 'col', 'k', 'LineWidth', 2);
%% raincloud_plot - plots a combination of half-violin, boxplot, and raw
% datapoints (1d scatter).
% Use as h = raincloud_plot(X, cl), where X is a data vector and cl is an
% RGB value. h is a cell array of handles for the various figure parts.
% Based on https://micahallen.org/2018/03/15/introducing-raincloud-plots/
% Inspired by https://m.xkcd.com/1967/
% Thanks to Jacob Bellmund for some improvements
function h = raincloud_plot(X, cl)
% calculate kernel density
[f, Xi] = ksdensity(X);
% density plot
h{1} = area(Xi, f); hold on
set(h{1}, 'FaceColor', cl);
set(h{1}, 'EdgeColor', [0.1 0.1 0.1]);
set(h{1}, 'LineWidth', 2);
% make some space under the density plot for the boxplot
yl = get(gca, 'YLim');
set(gca, 'YLim', [-yl(2) yl(2)]);
% width of boxplot
wdth = yl(2)*0.5;
% jitter for raindrops
jit = (rand(size(X)) - 0.5) * wdth;
% info for making boxplot
Y = quantile(X, [0.25 0.75 0.5 0.02 0.98]);
% raindrops
h{2} = scatter(X, jit - yl(2)/2);
h{2}.SizeData = 10;
h{2}.MarkerFaceColor = cl;
h{2}.MarkerEdgeColor = 'none';
% 'box' of 'boxplot'
h{3} = rectangle('Position', [Y(1) -yl(2)/2-(wdth*0.5) Y(2)-Y(1) wdth]);
set(h{3}, 'EdgeColor', 'k')
set(h{3}, 'LineWidth', 2);
% could also set 'FaceColor' here as Micah does, but I prefer without
% mean line
h{4} = line([Y(3) Y(3)], [-yl(2)/2-(wdth*0.5) -yl(2)/2+(wdth*0.5)], 'col', 'k', 'LineWidth', 2);
% whiskers
h{5} = line([Y(2) Y(5)], [-yl(2)/2 -yl(2)/2], 'col', 'k', 'LineWidth', 2);
h{6} = line([Y(1) Y(4)], [-yl(2)/2 -yl(2)/2], 'col', 'k', 'LineWidth', 2);
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