BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
BruceBrad
Lapis Lazuli | Level 10

I'm creating a scatterplot using sgplot. My points have both positive and negative values. I would like to draw two axes through (0,0), but keep the axis labels at the edge of the graph. What's the best way to do this? (I know I can use lineparm, but I'm hoping there is a simpler option).

1 ACCEPTED SOLUTION

Accepted Solutions
Rick_SAS
SAS Super FREQ
REFLINE 0 / axis=x;

REFLINE 0 / axis=y;



That draws the reference lines, but leaves the axes automatically positioned.


View solution in original post

5 REPLIES 5
Rick_SAS
SAS Super FREQ
REFLINE 0 / axis=x;

REFLINE 0 / axis=y;



That draws the reference lines, but leaves the axes automatically positioned.


BruceBrad
Lapis Lazuli | Level 10

Many thanks. That solves my current problem. For future reference (if I want to present this data differently) how do I get the axes with tickmarks and labels to go through (0,0)?

Rick_SAS
SAS Super FREQ

I'll let someone else advice as to how it might be accomplished.  In my opinion, you shouldn't do it. The center of the plot should be reserved for the data, with the axis ticks, values, and labels positioned to the outside. This is based on basic principles of graphing (a la Tufte) which state that the data should be presented as purely and unadorned as possible.

Rick_SAS
SAS Super FREQ

Another thought: To obtain a whole grid of reference lines, where each line is aligned with axes ticks, use the GRID option on the XAXIS and YAXIS statements, like this:

 

xaxis grid;
yaxis grid;

That gives you all of the advantages of axes that cut through the plot area, but keeps the tick values and labels on the outside of the plot area.

 

Jay54
Meteorite | Level 14

I don't think there is a way to do this in SGPLOT.  However, you can do this using GTL.

In your case, your data would span across (0, 0), and you would set the x and y origins at zero.

 

Axis_Origin.png

 

proc template;
  define statgraph class;
    begingraph;
      entrytitle 'Weight by Height for all Students';
      layout overlay / xaxisopts=(linearopts=(origin=60))
                               yaxisopts=(linearopts=(origin=100));
        scatterplot x=height y=weight / group=sex name='a';
        discretelegend 'a';
      endlayout;
    endgraph;
  end;
run;


proc sgrender data=sashelp.class template=class;
run;

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 5 replies
  • 2297 views
  • 1 like
  • 3 in conversation