******************************************** * www.stattutorials.com * * (c) Alan C. Elliott, 2010 * * Send comments to info@texasoft.com * ******************************************** ; DATA BARGRAPH; INPUT ITEM $10. AGREE NEUTRAL DISAGREE; * TURN THE DATA INTO PERCENTS WITHIN QUESTION; APCT=100*(agree / SUM(of AGREE,NEUTRAL,DISAGREE)); NPCT=100*(neutral / SUM(of AGREE,NEUTRAL,DISAGREE)); DPCT=100*(disagree / SUM(of AGREE,NEUTRAL,DISAGREE)); percent="Agree";wt= APCT;output; percent= "Neutral";wt=NPCT;output; percent="Disagree";wt=DPCT;output; keep item percent WT; datalines; QUESTION1 89 4 7 QUESTION2 84 8 6 QUESTION3 55 23 22 QUESTION4 21 45 34 QUESTION5 33 33 33 ; RUN; goptions reset=all; goptions hsize=8 vsize=6; options nodate nonumber orientation=landscape; * SPECIFY COLORS AND PATTERNS FOR THE BARS; pattern1 value=solid color=blue; pattern2 value=solid color=yellow; pattern3 value=solid color=maroon; pattern4 value=solid color=green; pattern5 value=solid color=purple; *DESIGN THE LEGEND TO BE AT THE RIGHT SIDE OF THE CHART * NOTE: SINCE WE COMBINED AGREE AND STRONGLY AGREE INTO ONE ITEM (AGREE) * WE INCLUDE THAT INFORMATION ON THE LABEL, AND SEPARATE IT INTO THREE * LINES FOR BETTER SPACING; legend1 value=(angle=90 f=swiss h=.75) shape=bar(1,3) label=none order=("Agree" "Neutral" "Disagree") value=(tick=1 justify=c 'Strongly' justify=c 'Agree' justify=c 'or Agree' tick=2 justify=c ' ' justify=c ' Neutral' justify=c ' ' tick=3 justify=c 'Strongly' justify=c 'Disagree' justify=c 'or Disagree') position = (middle right outside) across=1; * CREATE AXIS DEFINITIONS AXIS1 is GROUP AXIS, GAXIS AXIS2 IS RESPONSE AXIS, RAXIS AXIS3 IS MIDPOINT AXIS, MAXIS; axis1 label=none value=(angle=55 h=.8 f=Swiss); axis2 label=(angle=90 f=Swiss H=1.5 "Percent") order=(0 to 100 by 10); axis3 value=none label=none; title h=1.25 "Stacked Barchart with Key on Side"; * CODE TO CTEATE THE STACKED BARCHART WHEER VBAR (creates vertical bars based on the grouping variable variable ITEM GROUP=ITEM SUBGROUP=PERCENT designates the percents for each item ; proc gchart data=bargraph; vbar item/ frame sumvar=wt subgroup=percent group=item nozero gaxis=axis1 raxis=axis2 maxis=axis3 legend=legend1; run; quit;