Hi All,
If I use SGplot to make a plot with two different Y-axes, I love that I can use offsetmax and offsetmin to create distinct areas for each plot, rather than overlay them.
data have ;
do time= 1 to 10 ;
y1=rand('normal',0,1) ;
y2=rand('normal',100,10) ;
y3=rand('normal',1000,100) ;
output;
end;
run ;
proc sgplot data=have ;
yaxis
offsetmax=0.6 /*bottom 40%*/
labelpos=DataCenter
;
y2axis
offsetmin=0.6 /*top 40%*/
labelpos=DataCenter
;
series x=time y=y1 ;
series x=time y=y2 /y2axis ;
run ;
Which returns:
Now I'm in the situation where I want to do the same thing, with 3 zones. So I have Y1, Y2, Y3, which are all different attributes measured in different units, and I want a single plot with a shared time axis which shows how they all vary over time. So like above, but with three zones (and ideally I'd like to control the height of each zone).
Is this possible with SGPLOT? (I think no).
If not, I'm guessing it is possible if I get back into GTL, using layout lattice (maybe), and layout overlay to define each of the three plots?
Thanks,
-Q.
A simpler way is to use SGPANEL procedure. Mark the observations with three different classification values, say 1, 2, 3 in a column named 'Axis' or something. Then use PANELBY=axis, with COLUMNS=1 or LAYOUT=ROWLATTICE.
A simpler way is to use SGPANEL procedure. Mark the observations with three different classification values, say 1, 2, 3 in a column named 'Axis' or something. Then use PANELBY=axis, with COLUMNS=1 or LAYOUT=ROWLATTICE.
Thanks @Jay54 , that makes sense. I had thought briefly about SGPANEL, but dismissed it too quickly without realizing I could just transpose my data to create a categorical variable to PanelBy. Will give it a try.
So glad to see you're still contributing on here!
Well, if I had just checked the example on p264 of your red book where you show vital signs (BP, pulse, temp) by time, that's pretty much what I was looking for... Thanks again.
proc transpose data=have out=want ;
by time ;
run ;
proc sgpanel data=want ;
panelby _name_ /layout=rowlattice onepanel novarname uniscale=column;
series x=time y=col1 ;
rowaxis display=(nolabel) ;
run ;
I still might end up delving into GTL to be able to dictate the size of each panel. But definitely good to keep SGPANEL in mind.
Catch the best of SAS Innovate 2025 — anytime, anywhere. Stream powerful keynotes, real-world demos, and game-changing insights from the world’s leading data and AI minds.
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.
Ready to level-up your skills? Choose your own adventure.