GPL Reference Guide
GPL Reference Guide
GPL Reference Guide
For more information about SPSS software products, please visit our Web site at http://www.spss.com or contact SPSS Inc. 233 South Wacker Drive, 11th Floor Chicago, IL 60606-6412 Tel: (312) 651-3000 Fax: (312) 651-3668 SPSS is a registered trademark and the other product names are the trademarks of SPSS Inc. for its proprietary computer software. No material describing such software may be produced or distributed without the written permission of the owners of the trademark and license rights in the software and the copyrights in the published materials. The SOFTWARE and documentation are provided with RESTRICTED RIGHTS. Use, duplication, or disclosure by the Government is subject to restrictions as set forth in subdivision (c) (1) (ii) of The Rights in Technical Data and Computer Software clause at 52.227-7013. Contractor/manufacturer is SPSS Inc., 233 South Wacker Drive, 11th Floor, Chicago, IL 60606-6412. General notice: Other product names mentioned herein are used for identification purposes only and may be trademarks of their respective companies. TableLook is a trademark of SPSS Inc. Windows is a registered trademark of Microsoft Corporation. DataDirect, DataDirect Connect, INTERSOLV, and SequeLink are registered trademarks of DataDirect Technologies. Portions of this product were created using LEADTOOLS 1991-2000, LEAD Technologies, Inc. ALL RIGHTS RESERVED. LEAD, LEADTOOLS, and LEADVIEW are registered trademarks of LEAD Technologies, Inc. Portions of this product were based on the work of the FreeType Team (http://www.freetype.org). A portion of the SPSS software contains zlib technology. Copyright 1995-2002 by Jean-loup Gailly and Mark Adler. The zlib software is provided as-is, without express or implied warranty. In no event shall the authors of zlib be held liable for any damages arising from the use of this software. A portion of the SPSS software contains Sun Java Runtime libraries. Copyright 2003 by Sun Microsystems, Inc. All rights reserved. The Sun Java Runtime libraries include code licensed from RSA Security, Inc. Some portions of the libraries are licensed from IBM and are available at http://oss.software.ibm.com/icu4j/. Sun makes no warranties to the software of any kind. GPL Reference Guide Copyright 2005 by SPSS Inc. All rights reserved. Printed in the United States of America. No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in any form or by any means, electronic, mechanical, photocopying, recording, or otherwise, without the prior written permission of the publisher.
Contents
1 Introduction to GPL 1
Concepts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 Brief Overview of GPL Algebra. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 How Coordinates and the Algebra Interact . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
11
11 12 13 13 14 19 23 28 35 37 37 38 38 39 40 40 41 42 42 43 43 44 45 46 47 48 49 50 51
Statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
base Function . . . . . . . . . . . . base.aesthetic Function. . . . . base.all Function . . . . . . . . . . base.coordinate Function . . . begin Function . . . . . . . . . . . . bin.dot Function . . . . . . . . . . . bin.quantile.letter Function . . bin.rect Function . . . . . . . . . . binCount Function . . . . . . . . . binStart Function . . . . . . . . . . binWidth Function . . . . . . . . . closed Function . . . . . . . . . . . cluster Function. . . . . . . . . . . col Function. . . . . . . . . . . . . . collapse Function . . . . . . . . . color Function . . . . . . . . . . . . color.brightness Function. . . . color.hue Function . . . . . . . . . color.saturation Function . . . . csvSource Function . . . . . . . .
iii
dataMinimum Function . . . . . . . . . . . dataMaximum Function . . . . . . . . . . . delta Function . . . . . . . . . . . . . . . . . . end Function . . . . . . . . . . . . . . . . . . . eval Function . . . . . . . . . . . . . . . . . . . exclude Function . . . . . . . . . . . . . . . . exponent Function . . . . . . . . . . . . . . . gridlines Function . . . . . . . . . . . . . . . In Function . . . . . . . . . . . . . . . . . . . . include Function . . . . . . . . . . . . . . . . jump Function . . . . . . . . . . . . . . . . . . label Function (For Graphic Elements) label Function (For Guides) . . . . . . . . map Function. . . . . . . . . . . . . . . . . . . max Function . . . . . . . . . . . . . . . . . . . min Function . . . . . . . . . . . . . . . . . . . missing.gap Function . . . . . . . . . . . . . missing.interpolate Function . . . . . . . missing.wings Function . . . . . . . . . . . notIn Function . . . . . . . . . . . . . . . . . . origin Function (For Graphs). . . . . . . . origin Function (For Scales) . . . . . . . . position Function . . . . . . . . . . . . . . . . preserveStraightLines Function . . . . . reflect Function . . . . . . . . . . . . . . . . . region.confi.smooth Function. . . . . . . region.spread.confi Function . . . . . . . region.spread.range Function . . . . . . region.spread.sd Function . . . . . . . . . region.spread.se Function . . . . . . . . . reverse Function . . . . . . . . . . . . . . . . scale Function . . . . . . . . . . . . . . . . . . shape Function . . . . . . . . . . . . . . . . . size Function . . . . . . . . . . . . . . . . . . . smooth.cubic Function. . . . . . . . . . . . smooth.linear Function . . . . . . . . . . . smooth.loess Function . . . . . . . . . . . . smooth.mean Function. . . . . . . . . . . . smooth.spline Function . . . . . . . . . . . smooth.step Function. . . . . . . . . . . . . smooth.quadratic Function . . . . . . . . sort.data Function . . . . . . . . . . . . . . . sort.natural Function . . . . . . . . . . . . . sort.statistic Function . . . . . . . . . . . .
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
.. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. ..
51 52 52 53 53 54 55 55 56 56 57 57 58 59 60 60 60 61 61 62 62 63 64 64 65 65 66 67 68 69 70 70 71 72 73 74 75 76 77 78 78 79 80 80
iv
sort.values Function. . . . . . . . . . . . . . . . . split Function . . . . . . . . . . . . . . . . . . . . . . start Function . . . . . . . . . . . . . . . . . . . . . startAngle Function . . . . . . . . . . . . . . . . . summary.count Function . . . . . . . . . . . . . summary.count.cumulative Function . . . . summary.max Function . . . . . . . . . . . . . . summary.min Function . . . . . . . . . . . . . . . summary.mean Function . . . . . . . . . . . . . summary.percent Function. . . . . . . . . . . . summary.percent.cumulative Function. . . summary.sum Function . . . . . . . . . . . . . . summary.sum.cumulative Function . . . . . texture.pattern Function. . . . . . . . . . . . . . ticks Function . . . . . . . . . . . . . . . . . . . . . transparency Function . . . . . . . . . . . . . . . transpose Function . . . . . . . . . . . . . . . . . userSource Function . . . . . . . . . . . . . . . . values Function . . . . . . . . . . . . . . . . . . . .
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
.. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. ..
81 81 82 82 83 84 85 86 87 88 89 90 91 92 93 94 95 95 96
Examples
97
Using the Examples in Your Application. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97 Summary Bar Chart Examples. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98 Simple Bar Chart . . . . . . . . . . . . . . . . . . . . . . Simple Bar Chart of Counts . . . . . . . . . . . . . . Simple Horizontal Bar Chart . . . . . . . . . . . . . . Simple Bar Chart With Error Bars. . . . . . . . . . Simple Bar Chart with Bar for All Categories . Stacked Bar Chart . . . . . . . . . . . . . . . . . . . . . Clustered Bar Chart . . . . . . . . . . . . . . . . . . . . Clustered and Stacked Bar Chart . . . . . . . . . . Bar Chart Using an Evaluation Function . . . . . Paneled Bar Chart . . . . . . . . . . . . . . . . . . . . . 3-D Bar Chart. . . . . . . . . . . . . . . . . . . . . . . . . Error Bar Chart . . . . . . . . . . . . . . . . . . . . . . . Histogram Examples . . . . . . . . . . . . . . . . . . . . . . . Histogram . . . . . . . . . Frequency Polygon . . Stacked Histogram . . Cumulative Histogram ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... . . 98 . . 98 . . 99 . 100 . 101 . 101 . 102 . 103 . 103 . 104 . 106 . 106 . 107 . . . . 107 108 108 109
High-Low Chart Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109 Simple Range Bar for One Variable . . Simple Range Bar for Two Variables . High-Low-Close Chart . . . . . . . . . . . . Scatter/Dot Examples . . . . . . . . . . . . . . . . Simple 1-D Scatterplot . . . . . . . . . . . . Simple 2-D Scatterplot . . . . . . . . . . . . Simple 2-D Scatterplot with Fit Line . . Grouped Scatterplot . . . . . . . . . . . . . Scatterplot Matrix (SPLOM) . . . . . . . . Bubble Plot . . . . . . . . . . . . . . . . . . . . Scatterplot with Border Histograms . . Scatterplot with Border Boxplots . . . . Dot Plot . . . . . . . . . . . . . . . . . . . . . . . 2-D Dot Plot . . . . . . . . . . . . . . . . . . . . Line Chart Examples . . . . . . . . . . . . . . . . . Simple Line Chart. . . . . . . . . . . . . . . . Simple Line Chart with Points. . . . . . . Line Chart of Date Data . . . . . . . . . . . Line Chart With Step Interpolation . . . Fit Line. . . . . . . . . . . . . . . . . . . . . . . . Line Chart from Equation . . . . . . . . . . Line Chart with Separate Scales . . . . Line Chart in Parallel Coordinates . . . Pie Chart Examples. . . . . . . . . . . . . . . . . . ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... . . . . . . . . . . . . . . . . . . . . . . . . 110 110 111 112 112 112 113 114 114 115 116 117 118 119 120 120 121 122 122 123 124 125 126 126
Pie Chart . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 126 Paneled Pie Chart . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 127 Boxplot Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 128 1-D Boxplot . . . . . . . . . . . . . . . . . Boxplot . . . . . . . . . . . . . . . . . . . . Boxplot With Overlaid Dot Plot . . . Multi-Graph Examples . . . . . . . . . . . . ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... . . . . . . . . 128 128 130 130 130 131 132 133
Scatterplot with Border Histograms . . . . . Scatterplot with Border Boxplots . . . . . . . Stocks Line Chart with Volume Bar Chart . Histogram with Dot Plot . . . . . . . . . . . . . .
vi
Color Constants . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135 Shape Constants . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136 Size Constants . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136 Pattern Constants . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136
Bibliography Index
137 138
vii
Chapter
Introduction to GPL
The Graphics Production Language (GPL) is a language for creating graphs. It is a concise and flexible language based on the grammar described in The Grammar of Graphics. Rather than requiring you to learn commands that are specific to different graph types, GPL provides a basic grammar with which you can build any graph. For more information about the theory that supports GPL, see The Grammar of Graphics, 2nd Edition (Wilkinson, 2005). Following is a GPL example that creates a simple bar chart. A summary of the GPL follows the picture. Note: To run the examples that appear in the GPL documentation, they must be incorporated into the syntax specific to your application. For more information, see Using the Examples in Your Application in Chapter 3 on p. 97.
Figure 1-1 GPL for a simple bar chart SOURCE: s=userSource(id("Employeedata")) DATA: jobcat=col(source(s), name("jobcat"), unit.category()) DATA: salary=col(source(s), name("salary")) SCALE: linear(dim(2), include(0)) GUIDE: axis(dim(2), label("Mean Salary")) GUIDE: axis(dim(1), label("Job Category")) ELEMENT: interval(position(summary.mean(jobcat*salary)))
2 Chapter 1
Each line in the example is a statement. One or more statements make up a block of GPL. Each statement specifies an aspect of the graph, such as the source data, relevant data transformations, coordinate systems, guides (for example, axis labels), graphic elements (for example, points and lines), and statistics. Statements begin with a label that identifies the statement type. The label and colon (:) that follow it are the only items that delineate the statement. No other characters are needed, so multiple statements can appear on one line. Note that all quotes must be quotation marks. You cannot use single quotes in GPL. Consider the statements in the example: