Matlab 中的类似差值箱线图的图 [英] A difference-in-difference boxplot-like plot in Matlab

查看:45
本文介绍了Matlab 中的类似差值箱线图的图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有兴趣在 Matlab 中创建这样的图.
(来源:3rs-reduction.co.uk)

I am interested in creating a plot like this in Matlab.
(source: 3rs-reduction.co.uk)

通过像这样"我的意思是我希望有两个组,分别称为 A 和 B,观察两次,预处理和后处理,其中该图由 A 和 B 在时间预处理时的箱线图的左组组成,右组包括治疗后时间 A 和 B 的箱线图,其中 A pre 的平均值通过一条线与 A post 的平均值相关联,B pre 的平均值通过一条线与 B post 的平均值相关联.我并不是说需要保持颜色形状或线条(而不是框)的特定外观.

By "like this" I mean that I wish to have a two groups, call them A and B, observed twice, pretreatment and post-treatment, where the plot consists of a left group of the box plots of A and B at time pretreatment and the right group consists of boxplots of A and B at time post-treatment, and where the mean of A pre is linked by a line to mean of A post and the mean of B pre is linked by a line to mean of B post. I don't mean that the specific appearance of colors shapes, or lines (rather than boxes) needs to be maintained.

我尝试使用 boxplot 命令并使用hold on"到达那里.但我无法弄清楚如何将它们组合在一起.为了具体起见,假设就像在 Matlab boxplot 命令中一样,其中观察值在行中,字段在列中,并且顺序是 ((A,pre),(A,post),(B,pre),(B,post)).

I tried to get there with a boxplot command and using "hold on" but I couldn't quite figure out how to make it all fit together. To get concrete, assume that like in the Matlab boxplot command, where the observations are in rows and the fields are columns, and that the order is ((A,pre),(A,post),(B,pre),(B,post)).

一些示例代码:

simlength = 100;
groupmeans = [.1, .2, .2, .4];
groupstddev = [.05, .05, .05, .05];
simholder = randn(simlength,4);
simholder = repmat(groupmeans ,simlength,1) + simholder     .* repmat(groupstddev ,simlength,1);
boxplot(simholder)

如果我可以将箱线图的结果 1 和结果 3 以及结果 2 和 4 叠加起来,并在组之间划出界线,那么我会很高兴,只是不知道如何将所有部分放在一起.

If I could stack the results 1 and 3 and results 2 and 4 of that boxplot and draw the lines between the group means I would be quite happy, just not sure how to put all the pieces together.

谢谢!

推荐答案

Dan 的回答很接近(谢谢!),但没有包含我模仿上述图表所需的格式细节.一旦我弄清楚如何做到这一点,我尝试编辑他的以添加所需的更改,但编辑器并不关心我的更改.所以这就是我想要的.

Dan's answer was close (thanks!) but didn't include the formatting details I needed to mimic the above chart. Once I figured out how to do that, I tried editing his to add the required changes but the editors didn't care for my changes. So here here is what I wanted.

y1 = rand(2, 1);           
e1 = rand(2, 1)*.2;       
errorbar(y1, e1, 'o-');  

hold all

%Now repeat for B
y2 = rand(2, 1);
e2 = rand(2, 1)*.2;
errorbar(y2, e2, '^-');
plotrange = [y1-e1;y2-e2;y1+e1;y2+e2];
yplotmin = min(plotrange)* .5;
yplotmax = max(plotrange) * 1.5;

legend({'Control', 'Treatment'})

set(gca,'YLim',[yplotmin yplotmax])
set(gca,'XLim',[.5 2.5])
set(gca,'XTick',1:2)
set(gca,'XTickLabel',{'Pre-treatment', 'Post-treatment'});

这篇关于Matlab 中的类似差值箱线图的图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