1Introduction ............................................... 1
1.1 Welcome to ggplot2 ...................................... 1
1.2 Other resources ......................................... 2
1.3 What is the grammar of graphics? ......................... 3
1.4 How does ggplot2 fit in with other R graphics? ............. 4
1.5 About this book ......................................... 5
1.6 Installation ............................................. 6
1.7 Acknowledgements ...................................... 6
2 Getting started with qplot ................................. 9
2.1 Introduction ............................................ 9
2.2 Datasets ............................................... 10
2.3 Basic use ............................................... 11
2.4 Colour, size, shape and other aesthetic attributes ............ 12
2.5 Plot geoms ............................................. 13
2.5.1 Adding a smoother to a plot ........................ 14
2.5.2 Boxplots and jittered points ........................ 16
2.5.3 Histogram and density plots ........................ 18
2.5.4 Bar charts ........................................ 20
2.5.5 Time series with line and path plots ................. 20
2.6 Faceting ................................................ 22
2.7 Other options ........................................... 23
2.8 Differences from plot ..................................... 26
3 Mastering the grammar ................................... 27
3.1 Introduction ............................................ 27
3.2 Fuel economy data....................................... 28
3.3 Building a scatterplot .................................... 29
3.4 A more complex plot ..................................... 34
3.5 Components of the layered grammar ....................... 35
3.5.1 Layers ........................................... 37
3.5.2 Scales ............................................ 37
3.5.3 Coordinate system................................. 38
3.5.4 Faceting .......................................... 38
3.6 Data structures ......................................... 39
V