BookmarkSubscribeRSS Feed
BigD
Calcite | Level 5

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

2 REPLIES 2
Jay54
Meteorite | Level 14

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;

BigD
Calcite | Level 5

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

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 1115 views
  • 3 likes
  • 2 in conversation