introduction to the sgplot procedure - uncw …people.uncw.edu/blumj/stt592/ppt/introduction to the...

42
Introduction to the SGPLOT Procedure

Upload: lamdiep

Post on 01-Sep-2018

225 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Introduction to the SGPLOT Procedure - UNCW …people.uncw.edu/blumj/stt592/ppt/Introduction to the SGPLOT... · Introduction to the SGPLOT Procedure. ... the recent introduction

Introduction to the

SGPLOT Procedure

Page 2: Introduction to the SGPLOT Procedure - UNCW …people.uncw.edu/blumj/stt592/ppt/Introduction to the SGPLOT... · Introduction to the SGPLOT Procedure. ... the recent introduction

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.

Page 3: Introduction to the SGPLOT Procedure - UNCW …people.uncw.edu/blumj/stt592/ppt/Introduction to the SGPLOT... · Introduction to the SGPLOT Procedure. ... the recent introduction

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;

Page 4: Introduction to the SGPLOT Procedure - UNCW …people.uncw.edu/blumj/stt592/ppt/Introduction to the SGPLOT... · Introduction to the SGPLOT Procedure. ... the recent introduction

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;

Page 5: Introduction to the SGPLOT Procedure - UNCW …people.uncw.edu/blumj/stt592/ppt/Introduction to the SGPLOT... · Introduction to the SGPLOT Procedure. ... the recent introduction

Histogram Options

dataskin=

proc sgplot data=mysas.fish;

histogram hg/dataskin=pressed;

where hg lt 2;

run;

quit;

Page 6: Introduction to the SGPLOT Procedure - UNCW …people.uncw.edu/blumj/stt592/ppt/Introduction to the SGPLOT... · Introduction to the SGPLOT Procedure. ... the recent introduction

Histogram Options

dataskin=

proc sgplot data=mysas.fish;

histogram hg/dataskin=pressed;

where hg lt 2;

run;

quit;

Page 7: Introduction to the SGPLOT Procedure - UNCW …people.uncw.edu/blumj/stt592/ppt/Introduction to the SGPLOT... · Introduction to the SGPLOT Procedure. ... the recent introduction

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

Page 8: Introduction to the SGPLOT Procedure - UNCW …people.uncw.edu/blumj/stt592/ppt/Introduction to the SGPLOT... · Introduction to the SGPLOT Procedure. ... the recent introduction

Histogram Options

Bin options: binstart=,binwidth=

proc sgplot data=mysas.fish;

histogram hg/binstart=0 binwidth=0.2;

where hg lt 2;

run;

quit;

Page 9: Introduction to the SGPLOT Procedure - UNCW …people.uncw.edu/blumj/stt592/ppt/Introduction to the SGPLOT... · Introduction to the SGPLOT Procedure. ... the recent introduction

Histogram Options

Bin options: binstart=,binwidth=

proc sgplot data=mysas.fish;

histogram hg/binstart=0 binwidth=0.2;

where hg lt 2;

run;

quit;

Page 10: Introduction to the SGPLOT Procedure - UNCW …people.uncw.edu/blumj/stt592/ppt/Introduction to the SGPLOT... · Introduction to the SGPLOT Procedure. ... the recent introduction

Histogram Options

Bin options: nbins=

proc sgplot data=mysas.fish;

histogram hg/nbins=6;

where hg lt 2;

run;

quit;

Page 11: Introduction to the SGPLOT Procedure - UNCW …people.uncw.edu/blumj/stt592/ppt/Introduction to the SGPLOT... · Introduction to the SGPLOT Procedure. ... the recent introduction

Histogram Options

Bin options: nbins=

proc sgplot data=mysas.fish;

histogram hg/nbins=6;

where hg lt 2;

run;

quit;

Page 12: Introduction to the SGPLOT Procedure - UNCW …people.uncw.edu/blumj/stt592/ppt/Introduction to the SGPLOT... · Introduction to the SGPLOT Procedure. ... the recent introduction

Histogram Options

Vertical Scale: Scale=

proc sgplot data=mysas.fish;

