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
Facility | response | target |
---|---|---|
h1 | 26 | 36 |
h2 | 8 | 18 |
h3 | 11 | 5 |
h4 | 112 | 140 |
Graph should look like this or so (with the red lines being the targets)
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
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.
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.
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;
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
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.