BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
xxformat_com
Barite | Level 11

Hi,

 

Is there a way to add two different labels to the same axis. I got it using reference lines but it would make more sens to me to do it with xaxisopts and yaxisopts.

 

proc template;
    define statgraph class;
        begingraph / border=false;
	        layout overlay 
	            / xaxisopts=(label='Test' 
	                         linearopts=(origin=60 
	                                     tickvaluesequence=(start    =40 
	                                                        end      =80 
	                                                        increment=10)
	                                     viewmin=40 
	                                     viewmax=80)
	                         displaysecondary=(label))
	              yaxisopts=(label     =' ' 
	                         linearopts=(origin=100 
	                                     tickvaluesequence=(start    =40 
	                                                        end      =160
	                                                        increment=20)
	                                     viewmin=40 
	                                     viewmax=160))
	              
	              walldisplay=none;
	              
	        scatterplot x=height y=weight;
                    
            endlayout;
        endgraph;
    end;
run;


*ods graphics/noborder;
proc sgrender data=sashelp.class template=class ;
run;

two_labels.JPG

 

Expected result (obtained with reference lines after removing the labels from the axis)

two_labels.JPG

1 ACCEPTED SOLUTION

Accepted Solutions
JeffMeyers
Barite | Level 11

In order to use the x2/y2axis you have to have a graph that uses that axis even if that graph isn't visible.  I took your example and added the same scatterplot to the x2/y2 axes but made the markers size 0 so they don't show up.

 

 

proc template;
    define statgraph class;
        begingraph / border=false;
	        layout overlay 
	            / xaxisopts =(label='X')
                  x2axisopts=(label='A')
	              yaxisopts =(label='Y')
                  y2axisopts=(label='B')
	              
	              walldisplay=none;
	              
	        scatterplot x=height y=weight;
	        scatterplot x=height y=weight / xaxis=x2 yaxis=y2 markerattrs=(size=0pt);
	  
                    
            endlayout;
        endgraph;
    end;
run;


*ods graphics/noborder;
proc sgrender data=sashelp.class template=class ;
run;

 

 

View solution in original post

7 REPLIES 7
RW9
Diamond | Level 26 RW9
Diamond | Level 26

I expect you would need to use x2/y2axis to add differing labels to an axis.  For my money the axis on your given example is Weight, the high/low is a calculation plot not a label.  E.g. going down your route, why is 0 not labelled as no weight/no height?  Doesn't make sense does it.  The label indicates what is plotted on that axis, not what the value is.

xxformat_com
Barite | Level 11

"why is 0 not labelled" where do you see a zero? I guess that you mean why the other axis has no labelled ?

Simply because I've tried to limit the code to describe the problem. In my real program Both axes have labels.

 

I'm using proc template and as such we don't have x2axis. I gave a trial with x2axisopts and displaysecondary but couldn't get a different label.

 

proc template;
    define statgraph class;
        begingraph / border=false;
	        layout overlay 
	            / xaxisopts =(label='X' displaysecondary=all)
                  x2axisopts=(label='A')
	              yaxisopts =(label='Y' displaysecondary=all)
                  y2axisopts=(label='B')
	              
	              walldisplay=none;
	              
	        scatterplot x=height y=weight;
	  
                    
            endlayout;
        endgraph;
    end;
run;


*ods graphics/noborder;
proc sgrender data=sashelp.class template=class ;
run;

x2axis.JPG

JeffMeyers
Barite | Level 11

In order to use the x2/y2axis you have to have a graph that uses that axis even if that graph isn't visible.  I took your example and added the same scatterplot to the x2/y2 axes but made the markers size 0 so they don't show up.

 

 

proc template;
    define statgraph class;
        begingraph / border=false;
	        layout overlay 
	            / xaxisopts =(label='X')
                  x2axisopts=(label='A')
	              yaxisopts =(label='Y')
                  y2axisopts=(label='B')
	              
	              walldisplay=none;
	              
	        scatterplot x=height y=weight;
	        scatterplot x=height y=weight / xaxis=x2 yaxis=y2 markerattrs=(size=0pt);
	  
                    
            endlayout;
        endgraph;
    end;
run;


*ods graphics/noborder;
proc sgrender data=sashelp.class template=class ;
run;

 

 

xxformat_com
Barite | Level 11

Thanks. How do I change the orientation of the axis label. I would like to have them all horizontal.

JeffMeyers
Barite | Level 11

As far as I'm currently aware there is no rotation option for axis labels.  However you can do a clever work around with the following code.  A lattice layout doesn't necessarily have to have multiple rows/columns, but by using it you open up COLUMNHEADERS, ROWHEADERS, and SIDEBAR blocks where you can place ENTRY statements.  These ENTRY statements are more customizable than the regular labels, and if you put them into a layout gridded block you can still create multiple lines for long labels.

 

proc template;
    define statgraph class;
        begingraph / border=false;
            layout lattice / rows=1 columns=1;
                columnheaders;   
                      entry 'X-axis Label';
                endcolumnheaders;
                column2headers;   
                      entry 'X2-axis Label';
                endcolumn2headers;
                rowheaders;   
                      entry 'Y-axis Label';
                endrowheaders;
                row2headers;   
                      entry 'Y2-axis Label';
                endrow2headers;
	        layout overlay 
	            / xaxisopts =(display=(line ticks tickvalues))
	              yaxisopts =(display=(line ticks tickvalues))
	              
	              walldisplay=none;
	              
	        scatterplot x=height y=weight;
	  
                endlayout ;   
            endlayout;
        endgraph;
    end;
run;


*ods graphics/noborder;
proc sgrender data=sashelp.class template=class ;
run;
xxformat_com
Barite | Level 11

Thanks. I won't further search an option which does not exist then.

 

I'll use the reference lines instead.

 

RW9
Diamond | Level 26 RW9
Diamond | Level 26

My point was not to find zero, my point was about creating a label based on a data item, i.e. high or low, e.g. why is zero not mentioned.  The label should tell the user what is plotted on the axis, not what the value is representing, i.e. the label is Weight, the tick at the top states the high limit and low limit.

Anyway @JeffMeyers has given you an example.  you could also just plot those two labels you want at the point you  want them.  In fact more or less anything can be overlaid using GTL.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 7 replies
  • 2720 views
  • 0 likes
  • 3 in conversation