histogram hg/scale=count;

where hg lt 2;

run;

quit;

Page 13: Introduction to the SGPLOT Procedure - UNCW …people.uncw.edu/blumj/stt592/ppt/Introduction to the SGPLOT... · Introduction to the SGPLOT Procedure. ... the recent introduction

Histogram Options

Vertical Scale: Scale=

proc sgplot data=mysas.fish;

histogram hg/scale=count;

where hg lt 2;

run;

quit;

Page 14: Introduction to the SGPLOT Procedure - UNCW …people.uncw.edu/blumj/stt592/ppt/Introduction to the SGPLOT... · Introduction to the SGPLOT Procedure. ... the recent introduction

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.

Page 15: Introduction to the SGPLOT Procedure - UNCW …people.uncw.edu/blumj/stt592/ppt/Introduction to the SGPLOT... · Introduction to the SGPLOT Procedure. ... the recent introduction

Other Distributional Graphs

density statement

proc sgplot data=mysas.fish;

density hg;

where hg lt 2;

run;

quit;

Page 16: Introduction to the SGPLOT Procedure - UNCW …people.uncw.edu/blumj/stt592/ppt/Introduction to the SGPLOT... · Introduction to the SGPLOT Procedure. ... the recent introduction

Other Distributional Graphs

density statement

proc sgplot data=mysas.fish;

density hg;

where hg lt 2;

run;

quit;

Page 17: Introduction to the SGPLOT Procedure - UNCW …people.uncw.edu/blumj/stt592/ppt/Introduction to the SGPLOT... · Introduction to the SGPLOT Procedure. ... the recent introduction

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.

Page 18: Introduction to the SGPLOT Procedure - UNCW …people.uncw.edu/blumj/stt592/ppt/Introduction to the SGPLOT... · Introduction to the SGPLOT Procedure. ... the recent introduction

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;

Page 19: Introduction to the SGPLOT Procedure - UNCW …people.uncw.edu/blumj/stt592/ppt/Introduction to the SGPLOT... · Introduction to the SGPLOT Procedure. ... the recent introduction

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;

Page 20: Introduction to the SGPLOT Procedure - UNCW …people.uncw.edu/blumj/stt592/ppt/Introduction to the SGPLOT... · Introduction to the SGPLOT Procedure. ... the recent introduction

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.

Page 21: Introduction to the SGPLOT Procedure - UNCW …people.uncw.edu/blumj/stt592/ppt/Introduction to the SGPLOT... · Introduction to the SGPLOT Procedure. ... the recent introduction

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;

Page 22: Introduction to the SGPLOT Procedure - UNCW …people.uncw.edu/blumj/stt592/ppt/Introduction to the SGPLOT... · Introduction to the SGPLOT Procedure. ... the recent introduction

Combining Graphs

proc sgplot data=mysas.fish;

histogram hg/dataskin=sheen;

density hg;

density hg/type=kernel;

where hg lt 2;

run;

quit;

Page 23: Introduction to the SGPLOT Procedure - UNCW …people.uncw.edu/blumj/stt592/ppt/Introduction to the SGPLOT... · Introduction to the SGPLOT Procedure. ... the recent introduction

Order Matters

proc sgplot data=mysas.fish;

density hg;

histogram hg/dataskin=sheen;

density hg/type=kernel;

where hg lt 2;

run;

quit;

Page 24: Introduction to the SGPLOT Procedure - UNCW …people.uncw.edu/blumj/stt592/ppt/Introduction to the SGPLOT... · Introduction to the SGPLOT Procedure. ... the recent introduction

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.

Page 25: Introduction to the SGPLOT Procedure - UNCW …people.uncw.edu/blumj/stt592/ppt/Introduction to the SGPLOT... · Introduction to the SGPLOT Procedure. ... the recent introduction

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;

Page 26: Introduction to the SGPLOT Procedure - UNCW …people.uncw.edu/blumj/stt592/ppt/Introduction to the SGPLOT... · Introduction to the SGPLOT Procedure. ... the recent introduction

Combining Graphs—Useful Options

keylegend / location=inside position=topleft

