Data visualization with SAS programming

label between bars

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 8
Accepted Solution

label between bars

Hi SAS experts,

I try to use annotation to place a label in between two bars. But I can only put it on top of one bar, and don't know how to put it in between two bars.

In the below code, I try to place the label "p=0.001" in between bars "RC and "RF".  In another word, I try to put the label on top-middle of the the line generated by the code

function=  "polycont"; xc1="RC"; y1=49;  output;

function=  "polycont"; xc1="RF"; y1=49;  output;

I have tried to give a large value of width, it didn't work either. It always sits on top of the "RC" bar.

Can anybody help me?

I am using SAS 9.3 M1.

Thanks a lot!

Juen

Here is my code:

data bites_results;   * bites per 100 kcal;

input meal $ 1-31 diet $ 32-37 size bites bites_SE;

datalines;

                     B         RC        34      33.2941176       2.0170969

                     B         RF        23      43.2173913       2.5683976

                     B         EB        46      46.9565217       2.1526204

;

run;

data bites_results; set bites_results;

meal= compress(meal);

upper=bites + bites_SE;

lower=bites - bites_SE;

run;

data anno;

length xc1 $2;

retain drawspace "datavalue" linethickness 4;

function = "polyline"; xc1="RC"; y1= 37; output;

function=  "polycont"; xc1="RC"; y1=49;  output;

function=  "polycont"; xc1="RF"; y1=49;  output;

function=  "polycont"; xc1="RF"; y1=47;  output;

function=  "text";     xc1="RC"; y1=50; label= "p=0.001"; textsize=15;  width=100; output;

run;

proc sgplot data=bites_results sganno=anno;

vbarparm category=diet response= bites /limitupper = upper limitlower=lower LIMITATTRS=(thickness=2) ;

yaxis label="Bite Count" labelattrs=(size=20) valueattrs=(size=20) offsetmin = 0;

xaxis display=(nolabel) valueattrs=(size=20) ;

run;


Accepted Solutions
Solution
‎05-27-2015 04:59 PM
SAS Super FREQ
Posts: 1,147

Re: label between bars

To place anything on a discrete axis in a place other than the midpoint value, use the DISCRETEOFFSET attribute.  To put something halfway between A and B (adjacent values), use XC1='A' and DiscreteOffset=0.5  OR XC1='B' and DiscreteOffset= -0.5.

View solution in original post


All Replies
Solution
‎05-27-2015 04:59 PM
SAS Super FREQ
Posts: 1,147

Re: label between bars

To place anything on a discrete axis in a place other than the midpoint value, use the DISCRETEOFFSET attribute.  To put something halfway between A and B (adjacent values), use XC1='A' and DiscreteOffset=0.5  OR XC1='B' and DiscreteOffset= -0.5.

Occasional Contributor
Posts: 8

Re: label between bars

Thanks. It does the trick.

Below is my code just in case others may be interested.

function=  "text"; xc1="RC"; DiscreteOffset=0.5; y1=50; label= "p=0.001"; textsize=15;  width=100; output;

Thanks a lot.

Juen

SAS Super FREQ
Posts: 1,147

Re: label between bars

FYI...It is also possible to place text in the graph using the MARKERCHAR option of the SCATTER plot.  The data can come from the procedure data set and you can use DiscreteOffset the same way.  With SAS 9.4M2, you can also use the TEXT statement.

🔒 This topic is solved and locked.

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

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