The gchart Procedure - PowerPoint PPT Presentation

1 / 34
About This Presentation
Title:

The gchart Procedure

Description:

Controls style of major or minor tick marks. Some options: n= number of ticks (for minor it's the number between major ticks) h= height. c= color ... – PowerPoint PPT presentation

Number of Views:66
Avg rating:3.0/5.0
Slides: 35
Provided by: BLU54
Learn more at: http://people.uncw.edu
Category:
Tags: gchart | procedure | tick

less

Transcript and Presenter's Notes

Title: The gchart Procedure


1
The gchart Procedure
  • The gchart Procedure is used to create bar charts
    of various types (it can also create pie charts.
  • Its most basic form would look something like
    this
  • proc gchart datasave.padgett
  • vbar plantht
  • run
  • quit

2
The gchart Procedure
  • The vbar (or hbar) statement includes a variable
    that is referred to as the midpoint variable.
  • If this variable is of the character type, a
    midpoint is established for each unique value.
  • If it is numeric, SAS establishes classes or bins
    for it.
  • In either case, the frequency in each class is
    summarized by vertical (or horizontal) bars.

3
Basic Output
This is kind of like a histogram, except for the
spacing
This value of 75 corresponds to a class ranging
from 67.5 to 82.5 (with a frequency of about 60)
4
A Few Options
Sets the number of midpoints
  • In this version
  • proc gchart datasave.padgett
  • vbar plantht/space0 typepercent levels9
  • run
  • quit

Controls spacing between bars
Changes the statistic from frequency to percent
5
So We Get
This is a histogram
6
Setting Midpoints
  • You can also set midpoints explicitly
  • proc gchart datasave.padgett
  • vbar plantht/space0 typepercent
  • midpoints0 25 50 75 100 125 150
  • run
  • quit

The chart will be constructed with these 7 values
as class midpoints
7
Setting Midpoints
  • We might try
  • proc format
  • value classes
  • low-lt30'lt30'
  • 30-lt6030-60'
  • 60-lt9060-90'
  • 90-lt12090-120'
  • 120-high'gt120'
  • run
  • proc gchart datasave.padgett
  • vbar plantht/space0 typepercent
  • format plantht classes.
  • run
  • quit

8
We Get
SAS establishes the midpoints first then applies
the format
Oops
9
The Discrete Option
  • proc gchart datasave.padgett
  • vbar plantht/discrete space0 typepercent
  • format plantht classes.
  • run
  • quit

Discrete establishes each distinct value of the
midpoint variable as a midpoint on the graph. If
the variable is formatted, the formatted values
are used for the construction.
If you use discrete with a numeric variable
you should 1. Be sure it has only a few
distinct values. or 2. Use a format to
make categories for it.
10
Result
Bar width determines the space available
for writing midpoint values
11
Bar Width
  • proc gchart datasave.plantht
  • vbar plantht/discrete space0 typepercent
    width12
  • format plantht classes.
  • run
  • quit

Sets bar width
12
Horizontal Bar Charts
  • proc format
  • value pol_type 'CO' 'Carbon Monoxide' 'LEAD'
    'Lead' 'O3' 'Ozone'
  • 'SO2' 'Sulfur Diox.'
  • run
  • proc gchart datasave.projects
  • hbar pol_type/discrete typepercent
  • format pol_type pol_type.
  • run
  • quit

13
Horizontal Bar Charts
Besides the orientation of the bars, horizontal
bar charts differ in that they produce a set of
summary statistics by default. You can suppress
this with the nostats option.
14
Summary Variables
  • If I want my bar chart to summarize values of
    some analysis variable for each midpoint, use the
    sumvar (and type ) option.
  • E.g.
  • proc gchart datasave.projects
  • hbar pol_type/discrete sumvarjobtotal
    typemean nostats
  • format pol_type pol_type.
  • run
  • quit

15
Result
Mean total cost is now summarized for each
pollution type.
Note Only two types of statistics are available
with summary variables, the sum (which is the
default) and the mean
16
Where to find more
17
Axis Modification
  • The two axes on the bar graph are referred to as
    the midpoint axis (maxis) and the response axis
    (raxis).
  • Axes can be modified with axis statements. The
    general form of an axis statement is
  • axisn options
  • where n is an integer between 1 and 99.

18
Axis Modification
  • Lots of options can be set in an axis statement.
    E.g.
  • proc gchart datasave.projects
  • hbar pol_type/discrete sumvarjobtotal typemean
    nostats maxisaxis1 raxisaxis2
  • format pol_type pol_type.
  • axis1 label(cblue h1.5 fswissb Type of
    Pollution Project')
  • axis2 order(0 to 100000 by 20000) minor(n1)
    value(h1.25 fswissb)
  • label(fswissb cred h1.5 'Mean Job Cost in
    Dollars')
  • run
  • quit

Assign axis statements to each chart axis
Choose options/modifications for specified axis
19
The Result
20
Some Options
  • c
  • sets axis color
  • w
  • sets axis width
  • label(options) Sets axis label, some options
  • h text height
  • c text color
  • f font style
  • Any Text is the axis label (overrides any label
    currently assigned)
  • a angle of the label text
  • r rotation of individual characters

21
Some Options
  • value (options)
  • controls appearance of axis values, options are
    similar to those for label.
  • order(a to b by c)
  • sets axis starting and ending points and
    increment
  • minor(options) major(options)
  • Controls style of major or minor tick marks.
    Some options
  • n number of ticks (for minor its the number
    between major ticks)
  • h height
  • c color
  • w width

22
Where to Find More (If you dare)
23
Bar Fill Patterns
  • In all charts to this point, all bars have been
    red. It is possible to change the color, and it
    is possible to give each bar a different color.
  • To give bars different colors, specify
    patternidmidpoint in the hbar or vbar statement.

24
Bar Fill Patterns
patternidmidpoint gives each bar its
own pattern or color
25
Setting a Color List
  • The goptions statement allows us to set several
    global graphics options, one of which is a color
    list
  • goptions colors(blue red yellow cyan orange)
  • proc gchart datasave.projects
  • hbar pol_type/discrete sumvarjobtotal typemean
    nostats
  • maxisaxis1 raxisaxis2 patternidmidpoint
  • format pol_type pol_type.
  • axis1 label(cblue h1.5 fswissb Type of
    Pollution Project')
  • axis2 order(0 to 100000 by 20000)
  • minor(n1) value(h1.25 fswissb)
    label(fswissb cred h1.5 Mean Total Project
    Cost')
  • run
  • quit

This color becomes the default axis and text color
26
Setting a Color List
  • Remember, setting a color is an option for any
    axis statement, so if you change the color list,
    you can always override the first color behavior
    in the axis statement.
  • coutline is an option you can use in the vbar or
    hbar statement to set the bar outline color.

27
Alternate Fill Patterns
  • You can specify some alternate fill patterns for
    bars (particularly useful for creating black
    white charts) with a pattern statement(s).
  • The two major options in the pattern statement
    are c and v, for color and fill, respectively.
    Rules
  • If no color is specified, the fill pattern is
    applied for each color in the color list.
  • If a color is specified, the fill pattern is
    applied only once.
  • The fill pattern can be set to on of Ln, Rn or
    Xn where n is an integer between 1 and 5.

28
An Example
L, R and X correspond to left-leaning, right-leani
ng and crossed lines. The number controls
the thickness
Add these pattern statements to your previous
code to get the above bar graph pattern cblack
vL1 pattern cblack vR1 pattern cblack vX1
pattern cblack vL5 pattern cblack vR5
29
The group option
  • proc gchart datasave.padgett
  • hbar marsh/groupflower discrete sumvarplantht
    typemean nostats maxisaxis1 raxisaxis2
    gaxisaxis3 patternidmidpoint
  • format marsh marsh. flower flower.
  • axis1 label(cblue h1.5 fswissb Marsh')
  • axis2 order(0 to 120 by 20) minor(n1)
    value(h1.25 fswissb)
  • label(fswissb cred h1.5 'Mean Plant Height
    in Centimeters')
  • axis3 label(cgreen h1.5 fswissb
    Flowering')
  • run
  • quit

Sets up a grouping variablebars for the full
set of midpoints are constructed for each value
of the group variable
We can modify the group axis as well
30
Grouped Bar-Chart
31
The subgroup option
Subgroup creates stacked bars across levels of a
variable. (Not appropriate for means)
32
The subgroup option
proc gchart datasave.padgett hbar
marsh/groupflower discrete typepercent nostats
maxisaxis1 raxis axis2 gaxisaxis3
patternidsubgroup subgroupform legendlegend1
format marsh marsh. flower flower.
axis1 label(cblue h1.5 fswissb 'Marsh')
axis2 order(0 to 50 by 10) minor(n1)
value(h1.25 fswissb) label(fswissb
cred h1.5 ) axis3 label(cgreen h1.5
fswissb 'Flowering') legend1 across1
label(cblue 'Form of Plant') frame cshadowgray
position(top right) modeshare
33
Legend Modifications
  • In a legend statement, some options available
    are
  • label similar to what is available in the axis
    statement.
  • across and down sets limit for row or column
    length in the legend (only use one)
  • frame draws a border around the legend
  • cshadow places a shadow behind the legend in
    the specified color.

34
Legend Modifications
  • position( ) places the legend, choices include
  • inside/outside
  • left/right/center
  • top/bottom/middle
  • (default is bottom center outside).
  • mode tells how to allocate space for the chart
    and legend, choices are
  • reserve sets aside space for the legend before
    graph is drawn (cant be used with position set
    to inside)
  • share or protect allows graph and legend to use
    the same space. Share has the graph drawn over
    the legend if they intersect, protect does the
    opposite.
Write a Comment
User Comments (0)
About PowerShow.com