% Assuming data is a matrix where each row is an observation
data=[28 117 14 40 1 1 1 70; 19 121 9 24 6 8 2 69; 15 122 15 43 2 3 4 78];
labels={'Green', 'Deep Black', 'Light White', 'Deep White', 'Brown', 'Yellow', 'Blue', 'Grey'};

iOrder=[7 5 2 4 1 8 3 6];
% Calculate means and standard deviations
means = mean(data);
std_devs = std(data);

% Define colors for bars
fColor = [0.1 0.1 1; % Blue
          0.7 0.3 0; % Brown
          0.1 0.1 0.1; % Deep black
          0.9 0.9 0.9; % Deep white
          0.2 0.7 0.2; % Green
          0.4 0.4 0.4; % Grey
          0.6 0.6 0.6; % Light white
          0.9 0.9 0.1]; % Yellow

figure(1);clf;hold on;
for k = 1:length(data)
    bar(k, means(iOrder(k)), 'FaceColor', fColor(k, :));
    SortedLabels{k}=labels{iOrder(k)};
    er = errorbar(k,means(iOrder(k)),std_devs(iOrder(k)));
    er.Color = [0 0 0];
    er.LineStyle = 'none';
end
%xlim([1 8])
set(gca,'XTickLabel',SortedLabels);
set(gca, 'XTick', 1:length(means),'XTickLabel',SortedLabels,'XTickLabelRotation',45);

% Set title and labels
xlabel('Pellet category');
ylabel('Pellet count');
