Hello Community,
While creating matrix plot using the option DIOGANAL=(histogram), tick values are disappearing . Trying to use GTL to modify the template, but don't see any available options in the tmplout-generated code or sas documentations. TEMPLATES with/out tick values don't differ.
Is there any SG or GTL option available for the MATRIX statement to display tick values even when using DIOGANAL=(histogram) option?
Please see the below examples.
1. Tick values displayed without DIOGANAL=(histogram) option.
proc sgscatter data=sashelp.iris tmplout='C:\Users\Desktop\matrix1.sas'; title "Scatterplot Matrix for Iris Data"; matrix sepallength petallength; run; title;
the tmplout created template is:
proc template;
define statgraph sgscatter;
begingraph / designwidth=640 designheight=640;
EntryTitle "Scatterplot Matrix for Iris Data" /;
layout lattice / pad=(top=5);
ScatterPlotMatrix SepalLength PetalLength / subpixel=off NAME="MATRIX";
endlayout;
endgraph;
end;
run;
2. Tick values disappeared with DIOGANAL=(histogram) option.
proc sgscatter data=sashelp.iris tmplout='C:\Users\Desktop\matrix2.sas'; title "Scatterplot Matrix for Iris Data"; matrix sepallength petallength/diagonal=(histogram); run; title;
the tmplout created template is:
proc template;
define statgraph sgscatter;
begingraph / designwidth=640 designheight=640 subpixel=on;
EntryTitle "Scatterplot Matrix for Iris Data" /;
layout lattice / pad=(top=5);
ScatterPlotMatrix SepalLength PetalLength / subpixel=off NAME="MATRIX" diagonal=( histogram );
endlayout;
endgraph;
end;
run;
OK. This one ?
/*Example 2*/
ods listing gpath="%sysfunc(pathname(work))" image_dpi=300 style=htmlblue;
ods graphics / reset=all imagename='sepallength' noborder width=77px height=77px;
ods html exclude sgplot;
/*generate a histogram graph*/
title;
proc sgplot data=sashelp.iris pad=0 noborder noautolegend;
histogram sepallength ;
xaxis display=none;
yaxis display=none;
run;
ods listing gpath="%sysfunc(pathname(work))" image_dpi=300 style=htmlblue;
ods graphics / reset=all imagename='petallength' noborder width=77px height=77px;
ods html exclude sgplot;
/*generate a histogram graph*/
title;
proc sgplot data=sashelp.iris pad=0 noborder noautolegend;
histogram petallength ;
xaxis display=none;
yaxis display=none;
run;
%sganno
data sganno;
%SGIMAGE(IMAGE="%sysfunc(pathname(work))\sepallength.png",ANCHOR="topleft",BORDER="FALSE",DRAWSPACE="LAYOUTPERCENT" ,x1=5,y1=94)
%SGIMAGE(IMAGE="%sysfunc(pathname(work))\petallength.png",ANCHOR="topleft",BORDER="FALSE",DRAWSPACE="LAYOUTPERCENT" ,x1=51,y1=48)
/*get rid of the tick markers around histogram*/
%SGRECTANGLE(X1=10,
Y1=91.9,
HEIGHT=2,
WIDTH=40,
ANCHOR="TOPLEFT" ,
DISPLAY="FILL" , /*DISPLAY="ALL"*/
DRAWSPACE="GRAPHPERCENT",
FILLCOLOR="white" ,
HEIGHTUNIT="PERCENT" ,
WIDTHUNIT="PERCENT"
)
%SGRECTANGLE(X1=8.1,
Y1=90,
HEIGHT=40,
WIDTH=2,
ANCHOR="TOPLEFT" ,
DISPLAY="FILL" , /*DISPLAY="ALL"*/
DRAWSPACE="GRAPHPERCENT",
FILLCOLOR="white" ,
HEIGHTUNIT="PERCENT" ,
WIDTHUNIT="PERCENT"
)
%SGRECTANGLE(X1=50,
Y1=10.2,
HEIGHT=2,
WIDTH=40,
ANCHOR="TOPLEFT" ,
DISPLAY="FILL" , /*DISPLAY="ALL"*/
DRAWSPACE="GRAPHPERCENT",
FILLCOLOR="white" ,
HEIGHTUNIT="PERCENT" ,
WIDTHUNIT="PERCENT"
)
%SGRECTANGLE(X1=89.8,
Y1=50,
HEIGHT=40,
WIDTH=2,
ANCHOR="TOPLEFT" ,
DISPLAY="FILL" , /*DISPLAY="ALL"*/
DRAWSPACE="GRAPHPERCENT",
FILLCOLOR="white" ,
HEIGHTUNIT="PERCENT" ,
WIDTHUNIT="PERCENT"
)
/*Add X an Y variable label*/
%SGTEXT(
LABEL="Sepal Length (mm)",
WIDTH=40,
WIDTHUNIT= "PERCENT" ,
ANCHOR="CENTER" ,
BORDER="FALSE",
DRAWSPACE="GRAPHPERCENT",
TEXTSIZE=12,
X1=30,
Y1=95
)
%SGTEXT(
LABEL="Petal Length (mm)",
WIDTH=40,
WIDTHUNIT= "PERCENT" ,
ANCHOR="CENTER" ,
BORDER="FALSE",
DRAWSPACE="GRAPHPERCENT",
TEXTSIZE=12,
X1=70,
Y1=95
)
%SGTEXT(
ROTATE=90,
LABEL="Sepal Length (mm)",
WIDTH=40,
WIDTHUNIT= "PERCENT" ,
ANCHOR="CENTER" ,
BORDER="FALSE",
DRAWSPACE="GRAPHPERCENT",
TEXTSIZE=12,
X1=4,
Y1=75
)
%SGTEXT(
ROTATE=90,
LABEL="Petal Length (mm)",
WIDTH=40,
WIDTHUNIT= "PERCENT" ,
ANCHOR="CENTER" ,
BORDER="FALSE",
DRAWSPACE="GRAPHPERCENT",
TEXTSIZE=12,
X1=4,
Y1=25
)
run;
ods graphics/reset;
title;
proc sgscatter data=sashelp.iris sganno=sganno pad=40px;
matrix sepallength petallength;
run;
Ksharp_0-1770451628779.png
Unfortunately, there is not a good way to achieve what you requested. The histograms have different axis ranges from the scatter plots, so the unified external row/column axes around the matrix cannot be created without negatively impacting the visual. The best you could do would be to create a Layout Lattice in GTL and, using internal axes, add the scatter plots and histograms in the desired order.
Thank you @DanH_sas, it's very helpful!
You want this ?
/*Example 1*/
ods listing gpath="%sysfunc(pathname(work))" image_dpi=300 style=htmlblue;
ods graphics / reset=all imagename='sepallength' noborder width=80px height=80px;
ods html exclude sgplot;
/*generate a histogram graph*/
title;
proc sgplot data=sashelp.iris pad=0 noborder noautolegend;
histogram sepallength ;
xaxis display=none;
yaxis display=none;
run;
ods listing gpath="%sysfunc(pathname(work))" image_dpi=300 style=htmlblue;
ods graphics / reset=all imagename='petallength' noborder width=80px height=80px;
ods html exclude sgplot;
/*generate a histogram graph*/
title;
proc sgplot data=sashelp.iris pad=0 noborder noautolegend;
histogram petallength ;
xaxis display=none;
yaxis display=none;
run;
%sganno
data sganno;
%SGIMAGE(IMAGE="%sysfunc(pathname(work))\sepallength.png",ANCHOR="topleft",BORDER="FALSE",DRAWSPACE="LAYOUTPERCENT" ,x1=6,y1=93)
%SGIMAGE(IMAGE="%sysfunc(pathname(work))\petallength.png",ANCHOR="topleft",BORDER="FALSE",DRAWSPACE="LAYOUTPERCENT" ,x1=54,y1=48)
run;
ods graphics/reset;
proc sgscatter data=sashelp.iris sganno=sganno;
title "Scatterplot Matrix for Iris Data";
matrix sepallength petallength;
run;
Ksharp_0-1770371187829.png
Hi @Ksharp ,
Thank you for the code, yes this looks like what I needed. Could we drop tick markers around histograms and add labels in the x- and y-axis, like in the example plot below? SGScatter.png
OK. This one ?
/*Example 2*/
ods listing gpath="%sysfunc(pathname(work))" image_dpi=300 style=htmlblue;
ods graphics / reset=all imagename='sepallength' noborder width=77px height=77px;
ods html exclude sgplot;
/*generate a histogram graph*/
title;
proc sgplot data=sashelp.iris pad=0 noborder noautolegend;
histogram sepallength ;
xaxis display=none;
yaxis display=none;
run;
ods listing gpath="%sysfunc(pathname(work))" image_dpi=300 style=htmlblue;
ods graphics / reset=all imagename='petallength' noborder width=77px height=77px;
ods html exclude sgplot;
/*generate a histogram graph*/
title;
proc sgplot data=sashelp.iris pad=0 noborder noautolegend;
histogram petallength ;
xaxis display=none;
yaxis display=none;
run;
%sganno
data sganno;
%SGIMAGE(IMAGE="%sysfunc(pathname(work))\sepallength.png",ANCHOR="topleft",BORDER="FALSE",DRAWSPACE="LAYOUTPERCENT" ,x1=5,y1=94)
%SGIMAGE(IMAGE="%sysfunc(pathname(work))\petallength.png",ANCHOR="topleft",BORDER="FALSE",DRAWSPACE="LAYOUTPERCENT" ,x1=51,y1=48)
/*get rid of the tick markers around histogram*/
%SGRECTANGLE(X1=10,
Y1=91.9,
HEIGHT=2,
WIDTH=40,
ANCHOR="TOPLEFT" ,
DISPLAY="FILL" , /*DISPLAY="ALL"*/
DRAWSPACE="GRAPHPERCENT",
FILLCOLOR="white" ,
HEIGHTUNIT="PERCENT" ,
WIDTHUNIT="PERCENT"
)
%SGRECTANGLE(X1=8.1,
Y1=90,
HEIGHT=40,
WIDTH=2,
ANCHOR="TOPLEFT" ,
DISPLAY="FILL" , /*DISPLAY="ALL"*/
DRAWSPACE="GRAPHPERCENT",
FILLCOLOR="white" ,
HEIGHTUNIT="PERCENT" ,
WIDTHUNIT="PERCENT"
)
%SGRECTANGLE(X1=50,
Y1=10.2,
HEIGHT=2,
WIDTH=40,
ANCHOR="TOPLEFT" ,
DISPLAY="FILL" , /*DISPLAY="ALL"*/
DRAWSPACE="GRAPHPERCENT",
FILLCOLOR="white" ,
HEIGHTUNIT="PERCENT" ,
WIDTHUNIT="PERCENT"
)
%SGRECTANGLE(X1=89.8,
Y1=50,
HEIGHT=40,
WIDTH=2,
ANCHOR="TOPLEFT" ,
DISPLAY="FILL" , /*DISPLAY="ALL"*/
DRAWSPACE="GRAPHPERCENT",
FILLCOLOR="white" ,
HEIGHTUNIT="PERCENT" ,
WIDTHUNIT="PERCENT"
)
/*Add X an Y variable label*/
%SGTEXT(
LABEL="Sepal Length (mm)",
WIDTH=40,
WIDTHUNIT= "PERCENT" ,
ANCHOR="CENTER" ,
BORDER="FALSE",
DRAWSPACE="GRAPHPERCENT",
TEXTSIZE=12,
X1=30,
Y1=95
)
%SGTEXT(
LABEL="Petal Length (mm)",
WIDTH=40,
WIDTHUNIT= "PERCENT" ,
ANCHOR="CENTER" ,
BORDER="FALSE",
DRAWSPACE="GRAPHPERCENT",
TEXTSIZE=12,
X1=70,
Y1=95
)
%SGTEXT(
ROTATE=90,
LABEL="Sepal Length (mm)",
WIDTH=40,
WIDTHUNIT= "PERCENT" ,
ANCHOR="CENTER" ,
BORDER="FALSE",
DRAWSPACE="GRAPHPERCENT",
TEXTSIZE=12,
X1=4,
Y1=75
)
%SGTEXT(
ROTATE=90,
LABEL="Petal Length (mm)",
WIDTH=40,
WIDTHUNIT= "PERCENT" ,
ANCHOR="CENTER" ,
BORDER="FALSE",
DRAWSPACE="GRAPHPERCENT",
TEXTSIZE=12,
X1=4,
Y1=25
)
run;
ods graphics/reset;
title;
proc sgscatter data=sashelp.iris sganno=sganno pad=40px;
matrix sepallength petallength;
run;
Ksharp_0-1770451628779.png
Thank you, @Ksharp , whith you nothing seems impossible in SAS 🙂
CFC_SAS_Communities_400x225.jpg
It's your turn to help shape SAS Innovate 2027. Share your expertise and inspire the SAS community.
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.