
Creating grouped or stacked bar plot?
조회 수: 6 (최근 30일)
이전 댓글 표시
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?
댓글 수: 0
답변 (1개)
Scott MacKenzie
2021년 5월 12일
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'});

댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Bar Plots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!