FOCUS AREAS

Graphics

bean plot
Base SAS: Graph Template Language

%let gpath='.';
%let dpi=100;

/* Generate some random data */
data k1;
  seed = 1283470;
  do i = 1 to 1000;
    z1 = rannor(seed);
    z2 = rannor(seed);
    z3 = rannor(seed);
    x1 = 3*z1 + z2;
    y1 = 3*z1 + z3;
    x2 = 1.5*z1*z1 - 2.5*z2*z2;
    y2 = 5.5*z1 + z3*z3*2.5;
    x3 = 3*z1*z1 + z2;
    y3 = 4.5*z1 + 1.5*z3;
    output;
  end;
  drop seed i z1 z2 z3;
run;

/* Compute densities */
proc kde data=k1;
  univar x1 / out=o_x1 (rename=(value=x1 density=density_x1)) 
              noprint plots=none ;
  univar y1 / out=o_y1 (rename=(value=y1 density=density_y1))
              noprint plots=none;

  univar x2 / out=o_x2 (rename=(value=x2 density=density_x2))
              noprint plots=none;
  univar y2 / out=o_y2 (rename=(value=y2 density=density_y2))
              noprint plots=none;

  univar x3 / out=o_x3(rename=(value=x3 density=density_x3))
              noprint plots=none;
  univar y3 / out=o_y3(rename=(value=y3 density=density_y3))
              noprint plots=none;
run;

ods _all_ close;

proc means data=o_x1;
 var x1;
 output out=x1quart mean=mean_x1;
run;

proc means data=o_y1;
 var y1;
 output out=y1quart mean=mean_y1;
run;

proc means data=o_x2;
  var x2;
  output out=x2quart mean=mean_x2;
run;

proc means data=o_y2;
 var y2;
 output out=y2quart mean=mean_y2;
run;

proc means data=o_x3;
 var x3;
 output out=x3quart mean=mean_x3;
run;

proc means data=o_y3;
 var y3;
 output out=y3quart mean=mean_y3;
run;

data quarts;
 merge x1quart y1quart x2quart y2quart x3quart y3quart;
 low_x1=0;      high_x1=0.05;
 low_y1=-0.05;  high2=0;
 low_x2=0;      high_x2=0.05;
 low_y2=-0.05;  high_y2=0;
 low_x3=0;      high_x3=0.05;
 low_y3=-0.05;  high_y3=0;
run;

data dens;
  merge 
    o_x1 o_y1 
    o_x2 o_y2
    o_x3 o_y3
    quarts;
run;

proc template;
  define statgraph test;
    begingraph / datacolors=(lightSeaGreen orange)
                 datacontrastcolors=(lightSeaGreen orange);
    entrytitle  "Probability Distribution Functions with Placebo and MDA";
    entryfootnote halign=left "This graph uses the new DATACOLORS option on "
                              "BEGINGRAPH statement to set group colors.";

    layout lattice / columns=3 rowdatarange=unionall border=false;

      rowaxes;
        rowaxis/ display=(ticks tickvalues line) griddisplay=on offsetmin=0.1 
                 linearopts=(tickvaluelist=(-20 -10 0 10 20));
      endrowaxes;

      sidebar / align=bottom;
        layout gridded;
          entry " ";
          discretelegend "band1" "band2" / across=2;
        endlayout;
      endsidebar;

      layout overlay / xaxisopts=(display=none) walldisplay=none border=false;
        bandplot y=x1 limitlower=0 limitupper=density_x1 /fillattrs=graphdata1 
          datatransparency=0.4 name="band1" legendlabel="Placebo";
        seriesplot y=x1 x=density_x1 /lineattrs=graphdata1;
        highlowplot y=mean_x1 high=high_x1 low=low_x1 /
          lineattrs=graphdata1(pattern=dash thickness=3) ;
        bandplot y=x1 limitlower=0 limitupper=eval(-1*density_y1) / name="band2"  
          fillattrs=graphdata2 datatransparency=0.4
          legendlabel="MDA (Treatment)";
        seriesplot y=x1 x=eval(-1*density_y1)/
          lineattrs=graphdata2(pattern=solid);
        highlowplot y=mean_y1 high=high2 low=low_y1 /
          lineattrs=graphdata2(pattern=dash thickness=3);
        referenceline x=0 / curvelabel="No Cue" curvelabelposition=min
          datatransparency=1;
      endlayout;

      layout overlay / xaxisopts=(display=none) walldisplay=none border=false;
        bandplot y=x2 limitlower=0 limitupper=density_x2 /fillattrs=graphdata1 
          datatransparency=0.4;
        seriesplot y=x2 x=density_x2 / lineattrs=(color=lightseagreen);
        highlowplot y=mean_x2 high=high_x2 low=low_x2 / 
          lineattrs=graphdata1(pattern=dash thickness=3);
        bandplot y=x2 limitlower=0 limitupper=eval(-1*density_y2) /
          fillattrs=(color=orange) datatransparency=0.4;
        seriesplot y=x2 x=eval(-1*density_y2) /lineattrs=(color=orange);
        highlowplot y=mean_y2 high=high_y2 low=low_y2 / 
          lineattrs=(color=orange pattern=dash thickness=3);
        referenceline x=0 / curvelabel="False Cue" curvelabelposition=min
          datatransparency=1;
      endlayout;

      layout overlay / xaxisopts=(display=none) walldisplay=none border=false ;
        bandplot y=x3 limitlower=0 limitupper=density_x3 /fillattrs=graphdata1
          datatransparency=0.4;
        seriesplot y=x3 x=density_x3 / lineattrs=(color=lightseagreen);
        highlowplot y=mean_x3 high=high_x3 low=low_x3 / 
          lineattrs=graphdata1(pattern=dash thickness=3);
        bandplot y=x3 limitlower=0 limitupper=eval(-1*density_y3) /
          fillattrs=(color=orange) datatransparency=0.4;
        seriesplot y=x3 x=eval(-1*density_y3) /lineattrs=(color=orange);
        highlowplot y=mean_y3 high=high_y3 low=low_y3 / 
          lineattrs=(color=orange pattern=dash thickness=3);
        referenceline x=0 / curvelabel="True Cue" curvelabelposition=min
          datatransparency=1;
      endlayout;
    endlayout;
  endgraph;
 end;
run;

ods _all_ close;
ods listing image_dpi=&dpi gpath=&gpath;
ods graphics / reset imagename='V94_BeanPlot' width=6.93in height=3.15in;
proc sgrender data=dens template=test;
run;
ods _all_ close;