ggplot2: elegant graphics for data analysis
Welcome
Preface to the third edition
Major changes
Preface to the second edition
Major changes
The future
Acknowledgements
I Getting started
1
Introduction
1.1
Welcome to ggplot2
1.2
What is the grammar of graphics?
1.3
How does ggplot2 fit in with other R graphics?
1.4
About this book
1.5
Installation
1.6
Other resources
1.7
Colophon
2
Getting started with ggplot2
2.1
Introduction
2.2
Fuel economy data
2.2.1
Exercises
2.3
Key components
2.3.1
Exercises
2.4
Colour, size, shape and other aesthetic attributes
2.4.1
Exercises
2.5
Facetting
2.5.1
Exercises
2.6
Plot geoms
2.6.1
Adding a smoother to a plot
2.6.2
Boxplots and jittered points
2.6.3
Histograms and frequency polygons
2.6.4
Bar charts
2.6.5
Time series with line and path plots
2.6.6
Exercises
2.7
Modifying the axes
2.8
Output
3
Frequently asked questions
II Toolbox
Introduction
4
Individual geoms
4.1
Basic plot types
4.1.1
Exercises
5
Collective geoms
5.1
Multiple groups, one aesthetic
5.2
Different groups on different layers
5.3
Overriding the default grouping
5.4
Matching aesthetics to graphic objects
5.5
Exercises
6
Statistical summaries
6.1
Revealing uncertainty
6.2
Weighted data
6.3
Diamonds data
6.4
Displaying distributions
6.4.1
Exercises
6.5
Dealing with overplotting
6.6
Statistical summaries
7
Space and time
7.1
Surface plots
7.2
Drawing maps
7.2.1
Vector boundaries
7.2.2
Point metadata
7.2.3
Raster images
7.2.4
Area metadata
8
Annotations
8.1
Titles
8.2
Labels
8.3
Text labels
8.4
Building custom annotations
8.5
Direct labelling
8.6
Annotation across facets
9
Arranging plots
III The Grammar
10
Mastering the grammar
10.1
Introduction
10.2
Building a scatterplot
10.2.1
Mapping aesthetics to data
10.2.2
Scaling
10.3
Adding complexity
10.4
Components of the layered grammar
10.4.1
Layers
10.4.2
Scales
10.4.3
Coordinate system
10.4.4
Facetting
10.5
Exercises
11
Build a plot layer by layer
11.1
Introduction
11.2
Building a plot
11.3
Data
11.3.1
Exercises
11.4
Aesthetic mappings
11.4.1
Specifying the aesthetics in the plot vs. in the layers
11.4.2
Setting vs. mapping
11.4.3
Exercises
11.5
Geoms
11.5.1
Exercises
11.6
Stats
11.6.1
Generated variables
11.6.2
Exercises
11.7
Position adjustments
11.7.1
Exercises
12
Scales, axes and legends
12.1
Introduction
12.2
Modifying scales
12.2.1
Exercises
12.3
Guides: legends and axes
12.3.1
Scale title
12.3.2
Breaks and labels
12.3.3
Exercises
12.4
Legends
12.4.1
Layers and legends
12.4.2
Legend layout
12.4.3
Guide functions
12.4.4
Exercises
12.5
Limits
12.5.1
Exercises
12.6
Scales toolbox
12.6.1
Continuous position scales
12.6.2
Colour
12.6.3
The manual discrete scale
12.6.4
The identity scale
12.6.5
Exercises
13
Coordinate systems
13.1
Linear coordinate systems
13.1.1
Zooming into a plot with
coord_cartesian()
13.1.2
Flipping the axes with
coord_flip()
13.1.3
Equal scales with
coord_fixed()
13.2
Non-linear coordinate systems
13.2.1
Transformations with
coord_trans()
13.2.2
Polar coordinates with
coord_polar()
13.2.3
Map projections with
coord_map()
14
Facetting
14.1
Facet wrap
14.2
Facet grid
14.3
Controlling scales
14.4
Missing facetting variables
14.5
Grouping vs. facetting
14.6
Continuous variables
14.7
Exercises
15
Themes
15.1
Introduction
15.2
Complete themes
15.2.1
Exercises
15.3
Modifying theme components
15.4
Theme elements
15.4.1
Plot elements
15.4.2
Axis elements
15.4.3
Legend elements
15.4.4
Panel elements
15.4.5
Facetting elements
15.4.6
Exercises
15.5
Saving your output
IV Extending ggplot2
16
Programming with ggplot2
16.1
Introduction
16.2
Single components
16.2.1
Exercises
16.3
Multiple components
16.3.1
Plot components
16.3.2
Annotation
16.3.3
Additional arguments
16.3.4
Exercises
16.4
Plot functions
16.4.1
Indirectly referring to variables
16.4.2
The plot environment
16.4.3
Exercises
16.5
Functional programming
16.5.1
Exercises
17
ggplot2 internals
17.1
The
plot()
method
17.2
Follow the data
17.2.1
The build step
17.2.2
The gtable step
17.3
ggproto
17.3.1
ggproto syntax
17.3.2
ggproto style guide
References
Written with bookdown
ggplot2: Elegant Graphics for Data Analysis
3
Frequently asked questions