Creating a stacked bar plot

418 ビュー (過去 30 日間)
Sophie Stringer
Sophie Stringer 2019 年 9 月 7 日
コメント済み: Stephen23 2019 年 9 月 8 日
Hi there,
I have a a matrix of percentages (P):
11.8227 13.4058 11.8959 13.2316 15.0877 7.6389 17.0667 17.8899 14.1361
12.0690 11.5942 14.1264 14.7583 12.9825 17.3611 14.6667 11.9266 15.1832
8.3744 9.7826 12.6394 7.3791 9.8246 19.4444 10.4000 11.4679 7.8534
9.8522 10.5072 13.7546 12.9771 10.8772 17.3611 12.0000 14.2202 16.7539
14.7783 15.5797 14.4981 13.9949 12.2807 11.1111 14.1333 13.3028 12.5654
14.7783 14.4928 14.1264 12.4682 14.0351 12.5000 11.4667 10.0917 12.0419
13.5468 9.7826 12.2677 12.4682 9.8246 5.5556 9.6000 9.6330 12.5654
14.7783 14.8551 6.6914 12.7226 15.0877 9.0278 10.6667 11.4679 8.9005
Where each column (vertically) above adds to 100 and each column is a particular node ranging from 1-9. Each row represents phases 1-8 (horizontally).
I would like to make a stacked bar chart for this data. I've done the basic code for a stacked bar plot. And have gotten the graph below. But the axis are the wrong way around. I need the x axis to be columns 1 to 9. And the stacked variables to be the vertical columns (adding to 100). Is there an easy way of doing this?
I have attached the percentage file.
Thank you in advance. :D
figure(15)
bar(P, 'stacked')
Screen Shot 2019-09-07 at 5.12.37 pm.png

採用された回答

Stephen23
Stephen23 2019 年 9 月 7 日
編集済み: Stephen23 2019 年 9 月 7 日
The bar documentation states "If y is a matrix, then bar groups the bars according to the rows in y", so you need to translate your matrix:
bar(P.','stacked')
% ^^ translate
untitled.png
  2 件のコメント
Stephen23
Stephen23 2019 年 9 月 8 日
@Sophie Stringer: glad it helped. Please don't forget to accept my answer!

サインインしてコメントする。

その他の回答 (0 件)

Community Treasure Hunt

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

Start Hunting!

Translated by