Plotting data with 5 dimensions

10 ビュー (過去 30 日間)
Teshan Rezel
Teshan Rezel 2021 年 7 月 7 日
コメント済み: Mohammad Sami 2021 年 7 月 10 日
Hi folks,
I have a dataset that has data points each with a name and 4 elements. However, of these elements are percentages that add up to a hundred, so a stacked graph will do the trick. The problem is that I need to include the 4th element, which is a number, as well as the names of the points.
For example, I could have:
A B C D
point1 = 64% 26% 10% 23
point2 = 83% 10% 7% 18
Is there a way to adequately display all this information in a single plot without clutter? I was thinking of representing each data point as a mini pie chart, with the diameter of the circle highlighting column D, and columns A, B and C in the graph as normal, but I'm unsure how to go about this!
  6 件のコメント
Steven Lord
Steven Lord 2021 年 7 月 8 日
Since these seem to have different units (one percentages, one a number of items?) does it make sense to have them on the same plot? Or would a pair of plots, one a stacked plot and one a line plot, with the plots themselves on axes stacked vertically make more sense?
Teshan Rezel
Teshan Rezel 2021 年 7 月 9 日
hi @Steven Lord, yes it makes sense because the column D contains properties of the sample that are intrinsically related to the configuration of the 3 other columns

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

採用された回答

Mohammad Sami
Mohammad Sami 2021 年 7 月 8 日
How about you use the stacked chart as you intended and then just change the x axis to display the value of column D.
data = [64 26 10 23; 83 10 7 18];
datasub = data(:,1:3);
cats = categorical(compose('D = %i',data(:,4)));
b = bar(cats,datasub,'stacked');
set(b,{'DisplayName'},{'A';'B';'C'});
legend
  7 件のコメント
Teshan Rezel
Teshan Rezel 2021 年 7 月 9 日
hi @Mohammad Sami, thanks for this! This gets around the horzcat issue. The problem now is that the labels for the percentages seem to be incorrect. I'm not sure what's causing this so not sure how to correct it!
Mohammad Sami
Mohammad Sami 2021 年 7 月 10 日
The values are incorrect or just you are getting more decimal points then what you need ? If the later you can change the format spec inside the compose function to your desired formatting. Example %f or %0.2f You can see documentation for format spec under sprintf if you need more details. https://www.mathworks.com/help/matlab/ref/sprintf.html

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

その他の回答 (0 件)

カテゴリ

Help Center および File Exchange2-D and 3-D Plots についてさらに検索

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by