Data visualization with SAS programming

How to set up different coutline colors for subgroup bars?

Reply
Occasional Contributor
Posts: 9

How to set up different coutline colors for subgroup bars?

Does anyone know how to set up different coutline colors for each group in subgrouped vertical bars?

Is this possible?

Thx a lot.

Mladen

SAS Employee
Posts: 967

How to set up different coutline colors for subgroup bars?

The GChart 'coutline=' option controls the color of all the bar segment outlines.

I do not know of a GChart option to control the outline color of individual bar segments or groups of segments.

You could hypothetically use GChart to draw the axes (with zero-height bars), and then use the annotate function='bar' to draw the bar segments (using style='solid' for the interior fill color, and style='empty' for the outlines ... and then you would have total control over the outline color of each bar segment) ... but that would be very cumbersome (especially if you want to generalize the code to handle different data).

What kind of data are you trying to graph, and what would you like to be able to "see" (gain insight into) from the graph? ... Maybe there's a different/easier way to visualize it(?)

Occasional Contributor
Posts: 9

How to set up different coutline colors for subgroup bars?

Hi Robert!

First of all, thanks for your suggestions.

Now, I want to set up black coutline for bars.

picture1.bmp

This is my code.

%let date2=31JAN2012:0:0:0;

%let date1=31DEC2011:0:0:0;

%let Bilan_Ukupnof_2=33488;

%let Bilan_Ukupnof_1=33474;

%let VANBilan_HRK_Ukupnof_2=4222;

%let VANBilan_HRK_Ukupnof_1=3887;

%let Izloz_RNH_f_2=4590;

%let Izloz_RNH_f_1=4668;

%let Izloz_DRT_f_2=548;

%let Izloz_DRT_f_1=504;

%let Izloz_FSA_f_2=4260;

%let Izloz_FSA_f_1=4266;

%let Izloz_Others_f_2=4347;

%let Izloz_Others_f_1=4343;

%let TOTAL_GE_f_2=47195;

%let TOTAL_GE_f_1=46896;

%put &Bilan_Ukupnof_2;

