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-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
  • 1954 views
  • 1 like
  • 2 in conversation