Hello,
I am trying to use sgpanel to panel scatter & regerssions plots of various soil parameters (y-variables) agains total carbon (x-axis) by depth (3 depths). I can easily accomodate one y-variale (e.g., total N%, see below). But I'd like to have multiple y-variables (N%, C%, C:N, etc.)... can I do this in sgpanel? If not is there a way to do it in sgplot?
proc sgpanel
data=SOCnet_T2_2022
description=" " noautolegend;
panelby depth / columns=3;
styleattrs
datacolors=(CX0072B2 CX56B4E9 CX009E73 CXF0E442)
datasymbols=(triangle trianglefilled square squarefilled);
colaxis label="Total Carbon (ton/ac)" labelattrs=(color=black size=12pt weight=bold);
rowaxis label="Total Nitrogen (%)" labelattrs=(color=black size=12pt weight=bold);
scatter x=TC_tonac y=N_pct;
reg x=TC_tonac y=N_pct/cli clm nomarkers;
run;
I would like to creat something that looks like this...
You can do this with SGPANEL, but you will need to transform your data a bit. Your three Y axis columns will need to be transposed, such that all Y values are in a single column, with all values in-line with a new column (let's call it "yType") that contains the current Y axis label values ("Total Nitrogen (%)", "Total Carbon (%)", "C:N Ratio"). Then, on the PANELBY statement, set LAYOUT=LATTICE and add the "yType" variable after your "depth" variable. You will also need to set UNISCALE=COLUMN on the PANELBY statement so that each Y axis will be independently scaled.
Let me know if you have any more questions about this technique.
DanH, this is fantastic and worked great (see below). I have two follow up questions.
1. Is it possible to custom format the row/column headers? For example. I'd like to remove detph= from the columns, and change the rows to C %, Bulk Density (g/cc), and OM %. The only way I've thought to do this is supress them entirely and use an annotate dataset...
2. Is it possible to have 3 distinct y-axis labels on the left side of the graph as oppose to the column headers at the right?
Really appreciate your help with this. Code and image below.
proc sgpanel
data=C_2022
description=" " noautolegend;
panelby depth resp / columns=3 layout=lattice uniscale=column;
styleattrs
datacolors=(CX0072B2 CX56B4E9 CX009E73 CXF0E442)
datasymbols=(triangle trianglefilled square squarefilled);
scatter x=TC_tonac y=COL1/group=order;
reg x=TC_tonac y=COL1 / nomarkers degree=1;
rowaxis label=" ";
colaxis label="Total Carbon (ton/ac)" labelattrs=(color=black size=12pt weight=bold);
keylegend / title="Soil Orders" exclude=('95% Confidence Limits' '95% Prediction Limits' 'Regression') noborder ;
run;
For #1, use the NOVARNAME option on the PANELBY statement to drop the left-side labels (e.g. depth=). For your custom row values, create a user-defined format and set it on the SGPANEL procedure using the FORMAT statement: FORMAT resp myfmt.;
For #2, set ROWHEADERPOS=LEFT on the PANELBY statement. You might also want to set NOHEADERBORDER and HEADERBACKCOLOR to make the labels appear more like axis labels.
Hope this helps!
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
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.