PROC SQL;

      CREATE TABLE waterfall

            (date num

            informat=datetime22.3

            format=datetime22.,

            flag char(20),

            Segment char(6),

            value num

            format=commax20.,

            GROUPVAR char(1)

            )

      ;

      INSERT INTO waterfall

          VALUES("'&date2'"dt,"previous_

month","Clear",0,"1")
            VALUES("'&date2'"dt,"previous_month","CRE",%sysevalf
(&Bilan_Ukupnof_2),"1")
            VALUES("'&date2'"dt,"previous_month","KIP",0,"1")
            VALUES("'&date2'"dt,"previous_month","RNH",0,"1")
            VALUES("'&date2'"dt,"previous_month","DRT",0,"1")
            VALUES("'&date2'"dt,"previous_month","Others",0,"1")
            VALUES("'&date2'"dt,"previous_month","TOTAL",0,"1")

            VALUES("'&date2'"dt,"previous_month","Clear",%sysevalf
(&Bilan_Ukupnof_2),"2")
            VALUES("'&date2'"dt,"previous_month","CRE",0,"2")
            VALUES("'&date2'"dt,"previous_month","KIP",%sysevalf
(&VANBilan_HRK_Ukupnof_2),"2")
            VALUES("'&date2'"dt,"previous_month","RNH",0,"2")
            VALUES("'&date2'"dt,"previous_month","DRT",0,"2")
            VALUES("'&date2'"dt,"previous_month","Others",0,"2")
            VALUES("'&date2'"dt,"previous_month","TOTAL",0,"2")

            VALUES("'&date2'"dt,"previous_month","Clear",%sysevalf
(&Bilan_Ukupnof_2+&VANBilan_HRK_Ukupnof_2),"3")
            VALUES("'&date2'"dt,"previous_month","CRE",0,"3")
            VALUES("'&date2'"dt,"previous_month","KIP",0,"3")
            VALUES("'&date2'"dt,"previous_month","RNH",&Izloz_RNH_f_2,"3")
            VALUES("'&date2'"dt,"previous_month","DRT",0,"3")
            VALUES("'&date2'"dt,"previous_month","Others",0,"3")
            VALUES("'&date2'"dt,"previous_month","TOTAL",0,"3")

            VALUES("'&date2'"dt,"previous_month","Clear",%sysevalf
(&Bilan_Ukupnof_2+&VANBilan_HRK_Ukupnof_2+&Izloz_RNH_f_2),"4")
            VALUES("'&date2'"dt,"previous_month","CRE",0,"4")
            VALUES("'&date2'"dt,"previous_month","KIP",0,"4")
            VALUES("'&date2'"dt,"previous_month","RNH",0,"4")
            VALUES("'&date2'"dt,"previous_month","DRT",&Izloz_DRT_f_2,"4")
            VALUES("'&date2'"dt,"previous_month","Others",0,"4")
            VALUES("'&date2'"dt,"previous_month","TOTAL",0,"4")

            VALUES("'&date2'"dt,"previous_month","Clear",%sysevalf
(&Bilan_Ukupnof_2+&VANBilan_HRK_Ukupnof_2+&Izloz_RNH_f_2+&Izloz_DRT_f_2),
"5")
            VALUES("'&date2'"dt,"previous_month","CRE",0,"5")
            VALUES("'&date2'"dt,"previous_month","KIP",0,"5")
            VALUES("'&date2'"dt,"previous_month","RNH",0,"5")
            VALUES("'&date2'"dt,"previous_month","DRT",0,"5")
            VALUES("'&date2'"dt,"previous_month","Others",%sysevalf
(&Izloz_Others_f_2),"5")
            VALUES("'&date2'"dt,"previous_month","TOTAL",0,"5")

            VALUES("'&date2'"dt,"previous_month","Clear",0,"6")
            VALUES("'&date2'"dt,"previous_month","CRE",0,"6")
            VALUES("'&date2'"dt,"previous_month","KIP",0,"6")
            VALUES("'&date2'"dt,"previous_month","RNH",0,"6")
            VALUES("'&date2'"dt,"previous_month","DRT",0,"6")
            VALUES("'&date2'"dt,"previous_month","Others",0,"6")
            VALUES("'&date2'"dt,"previous_month","TOTAL",%sysevalf
(&TOTAL_GE_f_2),"6")


        VALUES("'&date1'"dt,"current_month","Clear",0,"1")
            VALUES("'&date1'"dt,"current_month","CRE",%sysevalf
(&Bilan_Ukupnof_1),"1")
            VALUES("'&date1'"dt,"current_month","KIP",0,"1")
            VALUES("'&date1'"dt,"current_month","RNH",0,"1")
            VALUES("'&date1'"dt,"current_month","DRT",0,"1")
            VALUES("'&date1'"dt,"current_month","Others",0,"1")
            VALUES("'&date1'"dt,"current_month","TOTAL",0,"1")

            VALUES("'&date1'"dt,"current_month","Clear",%sysevalf
(&Bilan_Ukupnof_1),"2")
            VALUES("'&date1'"dt,"current_month","CRE",0,"2")
            VALUES("'&date1'"dt,"current_month","KIP",%sysevalf
(&VANBilan_HRK_Ukupnof_1),"2")
            VALUES("'&date1'"dt,"current_month","RNH",0,"2")
            VALUES("'&date1'"dt,"current_month","DRT",0,"2")
            VALUES("'&date1'"dt,"current_month","Others",0,"2")
            VALUES("'&date1'"dt,"current_month","TOTAL",0,"2")

            VALUES("'&date1'"dt,"current_month","Clear",%sysevalf
(&Bilan_Ukupnof_2+&VANBilan_HRK_Ukupnof_1),"3")
            VALUES("'&date1'"dt,"current_month","CRE",0,"3")
            VALUES("'&date1'"dt,"current_month","KIP",0,"3")
            VALUES("'&date1'"dt,"current_month","RNH",&Izloz_RNH_f_1,"3")
            VALUES("'&date1'"dt,"current_month","DRT",0,"3")
            VALUES("'&date1'"dt,"current_month","Others",0,"3")
            VALUES("'&date1'"dt,"current_month","TOTAL",0,"3")

            VALUES("'&date1'"dt,"current_month","Clear",%sysevalf
(&Bilan_Ukupnof_1+&VANBilan_HRK_Ukupnof_1+&Izloz_RNH_f_1),"4")
            VALUES("'&date1'"dt,"current_month","CRE",0,"4")
            VALUES("'&date1'"dt,"current_month","KIP",0,"4")
            VALUES("'&date1'"dt,"current_month","RNH",0,"4")
            VALUES("'&date1'"dt,"current_month","DRT",&Izloz_DRT_f_1,"4")
            VALUES("'&date1'"dt,"current_month","Others",0,"4")
            VALUES("'&date1'"dt,"current_month","TOTAL",0,"4")

            VALUES("'&date1'"dt,"current_month","Clear",%sysevalf
(&Bilan_Ukupnof_1+&VANBilan_HRK_Ukupnof_1+&Izloz_RNH_f_1+&Izloz_DRT_f_1),
"5")
            VALUES("'&date1'"dt,"current_month","CRE",0,"5")
            VALUES("'&date1'"dt,"current_month","KIP",0,"5")
            VALUES("'&date1'"dt,"current_month","RNH",0,"5")
            VALUES("'&date1'"dt,"current_month","DRT",0,"5")
            VALUES("'&date1'"dt,"current_month","Others",%sysevalf
(&Izloz_Others_f_1),"5")
            VALUES("'&date1'"dt,"current_month","TOTAL",0,"5")

            VALUES("'&date1'"dt,"current_month","Clear",0,"6")
            VALUES("'&date1'"dt,"current_month","CRE",0,"6")
            VALUES("'&date1'"dt,"current_month","KIP",0,"6")
            VALUES("'&date1'"dt,"current_month","RNH",0,"6")
            VALUES("'&date1'"dt,"current_month","DRT",0,"6")
            VALUES("'&date1'"dt,"current_month","Others",0,"6")
            VALUES("'&date1'"dt,"current_month","TOTAL",%sysevalf
(&TOTAL_GE_f_1),"6")

      ;
      SELECT *
            FROM waterfall;
QUIT;

data waterfall;
   set waterfall;
   new=trim(flag)||groupvar;
run;

%_sas_pushchartsize(1000,800);

pattern1 v=s c=white;
pattern2 v=s c=mob/*CX003366*/ ;
pattern3 v=s c=vibg/*CX90B0D9*/;
pattern4 v=s c=darker_blue/*CX325682*/;
pattern5 v=s c=CX90B0D9/*CXB22222*/;
pattern6 v=s c=orange/*CX325682*/;
pattern7 v=s c=FireBrick/*CXB22222*/;
/* Define axis characteristics */
axis1 minor=none;
/* Add the title */
title 'Campaign Contributions in 2007';

goptions htext=12pt ctext=white;
/*PATTERN1 COLOR=CX003366;
PATTERN2 COLOR=CX90B0D9;*/

Axis1 order=(25000 to 50000 by 5000 )
      STYLE=1
      WIDTH=1
      color=black
      MINOR=NONE
      LABEL=(angle=90 f="Arial" h=12pt "mio HRK") VALUE=(F="arial"  HEIGHT=
5pt) ;

Axis2 LABEL=none VALUE=(f='Arial' HEIGHT=12pt "12/11" "01/12" "12/11"
"01/12" "12/11" "01/12" "12/11" "01/12" "12/11" "01/12" "12/11" "01/12")
offset=(5,5) color=black;

Axis3 LABEL=none VALUE=(f='Arial' HEIGHT=12pt "CRE" "KIP" "RNH" "DRT"
"Others" "Total")
color=black;

Legend1
      NOFRAME
      CBORDER=WHITE
      CFRAME=WHITE
      POSITION = (TOP LEFT INSIDE)
      LABEL=none VALUE=(f='Arial' HEIGHT=12pt c=black '' 'CRE' 'DRT' 'KIP'
'Others' 'RNH' 'Total' )
      offset=(0,0)
      shape=bar(3,1)
      MODE=SHARE
      across=7;

TITLE;
TITLE1;
TITLE2 h=7.5pt color="darker_blue" move=(67,34.50) JUSTIFY=CENTER font
=arial "Naslov";
FOOTNOTE;
FOOTNOTE1;

PROC GCHART DATA=WORK.waterfall
;
            VBAR flag /inside=sum
            SUMVAR=value
            GROUP=groupvar
            SUBGROUP=segment
            /*midpoints="CRE" "KIP" "RNH" "DRT" "Others" "Total"*/
            CLIPREF
            gspace=1.5
            space=0
            WIDTH=8.5

            coutline=white
            legend=legend1
            RAXIS=AXIS1
            MAXIS=AXIS2
            GAXIS=AXIS3

            des="" name="wfall";

      format value commax7.
      ;
RUN;

QUIT;
TITLE; FOOTNOTE;
TITLE;
FOOTNOTE;
GOPTIONS RESET = SYMBOL;
%_sas_popchartsize;

SAS Employee
Posts: 967

How to set up different coutline colors for subgroup bars?

Where you've got "coutline=white" ... change that to "coutline=black".

Occasional Contributor
Posts: 9

How to set up different coutline colors for subgroup bars?

Yes I know, but this is not acceptable solution for me.

Because i don't want coutline for white subgroups. In this case I will not get waterfall graph if you understand me.


SAS Employee
Posts: 967

How to set up different coutline colors for subgroup bars?

I think I don't understand what you're asking for.

Could you perhaps use a drawing package (such as "Paint") and draw the outline you want on the graph (by hand), and post that hand-edited image here, so I can see what areas you're wanting to be outlined?

Occasional Contributor
Posts: 9

How to set up different coutline colors for subgroup bars?

I apologize for the unclear explanation..

This is what I want, if it possible..


I would like if it possible to automate process.

picture1.bmp.

Occasional Contributor
Posts: 9

How to set up different coutline colors for subgroup bars?

picture1.bmp

SAS Employee
Posts: 967

How to set up different coutline colors for subgroup bars?

Hmm ... so you're using an "invisble" (white, same color as the background, with coutline=white) bar segment to give other bar segments the appearance of 'floating', to create something similar to a waterfall chart. ... And the reason you don't want to use coutline=black is that it will make this "invisible" segment visible again. [And with Gchart's coutline= it is all-or-nothing ... no way to coutline individual bars.]

It would be very difficult to draw these outlines with annotate (even more complex with grouped bars, as you have).  When dealing with bar charts, annotate only has access to the 'middle' position of the bar midpoint & group midpoint ... and then you would have to use an offset to the left & right (which you could somewhat calculate by figuring out the number of bars, and the % each bar occupies in the available space ... but which is also affected by the bar witdth, the spacing between the bars, and the spacing between the groups).  This one's beyond me.

Perhaps, instead, it would be better to go with a 'real' waterfall chart - sgplot has one that's experimental at SAS 9.3 (I know a lot of users don't want to depend on experimental functionality, but this would probably be a safer bet than trying to fake it with gchart & annotate the bar outlines ... and have you worked out what will happen if you have negative values?).  Also, you'd probably have to use 2 waterfall charts, rather than the 'grouped' chart:

http://support.sas.com/documentation/cdl/en/grstatproc/64778/HTML/default/viewer.htm#n121lznfa1jnlvn...

Sorry I don't have a great answer for you, but this might be one of those situations where it might be best to present the data in a slightly different way.

Occasional Contributor
Posts: 9

How to set up different coutline colors for subgroup bars?

Yes, that's right. I used coutline same as background to make segments invisible.

In my case I will never have a negative value.

Thx for sgplot suggestions.

I will see what can I do.

Thx for all.

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