How to plot multiple multcompare plots from anova

23 次查看(过去 30 天)
It doesn't work when I try to use tiledlayout to make a combined plot
% Loading data
y = [52.7 57.5 45.9 44.5 53.0 57.0 45.9 44.0]';
g1 = [1 2 1 2 1 2 1 2];
g2 = {'hi';'hi';'lo';'lo';'hi';'hi';'lo';'lo'};
g3 = {'may';'may';'may';'may';'june';'june';'june';'june'};
% For loop with subplot
for n = 1:4
subplot(2,2,n)
hold on
[~,~,stats] = anovan(y,{g1 g2 g3},'model','interaction','varnames',{'g1','g2','g3'});
results = multcompare(stats,'Dimension',[1 2]);
hold off
end
And tiledlayout also doesn't work
tiledlayout('flow')
nexttile
[~,~,stats] = anovan(y,{g1 g2 g3},'model','interaction','varnames',{'g1','g2','g3'});
results = multcompare(stats,'Dimension',[1 2]);
nexttile
[~,~,stats] = anovan(y,{g1 g2 g3},'model','interaction','varnames',{'g1','g2','g3'});
results = multcompare(stats,'Dimension',[1 2]);

采纳的回答

Walter Roberson
Walter Roberson 2020-1-27
multcompare() calls meansgraph(), which always unconditionally does a clf() which erases the entire current figure.
Therefore to plot multiple such graphs on the same figure, you are going to need to provide a figure for multcompare() to scribble into, and then you are going to have to extract the axes from the figure and move it to the desired target location.
However, there is the hidden difficulty that the graphs are interactive, each line having a buttondownfcn callback. To support that, the axes is given UserData and also the figure is given UserData as well. If you had more than one kind of multcompare, such as mixing anova1 with kruskalwallis then you would have a conflict when you merged the axes into one figure, but you should be okay as long as they are all for the same kind of graph.
  4 个评论
Barbab
Barbab 2023-10-3
Hello, I am trying to do the same, unfortunately the code you provided above for the multcompare plots is not working in my case. It says "Error using matlab.graphics.axis. Axes/set Invalid or deleted object." Could you suggest another solution?
Is there any easy way to get the data directly from multcompare and to plot it directly how I would like it to be?

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Analysis of Variance and Covariance 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by