07-10-2015 01:59 PM
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);
ods layout end;
ods pdf close;
07-10-2015 02:18 PM
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.
define statgraph equated;
entrytitle 'Blood Pressure';
layout overlayequated / xaxisopts=(griddisplay=on)
scatterplot x=systolic y=diastolic;
proc sgrender data=sashelp.heart template=equated;
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;
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.
07-10-2015 02:52 PM
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.
07-10-2015 03:18 PM
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.
07-11-2015 10:17 PM
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!!
Need further help from the community? Please ask a new question.