I am trying to create a boxplot, using boxplot(data)
for this sample data
1,0.3074855004
1,0.5342907151
1,0.1243014226
1,0.8373050862
1,0.2964970712
2,0.2753391378
2,0.0662903741
2,0.7435585174
2,0.141665858
2,0.8710871406
3,0.683215396
3,0.9968826184
3,0.8009274979
3,0.6164554236
3,0.9880523647
4,0.6854059871
4,0.4828904583
4,0.6001796951
4,0.3790802876
4,0.5728325425
I expect to get a graph with four columns but the output currently only shows two columns. Here is the output
I have tried following the documentation here
http://octave.sourceforge.net/statistics/function/boxplot.html
but I'm still having trouble getting desired results.
Please help me with the correct syntax for getting a proper boxplot in octave.
Thanks,
Your expectations are wrong. Why would boxplot()
assume that the first column is the group number. The documentation for boxplot()
says:
DATA is a matrix with one column for each data set, or data is a cell vector with one cell for each data set.
Your data is not any of the above.
Also, why are you even wasting memory by setting it up like that? Why do you have a column just to store the group number? Since each group seems to have the same number of values, you can reshape your second column into a matrix with one column per group:
octave> reshape (data(:,2), 5, 4)
ans =
0.307486 0.275339 0.683215 0.685406
0.534291 0.066290 0.996883 0.482890
0.124301 0.743559 0.800927 0.600180
0.837305 0.141666 0.616455 0.379080
0.296497 0.871087 0.988052 0.572833
or if each group has different number of values, use a cell array:
octave> accumarray (data(:,1), data(:,2), [], @(x) {x})
ans =
{
[1,1] =
0.30749
0.53429
0.12430
0.83731
0.29650
[2,1] =
0.275339
0.066290
0.743559
0.141666
0.871087
[3,1] =
0.68322
0.99688
0.80093
0.61646
0.98805
[4,1] =
0.68541
0.48289
0.60018
0.37908
0.57283
}
Once your data is a sensible format, boxplot()
will work as you expected.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.