How do you group categorical variables in order to create a boxplot?
4 次查看(过去 30 天)
显示 更早的评论
I have a set of data which has multiple categorical variables which need to be grouped together for analysis.
For example, I have a set of data where there four categorical variables: Microtopography, Structure, Burn Severity, and Canopy.
I want to group each combination of these four variables into one "group": Example - A = MicrotA, StructA, BurnA & CanoA as one group against B = MicrotB, StructureB, BurnB, CanoB. I would then like to plot these newly created groups (A & B) on the x-axis of a boxplot. Each combination of my original categorical variables is a unique, non-numerical variable. The y-axis will be a numerical variable.
I've looked into creating an index using string comparison, but for some reason cannot get it to work. I'm using data from a Table which I have imported form a Microsoft Access Database.
0 个评论
采纳的回答
dbmn
2017-3-17
I'm not entirely sure what you want to do, but this little example, that I created might help you to get started
% create some x data to experiment (you already have these)
x_data = categorical({'a', 'b', 'c', 'a', 'd', 'f', 'b', 'a', 'c', 'f', 'd'})
% create some y data to experiment (you already have these)
y_data = rand(size(x_data));
% Get Indices of your new master category that contains all elements a, b, c
group_index = [x_data == 'a' | x_data == 'b' | x_data == 'c'];
Now the question is what you want to do with that info. One possibility is to create a new vector (that can be added to the data vectors that you already have).
% Get all the y data
y_data_new = y_data(group_index);
% And then create some dummy x data
x_data_new = categorical(repmat({'your group name'}, size(y_data_new)));
% Add those things to an existing vector, or do whatever you need
x_data = [x_data, x_data_new];
y_data = [y_data, y_data_new];
2 个评论
Peter Perkins
2017-4-26
If PRS_t.CANOPY is a categorical, you do not need strcmp. Just use ==, as in dbmn's suggestion.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Data Distribution Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!