How do I change individual bar colors on "grouped" bar graph?
Show older comments
Can anyone recommend how I can change the individual colors on my grouped bar graph? I have two groups 'Concrete' and 'Abstract' representing different order conditions from my experiment. I'm trying to create a bar graph to visualize differences between two different time durations within the same group. I'm having trouble changing the color on the bars to match with the rest of the color scheme I'm working with. I would like to have the first bar in the first group-opaque blue, second bar/first group-blue, first bar second group-opaque red, second bar second group-red. Below is the script I'm running. I was also having trouble with the legend.
%%%Experiment 2 Bar Graph%%%
%%%Produces visual comparison of alpha values from all participants averaged
%%%for each condition.
%Loads files needed for bar graph
load('Exp2_Allsubs_Ultra_Params.mat')
%Creates standard error for error bars
cond0time1_std_err = std(all_subj_alphas_cond0_time1)./sqrt(length(all_subj_alphas_cond0_time1));
cond0time2_std_err = std(all_subj_alphas_cond0_time2)./sqrt(length(all_subj_alphas_cond0_time2));
cond1time1_std_err = std(all_subj_alphas_cond1_time1)./sqrt(length(all_subj_alphas_cond1_time1));
cond1time2_std_err = std(all_subj_alphas_cond1_time2)./sqrt(length(all_subj_alphas_cond1_time2));
%Creates Bar Graph for Alphaa Parameter
mean_alpha_values = [allsubs_ultraalpha_cond0time1 allsubs_ultraalpha_cond0time2; allsubs_ultraalpha_cond1time1 allsubs_ultraalpha_cond1time2];
alpha_stderr =[cond0time1_std_err cond0time2_std_err; cond1time1_std_err cond1time2_std_err];
y = bar(mean_alpha_values,'grouped');
hold on
% Calculate the number of groups and number of bars in each group
[ngroups,nbars] = size(mean_alpha_values);
% Get the x coordinate of the bars
x = nan(nbars, ngroups);
for i = 1:nbars
x(i,:) = y(i).XEndPoints;
end
% Plot the errorbars
errorbar(x',mean_alpha_values, alpha_stderr,'k','linestyle','none', 'LineWidth', 2);
%Formats Title of Chart
title('Alpha Parameter','FontSize',24,...
'FontName','Times New Roman');
% Create Y-Axis Label
ylabel({'Parameter Value'},'FontSize',18,...
'FontName','Times New Roman');
% %Creates Legend
% legend(bar(y),{'Short','Long'},'Location','northeastoutside')
% xlabel({'Condition Type'},'FontSize',18,'FontName','Times New Roman');
name={'Concrete First';'Abstract First'};
set(gca,'xticklabel',name);
%Formats gcf position
x0=10;
y0=10;
width=500;
height=700;
%Formats Current Axis and Current Figure
set(gca, 'FontSize', 18, 'FontWeight', 'bold')
set(gcf, 'Color', 'w', 'position',[x0,y0,width,height])
Accepted Answer
More Answers (0)
Categories
Find more on Data Distribution Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!