Reputation: 704
I have the following sample of data
Y X1 X2 X3 X4 ...
123 121 214 241 241
431 143 141 241 124
214 124 214 142 241
531 432 134 412 124
243 124 134 134 123
I would be interested in plotting using box plots the data above. Specifically, I would like to have on the x-axis X1, X2, ... and on the y-axis the information of values within each column as a box plot. However, since I would like to identify visually, the corresponding Y'value (e.g., for max X1 would be 531), I thought about using some labels. For creating the box plot, I am using
ods graphics off;
proc boxplot data=test;
plot Y*X;
run;
where X is
X Y
X1 121
X1 143
X1 124
X1 432
... ...
X2 214
X2 141
X2 214
...
As shown above, however, I am loosing the values of Y (i.e. 123, 431, ...). Is there any way to keep also this information in a (box) plot? Any other ideas would be also kept into consideration and appreciated.
Upvotes: 0
Views: 406
Reputation: 27508
Transpose your data and you will be able to use Proc SGPLOT
statement HBOX
.
Example:
data have;
input
Y X1 X2 X3 X4 ;
datalines;
123 121 214 241 241
431 143 141 241 124
214 124 214 142 241
531 432 134 412 124
243 124 134 134 123
;
proc transpose data=have out=tall (rename=col1=x);
by y notsorted;
var x1-x4;
run;
ods html file='hbox-plot.html';
proc sgplot data=tall;
hbox x / category=y;
yaxis type=linear;
run;
ods html close;
will produce
Upvotes: 1