FOCUS AREAS

Graphics

Adoption Rate over Time
Base SAS: ODS Graphics Procedures

/*** To generate this graph, you must be running SAS 9.4 (TS1M2) or later ***/

%let graphs='.';

%let dpi=100;
%let w=8in;
%let h=4.5in;

title;
footnote;
ods html close;

/*--Generate simulated data--*/
data spaghetti;
  pi=constant("PI");
  length Location $ 8 case $4;
  label y='Adoption Rate' x='Days';

  a1=10; a2=5; d1=0.2; v=0.6;
  Location='USA'; Year=2013; 
  do id=1 to 10;
    if mod(id, 2)=0 then case='Even'; else case='Odd';
    do x=1 to 500 by 5;
      y=a1*sin(x*pi/180)+a2*sin(2*x*pi/180+d1)-v*id +30;
      output;
    end;
  end;

  Location='USA'; Year=2014; 
  do id=11 to 20;
    if mod(id, 2)=0 then case='Even'; else case='Odd';
    do x=1 to 500 by 5;
      y=a1*sin(x*pi/180)+a2*sin(2*x*pi/180+d1)-v*id +30 -2;
      output;
    end;
  end;

  a1=10; a2=3; d1=0.4; v=0.4; 
  Location='Europe'; Year=2013; 
  do id=21 to 30;
    if mod(id, 2)=0 then case='Even'; else case='Odd';
    do x=1 to 500 by 5;
      y=a1*cos(x*pi/180)+a2*cos(2*x*pi/180+d1)-v*id +30;
      output;
    end;
  end;

  Location='Europe'; Year=2014; 
  do id=31 to 40;
    if mod(id, 2)=0 then case='Even'; else case='Odd';
    do x=1 to 500 by 5;
      y=a1*cos(x*pi/180)+a2*cos(2*x*pi/180+d1)-v*id +30 -2;
      output;
    end;
  end;
run;

/*--Render the graph--*/
title 'Adoption Rate over Time';
ods listing style=htmlblue gpath=&graphs image_dpi=&dpi;
ods graphics / reset antialiasmax=10000 width=&w height=&h imagename='Spaghetti';
proc sgplot data=spaghetti nowall noborder;
  series x=x y=y / group=id lineattrs=(thickness=2 pattern=solid) smoothconnect
         /*--GROUPLC= and GROUPLP require SAS 9.4 (TS1M2) or later--*/
         grouplc=Location grouplp=year
  ;
  xaxis display=(noline);
  yaxis display=(noticks noline) grid;
  keylegend / title='Location: ' location=inside position=bottomright
              autoitemsize valueattrs=(size=10)
              /*--TYPE= requires SAS 9.4 (TS1M2) or later--*/
              type=linecolor
  ;
  keylegend / title='Year: ' location=inside position=bottomleft
              autoitemsize valueattrs=(size=10)
              /*--LINELENGTH= and TYPE= require SAS 9.4 (TS1M2) or later--*/
              linelength=32 type=linepattern
  ;
  run;