DATA Step, Macro, Functions and more

How to add reference lines per category in proc sgplot ?

Reply
New Contributor
Posts: 3

How to add reference lines per category in proc sgplot ?

 

 

 

My dataset contains vitamin D intake from 4 different sources (bron) for 7 different subpopulations (a,b,c,d,e,f,g).

Is it possible to create reference lines that do not cover the entire width of a graph but with a limited to the concerned category.

 

SGPlot2.png

 

proc format; 
value formsubpop  1="a"
                  2="b"
			      3="c"
			      4="d"
			      5="e"
			      6="f"
			      7="g";
			      run;

proc sort data=VitD_aggr;
by subpop ;
run;

proc sgplot data=VitD_aggr;
  vbox VitD_tot/category=subpop group=bron grouporder=descending boxwidth=0.9 NOOUTLIERS;
    YAXIS LABEL = 'Usual vitamin D intake (ug/day)' GRID VALUES = (0 TO 50 BY 10); 
  xaxis display=(nolabel) ;
  REFLINE 10 /label="AI=10 ug/day" lineattrs=(color=green);
  REFLINE 25 /label="UL=25 ug/day" lineattrs=(color=red);
  REFLINE 15 /label="AI=15 ug/day" lineattrs=(color=green);
  REFLINE 50 / label="UL=50 ug/day" lineattrs=(color=red);
  format subpop formsubpop. ;
  keylegend / location =outside position =bottom across=1;
  run;

 

PROC Star
Posts: 1,190

Re: How to add reference lines per category in proc sgplot ?

Posted in reply to IsabelleM

How do you know if a refline applies to a certain category? If it is in the 95% confidence interval? If it is in the quartile range?

New Contributor
Posts: 3

Re: How to add reference lines per category in proc sgplot ?

Thank you for your reply.

The reflines depend on the subpop (=subpopulations) I will probably have to define them by subpop?

 

refline 10 and 50 apply to subpop's a, b, c and d

refline 15 and 50 apply to subpop's e, f and g

 

 

Super User
Posts: 13,000

Re: How to add reference lines per category in proc sgplot ?

Posted in reply to IsabelleM

It sounds like you are asking for something that likely is in the annotate facility. That will allow you do specify drawing a line between two coordinates over/under other elements. You would construct an appropriate data set with the drawing instructions and reference in the procedure with the SGANNO= option to indicate the set to use. There are a number of macros available to help such as %sgline to create the instructions given some parameters such as coordinates and line properties.

 

Super User
Posts: 22,820

Re: How to add reference lines per category in proc sgplot ?

Posted in reply to IsabelleM

Instead of a reference line think of it is as a customized scatter plot, with the symbols being a straight line. 

Add in the values for your individual reference to your data set, if it's not already included.

Then you can use SCATTER to include customized reference line. 

 


IsabelleM wrote:

 

 

 

My dataset contains vitamin D intake from 4 different sources (bron) for 7 different subpopulations (a,b,c,d,e,f,g).

Is it possible to create reference lines that do not cover the entire width of a graph but with a limited to the concerned category.

 

SGPlot2.png

 

proc format; 
value formsubpop  1="a"
                  2="b"
			      3="c"
			      4="d"
			      5="e"
			      6="f"
			      7="g";
			      run;

proc sort data=VitD_aggr;
by subpop ;
run;

proc sgplot data=VitD_aggr;
  vbox VitD_tot/category=subpop group=bron grouporder=descending boxwidth=0.9 NOOUTLIERS;
    YAXIS LABEL = 'Usual vitamin D intake (ug/day)' GRID VALUES = (0 TO 50 BY 10); 
  xaxis display=(nolabel) ;
  REFLINE 10 /label="AI=10 ug/day" lineattrs=(color=green);
  REFLINE 25 /label="UL=25 ug/day" lineattrs=(color=red);
  REFLINE 15 /label="AI=15 ug/day" lineattrs=(color=green);
  REFLINE 50 / label="UL=50 ug/day" lineattrs=(color=red);
  format subpop formsubpop. ;
  keylegend / location =outside position =bottom across=1;
  run;

 


 

New Contributor
Posts: 3

Re: How to add reference lines per category in proc sgplot ?

I have tried this out with polylines and polycont and it worked.

 

Thank you for your help!

Ask a Question
Discussion stats
  • 5 replies
  • 102 views
  • 2 likes
  • 4 in conversation