ggplot2 - Elegant Graphics for Data Analysis
von: Hadley Wickham
Springer-Verlag, 2009
ISBN: 9780387981413
Sprache: Englisch
211 Seiten, Download: 8925 KB
Format: PDF, auch als Online-Lesen
Contents | 5 | ||
1 Introduction | 9 | ||
1.1 Welcome to ggplot2 | 9 | ||
1.2 Other resources | 10 | ||
1.3 What is the grammar of graphics? | 11 | ||
1.4 How does ggplot2 fit in with other R graphics? | 12 | ||
1.5 About this book | 13 | ||
1.6 Installation | 14 | ||
1.7 Acknowledgements | 14 | ||
2 Getting started with qplot | 16 | ||
2.1 Introduction | 16 | ||
2.2 Datasets | 17 | ||
2.3 Basic use | 18 | ||
2.4 Colour, size, shape and other aesthetic attributes | 19 | ||
2.5 Plot geoms | 20 | ||
2.5.1 Adding a smoother to a plot | 21 | ||
2.5.2 Boxplots and jittered points | 23 | ||
2.5.3 Histogram and density plots | 25 | ||
2.5.4 Bar charts | 27 | ||
2.5.5 Time series with line and path plots | 27 | ||
2.6 Faceting | 29 | ||
2.7 Other options | 30 | ||
2.8 Differences from plot | 33 | ||
3 Mastering the grammar | 34 | ||
3.1 Introduction | 34 | ||
3.2 Fuel economy data | 35 | ||
3.3 Building a scatterplot | 36 | ||
3.4 A more complex plot | 41 | ||
3.5 Components of the layered grammar | 42 | ||
3.5.1 Layers | 44 | ||
3.5.2 Scales | 44 | ||
3.5.3 Coordinate system | 45 | ||
3.5.4 Faceting | 45 | ||
3.6 Data structures | 46 | ||
4 Build a plot layer by layer | 48 | ||
4.1 Introduction | 48 | ||
4.2 Creating a plot | 49 | ||
4.3 Layers | 49 | ||
4.4 Data | 52 | ||
4.5 Aesthetic mappings | 53 | ||
4.5.1 Plots and layers | 53 | ||
4.5.2 Setting vs. mapping | 54 | ||
4.5.3 Grouping | 56 | ||
4.5.4 Matching aesthetics to graphic objects | 59 | ||
4.6 Geoms | 62 | ||
4.7 Stat | 62 | ||
4.8 Position adjustments | 66 | ||
4.9 Pulling it all together | 66 | ||
4.9.1 Combining geoms and stats | 67 | ||
4.9.2 Displaying precomputed statistics | 69 | ||
4.9.3 Varying aesthetics and data | 69 | ||
5 Toolbox | 72 | ||
5.1 Introduction | 72 | ||
5.2 Overall layering strategy | 73 | ||
5.3 Basic plot types | 73 | ||
5.4 Displaying distributions | 75 | ||
5.5 Dealing with overplotting | 79 | ||
5.6 Surface plots | 84 | ||
5.7 Drawing maps | 84 | ||
5.8 Revealing uncertainty | 87 | ||
5.9 Statistical summaries | 88 | ||
5.9.1 Individual summary functions | 91 | ||
5.9.2 Single summary function | 91 | ||
5.10 Annotating a plot | 92 | ||
5.11 Weighted data | 95 | ||
6 Scales, axes and legends | 98 | ||
6.1 Introduction | 98 | ||
6.2 How scales work | 99 | ||
6.3 Usage | 100 | ||
6.4 Scale details | 103 | ||
6.4.1 Common arguments | 103 | ||
6.4.2 Position scales | 105 | ||
6.4.3 Colour | 109 | ||
6.4.4 The manual discrete scale | 114 | ||
6.4.5 The identity scale | 116 | ||
6.5 Legends and axes | 117 | ||
6.6 More resources | 119 | ||
7 Positioning | 121 | ||
7.1 Introduction | 121 | ||
7.2 Faceting | 121 | ||
7.2.1 Facet grid | 122 | ||
7.2.2 Facet wrap | 126 | ||
7.2.3 Controlling scales | 127 | ||
7.2.4 Missing faceting variables | 129 | ||
7.2.5 Grouping vs. faceting | 129 | ||
7.2.6 Dodging vs. faceting | 131 | ||
7.2.7 Continuous variables | 135 | ||
7.3 Coordinate systems | 135 | ||
7.3.1 Transformation | 136 | ||
7.3.2 Statistics | 139 | ||
7.3.3 Cartesian coordinate systems | 139 | ||
7.3.4 Non-Cartesian coordinate systems | 142 | ||
8 Polishing your plots for publication | 144 | ||
8.1 Themes | 144 | ||
8.1.1 Built-in themes | 145 | ||
8.1.2 Theme elements and element functions | 147 | ||
8.2 Customising scales and geoms | 152 | ||
8.2.1 Scales | 152 | ||
8.2.2 Geoms and stats | 153 | ||
8.3 Saving your output | 153 | ||
8.4 Multiple plots on the same page | 156 | ||
8.4.1 Subplots | 157 | ||
8.4.2 Rectangular grids | 158 | ||
9 Manipulating data | 161 | ||
9.1 An introduction to plyr | 161 | ||
9.1.1 Fitting multiple models | 165 | ||
9.2 Converting data from wide to long | 168 | ||
9.2.1 Multiple time series | 168 | ||
9.2.2 Parallel coordinates plot | 171 | ||
9.3 !ggplot()! methods | 173 | ||
9.3.1 Linear models | 174 | ||
9.3.2 Writing your own | 177 | ||
10 Reducing duplication | 180 | ||
10.1 Introduction | 180 | ||
10.2 Iteration | 180 | ||
10.3 Plot templates | 181 | ||
10.4 Plot functions | 184 | ||
Appendices | 186 | ||
A Translating between different syntaxes | 187 | ||
A.1 Introduction | 187 | ||
A.2 Translating between qplot and ggplot | 187 | ||
A.2.1 Aesthetics | 187 | ||
A.2.2 Layers | 188 | ||
A.2.3 Scales and axes | 188 | ||
A.2.4 Plot options | 189 | ||
A.3 Base graphics | 189 | ||
A.3.1 High-level plotting commands | 189 | ||
A.3.2 Low-level drawing | 191 | ||
A.3.3 Legends, axes and grid lines | 192 | ||
A.3.4 Colour palettes | 192 | ||
A.3.5 Graphical parameters | 192 | ||
A.4 Lattice graphics | 192 | ||
A.5 GPL | 194 | ||
B Aesthetic specifications | 196 | ||
B.1 Colour | 196 | ||
B.2 Line type | 196 | ||
B.3 Shape | 197 | ||
B.4 Size | 197 | ||
B.5 Justification | 197 | ||
C Manipulating plot rendering with !grid! | 199 | ||
C.1 Introduction | 199 | ||
C.2 Plot viewports | 199 | ||
C.3 Plot grobs | 201 | ||
C.4 Saving your work | 201 | ||
References | 203 | ||
Index | 206 | ||
Code index | 206 |