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

查看:384
本文介绍了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)).

要构建的一些示例代码:

Some example code to build upon:

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天全站免登陆