Data visualization with SAS programming

Stacked bar charts with positive and negative values

Reply
New Contributor
Posts: 2

Stacked bar charts with positive and negative values

Hi,

 

I have change data on a 4-point response scale. So patients can have up to a 3 category improvement, stay the same, or have up to a 3 category deterioration. So I have 7 categories a pt can fall into.

 

At the moment I have the data structured as below and use  proc sgpanel with vbar. This gets me close, but what I want to have is the stable (response = 0) in the middle, with the 0 y axis starting here with those who improved stacked on top, and then below the 0 axis have those who worsened.

 

Something like this (vertical or horizontal isn't a major worry) https://www.google.com/search?q=stacked+bar+chart+of+change&source=lnms&tbm=isch&sa=X&ved=0ahUKEwiR9...

 

data have;

input group percent response;

cards;

1 14.3 -3

1 14.3 -2

1 14.3 -1

1 14.3 0

1 14.3 1

1 14.3 2

1 14.3 3

0 14.3 -3

0 14.3 -2

0 14.3 -1

0 14.3 0

0 14.3 1

0 14.3 2

0 14.3 3

;

run;

 

proc sgpanel data = have;
format response chg.;
styleattrs datacolors=( cxAACEE2 cx65ABC4 cx017BA8 cx004159 cxA88BDD cx8959E0 cx643BAF)
datacontrastcolors=( cxAACEE2 cx65ABC4 cx017BA8 cx004159 cxA88BDD cx8959E0 cx643BAF);
vbar group / response= percent group=response ;
rowaxis label = 'Percent (%)' ;
colaxis label =' ' display=(novalues notick);

title 'Change from Baseline Frequencies  - Month 3';
run;

 

Thank you!!

SAS Super FREQ
Posts: 1,047

Re: Stacked bar charts with positive and negative values

Is this what you want?

 

patients.png

 

Basically, this required a little data tweak in a temporary data set that was, then, fed into PROC SGPLOT. The code is below. Let me know if this works for you,

 

Thanks!

Dan

 

data have;
input group percent response;
cards;
1 14.3 -3
1 14.3 -2
1 14.3 -1
1 14.3 0
1 14.3 1
1 14.3 2
1 14.3 3
0 14.3 -3
0 14.3 -2
0 14.3 -1
0 14.3 0
0 14.3 1
0 14.3 2
0 14.3 3
;
run;

proc format;
value grpfmt 0="Group 0"
             1="Group 1";
run;

data temp;
set have;
format group grpfmt.;
if response < 0 then percent = percent * -1;
else if response=0 then percent=0;
run;

proc sgplot data = temp;
styleattrs datacolors=( cxAACEE2 cx65ABC4 cx017BA8 cx004159 cxA88BDD cx8959E0 cx643BAF)
datacontrastcolors=( cxAACEE2 cx65ABC4 cx017BA8 cx004159 cxA88BDD cx8959E0 cx643BAF);
vbar group / response= percent group=response ;
yaxis label = 'Percent (%)' ;
xaxis label =' ';
title 'Change from Baseline Frequencies  - Month 3';
run;
New Contributor
Posts: 2

Re: Stacked bar charts with positive and negative values

Thank you!! This now has the 0 line where I need it, just one small problem the 3 category deterioration is directly below the 0 line, I guess I can just flip the change (my worry is that gets a little confusing) but I don't see a way around. Any order like ideas that would prevent possible confusion would be appreciated!

 

Presentation2.jpg

Ask a Question
Discussion stats
  • 2 replies
  • 123 views
  • 0 likes
  • 2 in conversation