Box plot for column of a table with categorical variables
Mostra commenti meno recenti
I have a table of different varieties of apples and their prices.
I'm trying to create a box plot for each variety, with the variety names as the categorical variables and show them on the same chart.
Here's my attempt:
T=readtable('fruitvegprices2.csv');
items={'apples','pears','carrots','cabbage'};
%apples
[idx,ia] = ismember(T.(2),items{1});
T_apples = T(idx,{'item','variety'});% this gives table of apples alone
S_apples=unique(T_apples,'stable') %distinct varieties of apples
A=sortrows(T(idx,{'item','variety','price'})) %grouping the varieties together
var_order=S_apples.variety;
namedvar=categorical(A.price,1:8,var_order);
plot=boxchart(namedvar,A.price)
xlabel('Variety')
ylabel('Price')
The output I get is:

I don't know how to fix this, also I can't seem to turn off the Latex interpreter for the x-axis labels.
Could I get some help please?
Thank you!
6 Commenti
Walter Roberson
il 13 Dic 2021
A=sortrows(T(idx,{'item','variety','price'})) %grouping the varieties together
sortrows() sorts first by the first column, which in this case would be 'item', not 'variety' ?
But you already know that T(idx,:) is only for apples, so it is not clear why you bother extracting and sorting on the item field, since the field should be the same for everything in the subset ?
Cris LaPierre
il 13 Dic 2021
Share your data file. You can attach it using the paperclip icon.
Achuan Chen
il 13 Dic 2021
Achuan Chen
il 13 Dic 2021
Walter Roberson
il 14 Dic 2021
Are you sure you want your posts to be considered Spam ? That could result in Mathworks closing your account.
Risposta accettata
Più risposte (1)
Achuan Chen
il 13 Dic 2021
0 voti
Categorie
Scopri di più su Bar Plots in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

