BookmarkSubscribeRSS Feed
grsanford
Fluorite | Level 6

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;

Picture2.jpg

 

I would like to creat something that looks like this... 

 

Picture2.png

3 REPLIES 3
DanH_sas
SAS Super FREQ

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.

grsanford
Fluorite | Level 6

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. Picture1.jpg

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;
DanH_sas
SAS Super FREQ

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!

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 3 replies
  • 375 views
  • 3 likes
  • 2 in conversation