Data visualization with SAS programming

Help with Gchart -horizontal bar, with over-under subgroups

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 12
Accepted Solution

Help with Gchart -horizontal bar, with over-under subgroups

I have a small data set containing roughly 30 cases which have variables for ID (alphanumeric), size ("Large", "Extra Large"), a variable containing the percent passed using one inspection type (call it "Contractor_Passed") and another containing the percent passed using another type ("Public_Passed"). I want a horizontal bar chart with all the agencies on the y axis (showing the ID variable), each having two bars (one under the other): one for each score type.  Basically, I'm comparing the percent passed of each type of inspection for each agency.  

I've tried looking online, but all of the gcharts with subgroups I've found have grouping based one one dichotomous categorical variable (e.g. gender) with single split bars.  Can Gchart make over-under bars with grouping based on two numeric variables, which I am comparing?  If necessary, I can make one for each size category and then use GREPLAY to put them side by side. 


Accepted Solutions
Solution
‎12-19-2014 10:45 AM
SAS Super FREQ
Posts: 925

Re: Help with Gchart -horizontal bar, with over-under subgroups

Try this example, and see if it is what you want:

proc sgplot data=sashelp.class;

hbar age / response=height stat=mean barwidth=0.4 discreteoffset=-0.2 x2axis;

hbar age / response=weight stat=mean barwidth=0.4 discreteoffset=0.2;

run;

View solution in original post


All Replies
Solution
‎12-19-2014 10:45 AM
SAS Super FREQ
Posts: 925

Re: Help with Gchart -horizontal bar, with over-under subgroups

Try this example, and see if it is what you want:

proc sgplot data=sashelp.class;

hbar age / response=height stat=mean barwidth=0.4 discreteoffset=-0.2 x2axis;

hbar age / response=weight stat=mean barwidth=0.4 discreteoffset=0.2;

run;

SAS Super FREQ
Posts: 925

Re: Help with Gchart -horizontal bar, with over-under subgroups

I just saw that both of your responses are percentages, so you might want to drop the "x2axis" option from the first HBAR statement.

Occasional Contributor
Posts: 12

Re: Help with Gchart -horizontal bar, with over-under subgroups

I think I found a way to combine the two graphs I have using SGPANEL, but I cannot get the layout the way I want it.   When I split the panels by size (2 categories) I see all the cases along wht x axis for both categories, leaving a lot of empty space in the panels.  My data set is structured so that each record is ONE of the TWO categories I am splitting the panels by.  How do I remove the empty records from the panels so that each panel only includes the applicable records instead of all?    Here is my working code:

proc sgpanel data=DATA_FINAL;

  panelby size  ;

  rowaxis label="Percent Passed";

  colaxis discreteorder=data label = 'Agency';

vbar ID / response=_Passed_by_c stat=mean barwidth=0.4  discreteoffset=0.5  ;

vbar ID / response=_Passed_by_P stat=mean barwidth=0.8  discreteoffset=0.5 transparency=.4 ;

run;

quit;

Once I get this fixed, I can work on the bar widths and spacing.

SAS Super FREQ
Posts: 925

Re: Help with Gchart -horizontal bar, with over-under subgroups

On the PANELBY statement, specify:

panelby size / uniscale=row layout=columnlattice;

Also, I'm not sure of your intent, by having both DISCRETEOFFSETs set to 0.5 will still make the bars be on top of one another. Did you mean to drop the minus from one of the statements?

Hope this helps!

Dan

Occasional Contributor
Posts: 12

Re: Help with Gchart -horizontal bar, with over-under subgroups

I prefer to have the bars completely overlapped; I find it much easier to read when the differences between the two are so great.  I also increased the width of the bar corresponding to the 'base' measure so that the reader can differentiate the measures in the lower portion.

SAS Super FREQ
Posts: 925

Re: Help with Gchart -horizontal bar, with over-under subgroups

If you like the overlap, you might like this approach better:

vbar ID / response=_Passed_by_c stat=mean transparency=.4

vbar ID / response=_Passed_by_P stat=mean barwidth=0.5  transparency=.4 ; 

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 6 replies
  • 553 views
  • 3 likes
  • 2 in conversation