introduction to the sgplot procedure - uncw …people.uncw.edu/blumj/stt592/ppt/introduction to the...
TRANSCRIPT
Introduction to the
SGPLOT Procedure
SAS SG Procedures
SG refers to “Statistical Graphics” and is an offshoot of
the recent introduction of special ODS graphics to
SAS/STAT procedures.
They may be better thought of as “template-based”
graphics procedures as opposed to “device-based”
procedures like GPLOT and GCHART.
In fact, the SG procedures can be thought of as
alternate ways to use various graph templates—results
can be duplicated with PROC TEMPLATE and PROC
SGRENDER.
SG procedures deliver directly to a specific graphics file
format (png by default), rather than to a SAS window.
SGPLOT
SGPLOT allows for an extensive collection of graphs (and
associated options to be selected).
Some choices:
Distributional
proc sgplot data=mysas.fish;
histogram hg;
where hg lt 2;
run;
quit;
SGPLOT
SGPLOT allows for an extensive collection of graphs (and
associated options to be selected).
Some choices:
Distributional
proc sgplot data=mysas.fish;
histogram hg;
where hg lt 2;
run;
quit;
Histogram Options
dataskin=
proc sgplot data=mysas.fish;
histogram hg/dataskin=pressed;
where hg lt 2;
run;
quit;
Histogram Options
dataskin=
proc sgplot data=mysas.fish;
histogram hg/dataskin=pressed;
where hg lt 2;
run;
quit;
Histogram Options
dataskin=
proc sgplot data=mysas.fish;
histogram hg/dataskin=pressed;
where hg lt 2;
run;
quit;
Options include: None,
Crisp, Gloss, Matte,
Pressed and Sheen
Histogram Options
Bin options: binstart=,binwidth=
proc sgplot data=mysas.fish;
histogram hg/binstart=0 binwidth=0.2;
where hg lt 2;
run;
quit;
Histogram Options
Bin options: binstart=,binwidth=
proc sgplot data=mysas.fish;
histogram hg/binstart=0 binwidth=0.2;
where hg lt 2;
run;
quit;
Histogram Options
Bin options: nbins=
proc sgplot data=mysas.fish;
histogram hg/nbins=6;
where hg lt 2;
run;
quit;
Histogram Options
Bin options: nbins=
proc sgplot data=mysas.fish;
histogram hg/nbins=6;
where hg lt 2;
run;
quit;
Histogram Options
Vertical Scale: Scale=
proc sgplot data=mysas.fish;
histogram hg/scale=count;
where hg lt 2;
run;
quit;
Histogram Options
Vertical Scale: Scale=
proc sgplot data=mysas.fish;
histogram hg/scale=count;
where hg lt 2;
run;
quit;
Histogram Options
Vertical Scale: Scale=
proc sgplot data=mysas.fish;
histogram hg/scale=count;
where hg lt 2;
run;
quit;
Percent is the default,
proportion is also available.
Other Distributional Graphs
density statement
proc sgplot data=mysas.fish;
density hg;
where hg lt 2;
run;
quit;
Other Distributional Graphs
density statement
proc sgplot data=mysas.fish;
density hg;
where hg lt 2;
run;
quit;
Other Distributional Graphs
density statement
proc sgplot data=mysas.fish;
density hg;
where hg lt 2;
run;
quit;
Normal is the default,
parameters are estimated
from the data.
Other Distributional Graphs
type= allows you to change to kernel estimate
proc sgplot data=mysas.fish;
density hg/type=kernel;
where hg lt 2;
run;
quit;
Other Distributional Graphs
type= allows you to change to kernel estimate
proc sgplot data=mysas.fish;
density hg/type=kernel;
where hg lt 2;
run;
quit;
Other Distributional Graphs
type= allows you to change to kernel estimate
proc sgplot data=mysas.fish;
density hg/type=kernel;
where hg lt 2;
run;
quit;
Both Normal and Kernel
allow for additional options.
Combining Graphs
SGPLOT allows multiple graphs to be selected and, by default,
works in layers.
Try:
proc sgplot data=mysas.fish;
histogram hg/dataskin=sheen;
density hg;
density hg/type=kernel;
where hg lt 2;
run;
quit;
Combining Graphs
proc sgplot data=mysas.fish;
histogram hg/dataskin=sheen;
density hg;
density hg/type=kernel;
where hg lt 2;
run;
quit;
Order Matters
proc sgplot data=mysas.fish;
density hg;
histogram hg/dataskin=sheen;
density hg/type=kernel;
where hg lt 2;
run;
quit;
Order Matters
proc sgplot data=mysas.fish;
density hg;
histogram hg/dataskin=sheen;
density hg/type=kernel;
where hg lt 2;
run;
quit;
This is drawn first,
behind/under the histogram.
Combining Graphs—Useful Options
Some SGPLOT statements control styles of various graph elements
through various options.
Try:
proc sgplot data=mysas.fish;
histogram hg/dataskin=sheen;
density hg;
density hg/type=kernel;
keylegend / location=inside position=topleft
across=1 title='Density Type'
titleattrs=(family='Arial Black' color=blue);
where hg lt 2;
run;
quit;
Combining Graphs—Useful Options
keylegend / location=inside position=topleft
across=1 title='Density Type'
titleattrs=(family='Arial Black' color=blue);
Combining Graphs—Useful Options
keylegend / location=inside position=topleft
across=1 title='Density Type'
titleattrs=(family='Arial Black' color=blue);
Chooses where the
legend is displayed
Combining Graphs—Useful Options
keylegend / location=inside position=topleft
across=1 title='Density Type'
titleattrs=(family='Arial Black' color=blue);
Can specify across or down to
set number of rows or columns.
You should pick one or the other.
Combining Graphs—Useful Options
keylegend / location=inside position=topleft
across=1 title='Density Type'
titleattrs=(family='Arial Black' color=blue);
Can create a title for
your legend.
Combining Graphs—Useful Options
keylegend / location=inside position=topleft
across=1 title='Density Type'
titleattrs=(family='Arial Black' color=blue);
Attributes can be set for
various character
elements like the title.
Several “attrs” (attributes) options will
be available.
A Few Other Useful Statements & Options
Axes can be altered with specific SGPLOT statements and options.
xaxis:
proc sgplot data=mysas.fish;
histogram hg/dataskin=sheen;
density hg;
density hg/type=kernel;
keylegend / location=inside position=topleft
across=1 title='Density Type'
titleattrs=(family='Arial Black' color=blue);
xaxis minor minorcount=2 offsetmin=0
valueattrs=(family='Georgia' color=cx5555FF size=12pt);
where hg lt 2;
run;
quit;
A Few Other Useful Statements & Options
xaxis minor minorcount=2 offsetmin=0
valueattrs=(family='Georgia' color=cx5555FF size=12pt);
A Few Other Useful Statements & Options
xaxis minor minorcount=2 offsetmin=0
valueattrs=(family='Georgia' color=cx5555FF size=12pt);
Establish the presence of
minor ticks and how many
appear between major ticks
A Few Other Useful Statements & Options
xaxis minor minorcount=2 offsetmin=0
valueattrs=(family='Georgia' color=cx5555FF size=12pt);
Distance from axis to lowest
major tick. Must be between 0
and 1, taken as a proportion of
available space
offsetmax= is also
available
A Few Other Useful Statements & Options
xaxis minor minorcount=2 offsetmin=0
valueattrs=(family='Georgia' color=cx5555FF size=12pt);
Another “attrs” option, this controls
the value text—values at major ticks.
A Few Other Useful Statements & Options
yaxis, too:
proc sgplot data=mysas.fish;
histogram hg/dataskin=sheen scale=proportion;
density hg;
density hg/type=kernel;
keylegend / location=inside position=topleft
across=1 title='Density Type'
titleattrs=(family='Arial Black' color=blue);
xaxis minor minorcount=2 offsetmin=0
valueattrs=(family='Georgia' color=cx5555FF size=12pt);
yaxis offsetmax=0 values=(0 to .25 by 0.025) valuesformat=percent8.1
display=(nolabel);
where hg lt 2;
run;
quit;
This change will be
applied to the y-axis for all
three overlayed figures
A Few Other Useful Statements & Options
yaxis offsetmax=0 values=(0 to .25 by 0.025) valuesformat=percent8.1
display=(nolabel);
Value range can be set—
these are now decimals
A Few Other Useful Statements & Options
yaxis offsetmax=0 values=(0 to .25 by 0.025) valuesformat=percent8.1
display=(nolabel);
But a format for them can
be chosen (like percent).
A Few Other Useful Statements & Options
yaxis offsetmax=0 values=(0 to .25 by 0.025) valuesformat=percent8.1
display=(nolabel);
So that axis label is no
longer necessary.
Exercises
Using the projects data set, see if you can make this overlay (some
new options for density and histogram, no other statements yet).
Exercises
Now work on the axes a bit.
Exercises
And a little more…