Data visualization with SAS programming

Waterfall plot

Reply
Occasional Contributor
Posts: 18

Waterfall plot

Does anyone know if the circled area in the screenshot below is possible to program?  It was manually inserted, thanks.

Capture.PNG

Super User
Posts: 23,224

Re: Waterfall plot

Posted in reply to HitmonTran

It's probably possible using either POLYGON or possibly a MARKER PLOT since they're all the same size

This assumes you're using SGPLOT or SG procedures in general though. 

SAS Super FREQ
Posts: 1,068

Re: Waterfall plot

Posted in reply to HitmonTran

Using data from Sanjay's post on waterfall charts (https://blogs.sas.com/content/graphicallyspeaking/2017/07/30/clinical-graphs-waterfall-plot/), I created a little example that should get you going. The key here is using the Y2AXIS and adjusting the offsets of both the YAXIS and Y2AXIS so that the overlaid bar charts do not collide. You can use an attributes map to control the colors of the "coding" bar chart.

 

Hope this helps!

Dan

 

data TumorSize;
  length Cid $ 3;
  label Change='Change from Baseline (%)';
  do Id=1 to 25;
    cid=put(id, 2.0);
    change=30-120*ranuni(2);
    Group=ifc(int(ranuni(2)+0.5), 'Treatment 1', 'Treatment 2');
        Duration=floor(50+100*ranuni(2));
        Drop=ifn(ranuni(2) < 0.3, floor(duration-10), .);
    if mod(id, 5) = 1 then Label='C';
    if mod(id, 5) = 2 then label='R';
    if mod(id, 5) = 3 then label='S';
    if mod(id, 5) = 4 then label='P';
    if mod(id, 5) = 0 then label='N';
    output;
  end;
run;

/* Add dummy response value for the "coding" bar chart */
data temp;
set TumorSize;
retain dummyvar 1;
run;

/* Sort it */
proc sort data=temp out=TumorSizeSort;
  by descending change;
run;

/* Draw it */
title "Waterfall";
proc sgplot data=TumorSizeSort;
xaxis display=none discreteorder=data;
yaxis offsetmin=0.15 min=-100 max=100;
y2axis display=none offsetmax=0.9;
vbarparm category=id response=change / group=group;
vbarparm category=id response=dummyvar / group=label y2axis name="code";
refline 20 / lineattrs=(color=green pattern=dash);
refline -30 / lineattrs=(color=blue pattern=dash);
keylegend "code";
run;
PROC Star
Posts: 2,305

Re: Waterfall plot

[ Edited ]

None of my business, but if the bottom bars mean what I think, the chart may be easier to read this way:

 

Capture.PNG

( it would probably be better to remove the space between the background bars but I couldn't).

 

data TumorSize;
  length Cid $ 3;
  label Change='Change from Baseline (%)';
  do Id=1 to 25;
    cid=put(id, 2.0);
    change=30-120*ranuni(2);
    Group=ifc(int(ranuni(2)+0.5), 'Treatment 1', 'Treatment 2');
        Duration=floor(50+100*ranuni(2));
        Drop=ifn(ranuni(2) < 0.3, floor(duration-10), .);
    if mod(id, 5) = 1 then Label='C';
    if mod(id, 5) = 2 then label='R';
    if mod(id, 5) = 3 then label='S';
    if mod(id, 5) = 4 then label='P';
    if mod(id, 5) = 0 then label='N';
    output;
  end;
run;

/* Add dummy response value for the "coding" bar chart */
data temp;
  set TumorSize;
  retain dummyvar 11;
run;

/* Sort it */
proc sort data=temp out=TumorSizeSort;
  by descending change;
run;

/* Draw it */
title "Waterfall";
proc sgplot data=TumorSizeSort;
  xaxis display=none discreteorder=data;
  yaxis offsetmin=0.15 min=-100 max=100;
  y2axis display=none offsetmax=0.9 min=0 max=1;
  vbarparm category=id response=change   / group=group ;
  vbarparm category=id response=dummyvar / group=label y2axis name="code" transparency=.8  barwidth=1  nooutline;
  refline 20 / lineattrs=(color=green pattern=dash);
  refline -30 / lineattrs=(color=blue pattern=dash);
  keylegend "code";
run;

 

Super User
Posts: 13,283

Re: Waterfall plot

@ChrisNZ, the inability to get the background bars without space might be choice of style and (guessing here) whether it uses a bar outline color.

 

I ran you code using style Meadow and get:

SGPlot.png

Ask a Question
Discussion stats
  • 4 replies
  • 133 views
  • 1 like
  • 5 in conversation