Clear Filters
Clear Filters

Change x- and y-axis description in multcompare()

4 views (last 30 days)
Hi!
I am using multcompare() to plot the Tukey HSD Plot. Is it possible to change the description of the x- and y-axis and also change the title?

Accepted Answer

Pratik
Pratik on 3 Sep 2024
Hi Annika,
I understand that the title, and the description of the of the plot need to be changed.
Following code snippet can be added after "multcompare" function to achieve the same.
% Customize the plot
xlabel('Group Comparison');
ylabel('Mean Difference');
title('Tukey HSD Test Results');
Please refer to the documentation of "xlabel", "ylabel" and "title" for more information:
I hope this helps!

More Answers (2)

Zinea
Zinea on 3 Sep 2024
Hi Annika,
Yes, you can customize the axis labels and the title of a plot generated by the ‘multcompare’ function in MATLAB. Although this function itself does not directly provide options to change the axis labels or title, you can modify these properties after the plot is created using MATLAB's plotting functions.
Here is a complete MATLAB code which generates a dummy dataset, performs 'anova', followed by 'multcompare' and then changes the axis descriptions and the title:
% Generate a dummy dataset
% Assume we have three groups with different sample sizes
group1 = normrnd(5, 1, 10, 1); % Group 1 data: mean = 5, std = 1, n = 10
group2 = normrnd(6, 1, 15, 1); % Group 2 data: mean = 6, std = 1, n = 15
group3 = normrnd(7, 1, 12, 1); % Group 3 data: mean = 7, std = 1, n = 12
% Combine the data into a single vector
data = [group1; group2; group3];
% Create a grouping variable
group = [repmat({'Group 1'}, length(group1), 1);
repmat({'Group 2'}, length(group2), 1);
repmat({'Group 3'}, length(group3), 1)];
% Perform one-way ANOVA
[p, tbl, stats] = anova1(data, group);
% Perform Tukey's HSD test using multcompare
[c, m, h, gnames] = multcompare(stats);
% Customize the plot
xlabel('Mean Difference'); % X-axis label
ylabel('Group Comparisons'); % Y-axis label
title('Tukey HSD Test Results'); % Title
Output of above code:
Hope this helps you move forward!

Annika
Annika on 3 Sep 2024
Edited: Annika on 3 Sep 2024
Thanks a lot, it worked! My question now is whether it is possible to change the colour and thickness of the graphs in the plot?

Community Treasure Hunt

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

Start Hunting!