Creating grouped or stacked bar plot?

I have a big dataset with 2 variables - 'gender' and 'country' (both categorical variables). Gender has 2 unique variables, while Country has 10. I need to create a grouped or stacked bar plot such that the x axis would be the values in gender grouped together and the y axis would be the count of the occurences of the different values in 'country'. How would I go about doing it?

Antworten (1)

Scott MacKenzie
Scott MacKenzie am 12 Mai 2021

0 Stimmen

data = rand(2,10)*100;
b = bar(data, 'stacked', 'edgecolor', 'flat');
labels = { 'Canada', 'USA', 'etc', 'etc', 'etc', 'etc', 'etc', 'etc', 'etc', 'etc' };
h = legend(labels);
title(h, 'Country');
ylabel('Occurences of Something');
xlabel('Gender');
xticklabels({'Female' 'Male'});

Produkte

Version

R2019b

Gefragt:

pp
am 27 Aug. 2020

Beantwortet:

am 12 Mai 2021

Community Treasure Hunt

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

Start Hunting!

Translated by