Data visualization with SAS programming

how can I get the x and y axes equal in length?

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 5
Accepted Solution

how can I get the x and y axes equal in length?

Hi - I am trying to produce scatter plots (4 per page in a PDF file) such that they are "square" rather than "rectangular" in shape (i.e. the x-axis is equal in length to the y-axis).  How can I make SAS do this (version 9.4) ?  Below is an example of the code for the 1st graph that appears in the top left corner of the page.

ODS PDF FILE="F:\graphs1_4.pdf";

ods layout start;

ods region x=0.25 in y=1.5 in width=3.75 in height=3.75 in;

proc sgplot data=cpet15 noautolegend;

  xaxis label="Time (min)";

  yaxis label="VE (L/min)";

  scatter x=t15_c_min y=ex_ve / MARKERATTRS= (symbol=circlefilled color=black size=3pt);

  scatter x=t15_c_min y=noex_ve / MARKERATTRS= (symbol=circle color=black size=3pt);

run;

ods layout end;

ods pdf close;

ods listing;


Accepted Solutions
Solution
‎07-10-2015 02:13 PM
Respected Advisor
Posts: 4,606

Re: how can I get the x and y axes equal in length?

Look at the ASPECT= option in PROC SGPLOT.

PG

PG

View solution in original post


All Replies
Solution
‎07-10-2015 02:13 PM
Respected Advisor
Posts: 4,606

Re: how can I get the x and y axes equal in length?

Look at the ASPECT= option in PROC SGPLOT.

PG

PG
SAS Super FREQ
Posts: 1,040

Re: how can I get the x and y axes equal in length?

The way to get a "real" equated plot is to use the GTL LayoutEquated container.  This will give you a graph where the mapping of the data to pixels on x and y axis are equal.  This is not hard.  Here is the code.

proc template;

  define statgraph equated;

    begingraph;

      entrytitle 'Blood Pressure';

     layout overlayequated / xaxisopts=(griddisplay=on)

                                        yaxisopts=(griddisplay=on);

     scatterplot x=systolic y=diastolic;

   endlayout;

  endgraph;

  end;

run;

proc sgrender data=sashelp.heart template=equated;

run;

A "poor man's" Equated plot can be obtained by using ASPECT option on SGPLOT procedure.  Note, this only makes the wall of equal size, but the actual pixel to data mapping may not be exactly equal.

proc sgplot data=sashelp.heart aspect=1;

  scatter x=systolic y=diastolic;

  xaxis grid;

  yaxis grid;

  run;

Notice in the first (GTL) graph, the axis tick interval is equal (50 units) on both axes and the number of pixels per grid is equal. 

In the second graph (SG), the wall is square, but the data spans about 200 units along x and about 100 units about Y.  The tick intervals are not equal.

Respected Advisor
Posts: 4,606

Re: how can I get the x and y axes equal in length?

I beg to differ. It is "not hard" ONCE you master proc template! How many days of work does that take? And anyone revising your work in the future will also need to spend that learning time.

Unless I am looking for something exotic, and a square graph area isn't that, I don't want to get into a new language layer.

PG

PG
SAS Super FREQ
Posts: 1,040

Re: how can I get the x and y axes equal in length?

It is perfectly reasonable to stay with the code you know.  As long as we understand that a plot with a square wall (equal X & Y axes lengths in pixels) is not same as an "Equated Plot".  An "Equated Plot" has the same mapping of data to pixels on both axes.  This ensures that an overlaid lineparm with slope=1,will display at 45 degrees.   Actual length of the axis need not be equal.

If what you want is an Equated Plot, you can approximate it with SGPLOT, as long as you ensure the data range on each axis is also in the same ratio as the ASPECT.  You should also watch out for axis offsets that are automatically set by the axis based on plot types.

Occasional Contributor
Posts: 5

Re: how can I get the x and y axes equal in length?

Hi - thanks so much for your help!  I was so set on making the graph "square" in the layout that I never even considered going back to the procedure to do it.  As it turns out, I am producing a number of graphs in this way, but the axes are never measured on the same scale, so the best solution for me is to use aspect=1 in the proc sgplot.  This worked like a charm for my situation & I really appreciate the discussion!!

Post a Question
Discussion Stats
  • 5 replies
  • 772 views
  • 6 likes
  • 3 in conversation