across=1 title='Density Type'

titleattrs=(family='Arial Black' color=blue);

Page 27: Introduction to the SGPLOT Procedure - UNCW …people.uncw.edu/blumj/stt592/ppt/Introduction to the SGPLOT... · Introduction to the SGPLOT Procedure. ... the recent introduction

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

Page 28: Introduction to the SGPLOT Procedure - UNCW …people.uncw.edu/blumj/stt592/ppt/Introduction to the SGPLOT... · Introduction to the SGPLOT Procedure. ... the recent introduction

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.

Page 29: Introduction to the SGPLOT Procedure - UNCW …people.uncw.edu/blumj/stt592/ppt/Introduction to the SGPLOT... · Introduction to the SGPLOT Procedure. ... the recent introduction

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.

Page 30: Introduction to the SGPLOT Procedure - UNCW …people.uncw.edu/blumj/stt592/ppt/Introduction to the SGPLOT... · Introduction to the SGPLOT Procedure. ... the recent introduction

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.

Page 31: Introduction to the SGPLOT Procedure - UNCW …people.uncw.edu/blumj/stt592/ppt/Introduction to the SGPLOT... · Introduction to the SGPLOT Procedure. ... the recent introduction

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;

Page 32: Introduction to the SGPLOT Procedure - UNCW …people.uncw.edu/blumj/stt592/ppt/Introduction to the SGPLOT... · Introduction to the SGPLOT Procedure. ... the recent introduction

A Few Other Useful Statements & Options

xaxis minor minorcount=2 offsetmin=0

valueattrs=(family='Georgia' color=cx5555FF size=12pt);

Page 33: Introduction to the SGPLOT Procedure - UNCW …people.uncw.edu/blumj/stt592/ppt/Introduction to the SGPLOT... · Introduction to the SGPLOT Procedure. ... the recent introduction

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

Page 34: Introduction to the SGPLOT Procedure - UNCW …people.uncw.edu/blumj/stt592/ppt/Introduction to the SGPLOT... · Introduction to the SGPLOT Procedure. ... the recent introduction

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

Page 35: Introduction to the SGPLOT Procedure - UNCW …people.uncw.edu/blumj/stt592/ppt/Introduction to the SGPLOT... · Introduction to the SGPLOT Procedure. ... the recent introduction

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.

Page 36: Introduction to the SGPLOT Procedure - UNCW …people.uncw.edu/blumj/stt592/ppt/Introduction to the SGPLOT... · Introduction to the SGPLOT Procedure. ... the recent introduction

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

Page 37: Introduction to the SGPLOT Procedure - UNCW …people.uncw.edu/blumj/stt592/ppt/Introduction to the SGPLOT... · Introduction to the SGPLOT Procedure. ... the recent introduction

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

Page 38: Introduction to the SGPLOT Procedure - UNCW …people.uncw.edu/blumj/stt592/ppt/Introduction to the SGPLOT... · Introduction to the SGPLOT Procedure. ... the recent introduction

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).

Page 39: Introduction to the SGPLOT Procedure - UNCW …people.uncw.edu/blumj/stt592/ppt/Introduction to the SGPLOT... · Introduction to the SGPLOT Procedure. ... the recent introduction

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.

Page 40: Introduction to the SGPLOT Procedure - UNCW …people.uncw.edu/blumj/stt592/ppt/Introduction to the SGPLOT... · Introduction to the SGPLOT Procedure. ... the recent introduction

Exercises

Using the projects data set, see if you can make this overlay (some

new options for density and histogram, no other statements yet).

Page 41: Introduction to the SGPLOT Procedure - UNCW …people.uncw.edu/blumj/stt592/ppt/Introduction to the SGPLOT... · Introduction to the SGPLOT Procedure. ... the recent introduction

Exercises

Now work on the axes a bit.

Page 42: Introduction to the SGPLOT Procedure - UNCW …people.uncw.edu/blumj/stt592/ppt/Introduction to the SGPLOT... · Introduction to the SGPLOT Procedure. ... the recent introduction

Exercises

And a little more…