Data visualization with SAS programming

SGANNO Target Lines on a hbar chart

Reply
Contributor
Posts: 36

SGANNO Target Lines on a hbar chart

Hi,

I am having trouble getting  vertical lines as targets in the proper place for a hbar chart using sgplot procedure

data looks something like this

Facilityresponsetarget
h12636
h2818
h3115
h4112140

Graph should look like this or so (with the red lines being the targets)

Capture.JPG

I've seen it done with the regular annotate facility, but haven't been able to get too far with sganno

Thanks for your help.

Bruce

SAS Super FREQ
Posts: 1,080

Re: SGANNO Target Lines on a hbar chart

While you can certainly do this with SGAnno, you don't need annotate  You can use HBarParm and HiglLow combination to get what you need.  You can reduce the bar width if you need.  Here is the graph and the code.

TargetSG.png

data target;
  input Facility $ Response Target;
  datalines;
H1  26  36
H2   8  18
H3  11  25
H4 112 140
;
run;


title 'Response and Target by Facility';
proc sgplot data=target;
  hbarparm category=facility response=response / fillattrs=graphdata1 name='a';
  highlow  y=facility low=target high=target / lineattrs=graphdata2(thickness=2 pattern=solid)
    name='t' legendlabel='Target';
  highlow  y=facility low=target high=target / type=bar lineattrs=graphdata2(thickness=2 pattern=solid);
  xaxis display=(nolabel) offsetmin=0;
  yaxis display=(nolabel) reverse;
  discretelegend 'a' 't';
  run;

Two HighLow plots are used.  One with default Type=Line for the legend.  The other with Type=bar for the actual target in the graph.  You could use a scatter plot to draw the target for a different look.

TargetSG2.png

title 'Response and Target by Facility';

proc sgplot data=target;

  hbarparm category=facility response=response / fillattrs=graphdata1 name='a';

  scatter  y=facility x=target / markerattrs=graphdata2(symbol=triangledownfilled size=11)

    name='t' legendlabel='Target' discreteoffset=0.3;

  xaxis display=(nolabel) offsetmin=0;

  yaxis display=(nolabel) reverse;

  discretelegend 'a' 't';

  run;

Contributor
Posts: 36

Re: SGANNO Target Lines on a hbar chart

Thanks so much. Much easier and serves my purpose well.

Still would like to see the sganno solution as it would come in handy.

Bruce

Ask a Question
Discussion stats
  • 2 replies
  • 342 views
  • 3 likes
  • 2 in conversation