Bar chart legend and colour
Show older comments
I have created a bar chart and I want to add the names of the variants on the legend and they shoud have different colours.
How can I realize that?
ds = dataset("xlsfile", "dsCompact");
clean_ds = rmmissing(ds);
%% Mean of Mean of parameter variants for each velocity
[groupVariantsVelocity, variants, velocity, scale] = findgroups(clean_ds.parameter_variants, clean_ds.velocity, clean_ds.scale);
meanVariantsVelocity = splitapply(@mean, clean_ds.score, groupVariantsVelocity);
tVariantsVelocity = table (variants, velocity, scale, meanVariantsVelocity);
figure;
bar(meanVariantsVelocity(scale == "like"));
6 Comments
Adam Danz
on 19 Feb 2020
" I want to add the names of the variants on the legend and they shoud have different colours"
In your current code, each bar is a unique variant. So each bar would have its own color and each bar would pre represented in the legend. There's 40 bars so that would be a lot of colors and a lot of rows in the legend. It wouldn't be useful.
Maybe the idea hasn't been expressed well. Do you want to create a grouped bar chart instead where the scale groups (4) have different colors?
Megan
on 19 Feb 2020
Megan
on 19 Feb 2020
The code you shared produces this figure. Each bar is the mean of a varient group just for scale = likeability.

"I want to add the names of the variants on the legend and they shoud have different colours"
I suggest adding the names of the variants to the x axis ticks rather than having a legend with 10 rows of labels and 10 different bar colors.
If you're trying to do something different, please explain in detail.

Megan
on 19 Feb 2020
Megan
on 19 Feb 2020
Accepted Answer
More Answers (0)
Categories
Find more on Title 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!


