FOCUS AREAS

Graphics

Rate by Region and Year
Base SAS: ODS Graphics Procedure: SGPLOT

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

ods html close;
ods listing gpath=&gpath image_dpi=&dpi;

/*--Generate 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=1;
  Location='USA'; Year=2013; 
  do id=1 to 6;
    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=7 to 12;
    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.8; 
  Location='Europe'; Year=2013; 
  do id=13 to 18;
    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=19 to 24;
    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;

/*--SG Series with multiple classifications--*/
ods listing style=htmlblue;
ods graphics / reset width=5in height=3.75in imagename='Spaghetti_SG';
title 'Rate by Region and Year';
footnote j=l 'Line color is by Region and Pattern is by Year';
proc sgplot data=spaghetti;
  series x=x y=y / group=id grouplc=location grouplp=year name='a' lineattrs=(thickness=2);
  yaxis offsetmin=0.1;
  keylegend 'a' / type=linecolor location=inside position=bottomleft;
  keylegend 'a' / type=linepattern location=inside position=bottomright linelength=32;
  run;

title;
footnote;