Plotting data with 5 dimensions

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 个评论

Something like this might be helpful.
@Rik thanks, but I'm afraid this doesn't help with 4D data, just 3D! I can either choose to name my samples, or implement a 4th column but not both!
You suggested something similar yourself: use differently sized circles as markers to show the D value.
Alternatively, you can set the Z-value of each marker to the value of D. I don't know how readable the plot will be.
@Rik yes, this is the issue as well, the readability of the plot. I did suggest the marker size be equal to D but I'm not sure how to implement that, hence the question! I'm not very versed in Matlab so apologies.
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?
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

请先登录,再进行评论。

 采纳的回答

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 个评论

hi @Mohammad Sami, thanks for this. The only issue I have is that while this works to represent all the data, I would struggle to assign a sample name to this plot which is very important. So where the D=18 goes, I would normally have an identifier there.
Ok not sure how many samples are you plotting in one graph. You can simply alter the line creating the labels using the compose function to include the sample names in addition to the value. Example Name, D = 18.
d = [23; 18];
n = ["Sample1"; "Sample2"];
cats = categorical(compose('%s , D = %i',n,d))
cats = 2×1 categorical array
Sample1 , D = 23 Sample2 , D = 18
Another way is to scale the data to the value of D and then plot the bar chart. Then we add in the percentage in each bar.
data = [64 26 10 23; 83 10 7 18];
datasub = data(:,1:3);
scaled_data = datasub .* data(:,4) / 100;
label = categorical(["Sample1"; "Sample2"]);
b = bar(label,scaled_data,'stacked');
y = movmean(horzcat([0;0],cumsum(scaled_data,2)),2,2,'Endpoints','discard');
x = repelem(label,1,size(scaled_data,2));
t = compose('%i%%',datasub);
text(x(:),y(:),t(:));
ylabel('D')
@Mohammad Sami thank you, this is brilliant! I just have a small issue with using horzcat which I'm not sure how to fix. I get the following error at the "y = movmean(horzcat...)" line. scaled_data is a 44x3 double so I'm unsure how to proceed. But besides this, thank you! this idea of yours is genius!
Error using horzcat
Dimensions of arrays being concatenated are not consistent.
Since you have 44 points you need to generate a zero column vector of size 44.
if true
movmean(horzcat(zeros(44,1),cumsum(scaled_data,2)),2,2,'Endpoints','discard');
end
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!
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 个)

类别

帮助中心File Exchange 中查找有关 Annotations 的更多信息

产品

版本

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by