Getting Started - RhoInc/sas-beeswarm GitHub Wiki
This page illustrates a basic application of the %beeswarm macro.
We begin with some dummy data generation. The resulting dataset will have 4 different TRT groups each containing a RESPONSE value for 50 different SUBJECTS.
*-------------------------------------------;
*---------- dummy data generation ----------;
*-------------------------------------------;
data dummy;
do trt = 1, 2;
do subjects = 1 to 100;
if trt = 1 then response = -3 + 6*ranuni(17);
if trt = 2 then response = rannor(17);
output;
end;
end;
run;
Producing a beeswarm plot in SAS is a two-step process.
- Use the %beeswarm macro to add a new variable to your dataset.
- Use this new variable as the X= option in a SCATTER statement.
*----------------------------------------------------------------------;
*---------- 1. macro %beeswarm uses dataset DUMMY and variable TRT ----;
*---------- to create dataset BEESWARM and variable TRT_BEE -----------;
*----------------------------------------------------------------------;
%beeswarm
(data=dummy
,grpvar=trt
,respvar=response
);
*-----------------------------------------------------------------;
*---------- 2. use dataset BEESWARM and variable TRT_BEE in a ----;
*---------- SCATTER plot -----------------------------------------;
*-----------------------------------------------------------------;
proc sgplot data=beeswarm;
scatter x=trt_bee y=response / markerattrs=(symbol=circlefilled);
xaxis min=0.5 max=2.5 integer;3
run;
The resulting plot will look like this!