Commit a2c39ffc authored by Tom's avatar Tom

bleurgh

parent 90d8e874
......@@ -84,16 +84,17 @@ clz = cb([3 5],:);
figure('units', 'normalized', 'outerposition', [0.05 0.05 0.3 0.6])
data = [];
for i = 1:nyrs
target_yr = yrs_to_select(i);
data = [];
data{1} = yrs_educ(is_eur & yr == target_yr);
data{2} = yrs_educ(is_asi & yr == target_yr);
% data = [];
data{i, 1} = yrs_educ(is_eur & yr == target_yr);
data{i, 2} = yrs_educ(is_asi & yr == target_yr);
subplot(1, nyrs, i)
h(i) = n_rainclouds(data, clz);
h(i) = n_rainclouds(data(i,:), clz);
set(gca, 'XLim', [0 14]);
% flip plot so 'x' axis is vertical and 'y' is horizontal
......@@ -111,7 +112,7 @@ legend({'europe';'asia'}, 'Location', 'SouthEast');
%% another example of nrainclouds
yrs_to_select = [1970 1990 2010];
yrs_to_select = [1950 1970 1990 2010];
nyrs = length(yrs_to_select);
data = [];
......@@ -120,9 +121,10 @@ for i = 1:nyrs
data{i} = yrs_educ(yr == target_yr);
end
clz = cbrewer('qual', 'Set1', 3);
clz = cbrewer('qual', 'Set1', length(data));
figure('units', 'normalized', 'outerposition', [0.55 0.05 0.6 0.4])
n_rainclouds(data, clz);
set(gca, 'XLim', [-1 14]);
legend({'1970';'1990';'2010'});
xlabel('education (years)');
\ No newline at end of file
xlabel('education (years)');
tmpA = randn(150,1) + 5;
tmpB = randn(90,1) + 0;
d{1} = [tmpA' tmpB'];
tmpA = (1.5 .* randn(100,1)) + 3.5;
tmpB = (0.8 .* randn(90,1)) -1;
d{2} = [tmpA' tmpB'];
tmpA = (2 .* randn(120,1)) - 5;
tmpB = (0.5 .* randn(30,1)) + 4;
d{3} = [tmpA' tmpB'];
cl(1,:) = ([0.1 0.3 0.8]);
cl(2,:) = ([0.4 0.6 0.9]);
cl(3,:) = ([0.7 0.9 1]);
figure;
subplot(3,1,1), raincloud_plot(d{1}, cl(1,:));
subplot(3,1,2), raincloud_plot(d{2}, cl(2,:));
subplot(3,1,3), raincloud_plot(d{3}, cl(3,:));
\ No newline at end of file
......@@ -11,23 +11,32 @@
% Thanks to Jacob Bellmund for some improvements
function h = raincloud_plot(X, cl, density_type, box_on)
function [h, u] = raincloud_plot(X, cl, box_on, bandwidth, density_type)
if ~exist('density_type', 'var') | isempty(density_type)
density_type = 'ks'; % default is 'ks', can also be 'rash'
% if ~exist('density_type', 'var') | isempty(density_type)
% density_type = 'ks'; % default is 'ks', can also be 'rash'
% end
if nargin < 3
box_on = 1;
end
if nargin < 4
box_on = 1;
bandwidth = [];
end
if nargin < 5
density_type = 'ks';
end
% calculate kernel density
switch density_type
case 'ks'
[f, Xi] = ksdensity(X);
[f, Xi, u] = ksdensity(X, 'bandwidth', bandwidth);
case 'rash'
try
[Xi, f] = rst_RASH(X);
u = NaN; % not sure how to handle this with RASH yet
catch
disp('you''ve specified density_type = ''RASH'', but something''s gone wrong.')
disp('Have you downloaded Cyril Pernet''s robust stats toolbox?');
......
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