Data visualization with SAS programming

Fun w/ODS Graphics: Gantt chart-like take on Presidents' ages

Reply
Contributor tc
Contributor
Posts: 68

Fun w/ODS Graphics: Gantt chart-like take on Presidents' ages

PresidentAges.png

 

At home waiting for the Comcast installer today (75Mbps, Internet here I come!), so thought I'd take a crack at Rick Wicklin's visualize-the-ages-of-US-presidents challenge. Try as I might, I'm afraid Rick wins this ODS Graphics throwdown with his elegant viz, but thought I'd post my stab at a Gantt chart-like solution anyway (which I "adapted" from Sanjay Matange's The HIGHLOW Plot). Wait'll next year, as we Cubs fans (used to!) say. Smiley Happy

 

CODE (uses RW's Presidents SAS dataset)

* Gantt-chart like take on Rick Wicklin's Presidential ages vector chart;

title;
proc format;                             * Kludge since Trump's term TBD;
picture trump 74.1-74.9="?" other='99.9';

data presidents2;
set presidents;
if AgeAtEndDate=. then AgeAtEndDate=AgeAtInauguration+4; * Default to 4-year term;
format AgeAtInauguration AgeAtEndDate trump.;
label InaugurationDate="Inaugurated" PresidencyEndDate="End Date";

ods graphics on / imagemap height=11.25in width=11.25in;
proc sgplot data=presidents2 noautolegend;
highlow y=President low=AgeAtInauguration high=AgeAtEndDate /
         lowlabel=AgeAtInauguration highlabel=AgeAtEndDate lineattrs=(thickness=4pt);
yaxis grid reverse display=(nolabel noticks); 
yaxistable InaugurationDate PresidencyEndDate;
xaxis grid values=(40 to 80 by 5) valuesformat=z2. 
      label="Age of US Presidents at Beginning and End of Term";
run;
Super User
Posts: 1,209

Re: Fun w/ODS Graphics: Gantt chart-like take on Presidents' ages

Nice work @tc! Pleased to see you took up the challenge Smiley Wink

Contributor tc
Contributor
Posts: 68

Re: Fun w/ODS Graphics: Gantt chart-like take on Presidents' ages

Oops - didn't notice that Grover Cleveland had two terms, which threw a monkey wrench into my inauguration and term end dates (nice to see HIGHLOW handles the multiple line segments though!). Added President # tie-breaker - revised code, output below.

 

CODE

title;
proc format;                             * Kludge since Trump's term TBD;
picture trump 74.1-74.9="?" other='99.9';

data presidents2;
set presidents;
if AgeAtEndDate=. then AgeAtEndDate=AgeAtInauguration+4; * Default to 4-year term;
format AgeAtInauguration AgeAtEndDate trump. InaugurationDate PresidencyEndDate yymmddd10.;
label InaugurationDate="Inaugurated" PresidencyEndDate="End Date";

ods graphics on / imagemap height=11.25in width=11.25in;
proc sgplot data=presidents2 noautolegend;
highlow y=n low=AgeAtInauguration high=AgeAtEndDate /
        lowlabel=AgeAtInauguration highlabel=AgeAtEndDate lineattrs=(thickness=4pt);
yaxis grid reverse display=(nolabel noticks) type=discrete valueattrs=(size=8pt); 
yaxistable president / position=left valueattrs=(size=8pt) nolabel;
yaxistable InaugurationDate PresidencyEndDate / valueattrs=(size=8pt) labelattrs=(size=8pt);
xaxis grid values=(40 to 80 by 5) valuesformat=z2. valueattrs=(size=8pt)
      label="Age of US Presidents at Beginning and End of Term";
run

CHART

PresidentAgesV2.png

Post a Question
Discussion Stats
  • 2 replies
  • 380 views
  • 1 like
  • 2 in conversation