350 likes | 454 Views
Chapter 15. Introduction to Graphics. Section 15.1. Producing Bar and Pie Charts. Objectives. Produce high-resolution bar and pie charts. Control the statistics displayed in the chart. Graphically Summarizing Data. You can use bar or pie charts to graphically display the following:
E N D
Chapter 15 Introduction to Graphics
Section 15.1 Producing Bar and Pie Charts
Objectives • Produce high-resolution bar and pie charts. • Control the statistics displayed in the chart.
Graphically Summarizing Data • You can use bar or pie charts to graphically display the following: • distribution of a variable’s values • average value of a variable for different categories • total value of a variable for different categories
Specifying a Chart • When you use the GCHART procedure, perform the following tasks: • specify the physical form of the chart • identify a chart variable that determines the number of bars or pie slices to create • optionally identify an analysis variable to use for calculating statistics that determine the height (or length) of the bar or the size of the slice • By default, the height, length, or size represents a frequency count (N).
The GCHART Procedure • General form of the PROC GCHART statement: • Use one of these statements to specify the desired type of chart: PROC GCHART DATA=SAS-data-set; HBAR chart-variable . . . </options>; VBAR chart-variable . . . </options>; PIE chart-variable . . . </options>;
Chart Variable • The chart variable • determines the number of bars or slices produced within a graph • can be character or numeric.
Vertical Bar Chart • Produce a vertical bar chart that displays the number of employees in each job code. proc gchart data=ia.crew; vbar JobCode;run; JobCodeis the chart variable.
Horizontal Bar Chart Produce a horizontal bar chart that displays the number of employees in each job code. proc gchart data=ia.crew; hbar JobCode;run; JobCodeis the chart variable.
Pie Chart Produce a pie chart that displays the number of employees in each job code. proc gchart data=ia.crew; pie JobCode;run; JobCodeis the chart variable.
Character Chart Variable • If the chart variable is character, a bar or slice is created for eachuniquevariable value. • The chart variable is JobCode.
Numeric Chart Variable • For numeric chart variables, the variables are assumed to be continuousunless otherwise specified. • Intervals are automatically calculated and identified by midpoints. • One bar or slice is constructed for each midpoint.
Numeric Chart Variable • Produce a vertical bar chart on the numeric variable Salary. proc gchart data=ia.crew; vbar Salary;run; Salaryis the chart variable.
The DISCRETE Option • To override the default behavior for numeric chart variables, use the DISCRETEoption in the HBAR, VBAR, or PIE statement. • The DISCRETEoption produces a bar or slice for each unique numeric variable value; the values are no longer treated as intervals.
Numeric Chart Variable Produce a vertical bar chart that displays a separate bar for each distinct value of the numeric variable Salary. • Salary is the chart variable,but theDISCRETEoption modifies how the values are displayed. proc gchart data=ia.crew; vbar Salary / discrete;run;
Summary Statistic • By default, the statistic that determines the length or height of each bar or size of pie slice is a frequency count (N).
Analysis Variable • To override the default frequency count, you can use the following HBAR, VBAR, or PIE statement options: SUMVAR=analysis-variable TYPE=MEAN | SUM
SUMVAR= and TYPE= Options • If an analysis variable is specified, the default value of TYPE is SUM. • If an analysis variable is not specified, the default value of TYPE is FREQ.
Using an Analysis Variable • Produce a vertical bar chart that displays the average salary of employees in each job code. proc gchart data=ia.crew; vbar JobCode / sumvar=Salary type=mean;run;
RUN-Group Processing • PROC GCHART supports RUN-group processing, which means that • the procedure executes the group of statements following the PROC statement when a RUN statement is encountered • additional statements followed by another RUN statement can be submitted without resubmitting the PROC statement • the procedure stays active until a PROC, DATA, or QUIT statement is encountered.
Pie Chart Produce a pie chart that displays the total salary of employees in each job code. proc gchart data=ia.crew; pie JobCode / sumvar=Salary type=sum; format Salary dollar8.; run;
Pie Chart • You can use the FILL= option to specify whether to fill the pie slices in a solid (FILL=S) or crosshatched (FILL=X) pattern. pie JobCode / sumvar=Salary type=sum fill=x; format Salary dollar8.; run;
Exploding a Pie Slice • You can highlight individual slices of a pie chart by moving them away from the rest of the pie with the EXPLODE= option. pie JobCode / sumvar=Salary type=sum fill=x explode='PILOT3'; format Salary dollar8.; run;quit;