BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
aniket_bankar
Calcite | Level 5
I am trying to format the x-axis in my forest plot using SG plot procedure. 
I want to break the x-axis as one of the scatter is an outlier (see the services parameter). 
I want the axis to be from a range Min to 7 and then from 25-27. However I am unable to do that. 
My code is pasted below. 
 
proc sgplot data=work.midtermfp_4 dattrmap=attrmap 
noautolegend
nocycleattrs
    nowall;
    styleattrs AXISBREAK = BRACKET AXISEXTENT=DATA
      ;
ods pdf
style=styles.forest;
 
     *--- remove box around plot ---;
    styleattrs 
      axisextent=data
      ;
 
  *--- banding and reference line ---;
   refline band / 
      lineattrs=(thickness=17 color=CXE8F2F4); 
      ;
  
    *--- add reference line ---;
   refline 1 /axis=x
    lineattrs= (color=CX305662) transparency=0.5;
      ;
  
  *--- estimates and CIs ---;
   scatter y=record x=relative_risk /
      markerattrs=(symbol=squarefilled size=12 color=CX305662);
      xaxis ranges=(min-10 25-27)
      offsetmin=0.0 offsetmax=0.0 minor
      display=(nolabel)
      ;
   highlow y=record low=LCL_u high=UCL_u /
  lineattrs= (color=CX305662)
  ;
   
  *--- adding yaxis table at left ---;
   yaxistable subgroup / 
      location=inside
      position=left
      textgroup=level
      textgroupid=text
      indentweight=indentWt         /* 9.4m3 */
      ;
   *--- primary axes ---;
   yaxis
      reverse
      display=none
      offsetmin=0
      colorbands=odd
      colorbandsattrs=(transparency=1) 
      ;
      
   *--- a second yaxis table at left ---;
   yaxistable VAR4 VAR5/
      location=inside
      position=left
      ;
   
   *--- adding yaxis table at right ---;
   yaxistable VAR7 p_value /
      location=inside
      position=right
      ; 
      
   *--- text above xaxis ---;
   text x=x1 y=record text=text / 
      position=bottom 
      contributeoffsets=none 
      strip
      ;
   
   *--- text above x2axis ---;
   scatter y=record x=relative_risk / 
      markerattrs=(size=0) 
      x2axis
      ;
   x2axis offsetmin=0.0
      label='Relative risk (95% CI)' 
      display=(noline noticks novalues) 
      ;
run;
1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

From the documentation on Axis ranges:

 

When plots are associated with both the X and X2 axes or with both the Y and Y2 axes, neither axis can be broken.

Since you have an Xaxis and X2axis then you can't break either.

Either move the label to Xaxis, or remove the xaxis and break the X2axis. Or use another method than X2axis to show that label text as a fake title. Perhaps actually use a Title statement?

 

Please paste code and log entries into a code box opened with the forum's {I} or running man icon to preserve simple text format.

 

When I copy your code as shown and paste into my SAS editor every line has a period on it which does not appear visibly in the forum

View solution in original post

2 REPLIES 2
ballardw
Super User

From the documentation on Axis ranges:

 

When plots are associated with both the X and X2 axes or with both the Y and Y2 axes, neither axis can be broken.

Since you have an Xaxis and X2axis then you can't break either.

Either move the label to Xaxis, or remove the xaxis and break the X2axis. Or use another method than X2axis to show that label text as a fake title. Perhaps actually use a Title statement?

 

Please paste code and log entries into a code box opened with the forum's {I} or running man icon to preserve simple text format.

 

When I copy your code as shown and paste into my SAS editor every line has a period on it which does not appear visibly in the forum

aniket_bankar
Calcite | Level 5

Thanks @ballardw. I removed x2 axis and it worked like charm! 

sas-innovate-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 3276 views
  • 1 like
  • 2 in conversation