Paneled Plots - RhoInc/sas-beeswarm GitHub Wiki
In this example, we produce a paneled beeswarm plot.
Prior to calling the macro, first determine the appropriate values for optional parameters rmarkers=
(i.e., how many markers will fit along the response axis?) and gmarkers=
(i.e., how many markers will fit along the grouping axis?). By default, the macro assumes the values of 60 and 80. These values work fine for default-sized SGPLOT output (640px by 480px). However, for SGPANEL, the appropriate values are quite different.
*------------------------------------------------------------;
*---------- determine best rmarkers= and gmarkers= ----------;
*------------------------------------------------------------;
data fillpanel;
do panel = 1 to 3;
do x = 0 to 75;
do y = 0 to 35;
output;
end;
end;
end;
run;
proc sgpanel data=fillpanel;
panelby panel / columns=3;
scatter x=x y=y;
colaxis thresholdmax=0;
rowaxis thresholdmax=0;
run;
The values 75 and 35 are arrived at through experimentation. Expect to have to test several values before getting a good fit.
With the values for rmarkers=
and gmarkers=
now in hand, producing a paneled beeswarm plot is essentially a 3-step process.
- Split the original dataset into smaller panel-specific datasets.
- Pass the panel-specific datasets to the macro one at a time.
- Stack the panel-specific output datasets back together again and send to SGPANEL.
*------------------------------------------------------------;
*---------- dummy data generation ----------;
*------------------------------------------------------------;
data dummy;
do panel = 1 to 3;
do trt = 1, 2, 3;
do subjects = 1 to 30 - 4*trt*floor(sqrt(panel)) by 1;
response = sqrt(trt)*sqrt(panel)*(rannor(1)+3);
output;
end;
end;
end;
run;
*------------------------------------------------------------;
*---------- beeswarm call ----------;
*------------------------------------------------------------;
%macro panel;
%do i = 1 %to 3;
*----- split the dataset -----;
data panel&i;
set dummy;
where panel eq &i;
run;
*----- call beeswarm once per dataset -----;
%beeswarm
(data=panel&i
,respvar=response
,grpvar=trt
,rmarkers=75
,gmarkers=35
,rmin=0
,rmax=20
,out=beeswarm&i
);
%end;
*----- stack back together -----;
data beeswarm;
set %do i = 1 %to 3; beeswarm&i %end; ;
run;
%mend panel;
%panel;
*------------------------------------------------------------;
*---------- plot it ----------;
*------------------------------------------------------------;
proc sgpanel data=beeswarm;
panelby panel / columns=3;
scatter x=trt_bee y=response / markerattrs=(symbol=circlefilled);
colaxis min=0.5 max=3.5 integer;
run;