【问题标题】:A difference-in-difference boxplot-like plot in MatlabMatlab中的差分箱线图
【发布时间】:2019-09-05 19:17:25
【问题描述】:

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

“像这样”是指我希望有两组,分别称为 A 和 B,观察两次,预处理和后处理,其中图由 A 和 B 的箱形图的左组组成在预处理时间,右侧组由处理后时间的 A 和 B 的箱线图组成,其中 A pre 的平均值通过一条线连接到 A post 的平均值,B pre 的平均值通过一条线连接到平均值B 职位。我并不是说需要维护颜色形状或线条(而不是框)的特定外观。

我尝试使用 boxplot 命令并使用“hold on”来到达那里,但我无法完全弄清楚如何将它们组合在一起。具体来说,假设就像在 Matlab 箱线图命令中一样,观察是在行中,字段是列,并且顺序是 ((A,pre),(A,post),(B,pre),( B,发布))。

一些示例代码:

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 并在组之间画线,这意味着我会很高兴,只是不知道如何将所有部分放在一起。

谢谢!

【问题讨论】:

    标签: matlab plot boxplot anova


    【解决方案1】:

    这样的事情怎么样:

    x = rand(2, 1);           % ? maybe just leave out?
    y = rand(2, 1);           % [mean(Apre), mean(Apost)]
    e = rand(2, 1)*.2;        % ? is this maybe [std(Apre), std(Apost)]
    errorbar(x, y, e, 'o-');  % You can leave off the x here if you don't need it
    
    hold all
    
    %Now repeat for B
    x = rand(2, 1);
    y = rand(2, 1);
    e = rand(2, 1)*.2;
    errorbar(x, y, e, '^-');
    
    legend({'First series', 'Second Series'})
    

    【讨论】:

      【解决方案2】:

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

      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'});
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2010-09-29
        • 2018-04-15
        • 1970-01-01
        相关资源
        最近更新 更多