Plot basicsAll ggplot2 plots begin with a call to |
||
---|---|---|
Create a new ggplot |
||
Construct aesthetic mappings |
||
Add components to a plot |
||
Save a ggplot (or other grid object) with sensible defaults |
||
Quick plot |
||
Layer: geomsA layer combines data, aesthetic mapping, a geom (geometric object), a stat (statistical transformation), and a position adjustment. Typically, you will create layers using a |
||
Reference lines: horizontal, vertical, and diagonal |
||
Bar charts |
||
Heatmap of 2d bin counts |
||
Draw nothing |
||
A box and whiskers plot (in the style of Tukey) |
||
2d contours of a 3d surface |
||
Count overlapping points |
||
Smoothed density estimates |
||
Contours of a 2d density estimate |
||
Dot plot |
||
Horizontal error bars |
||
Hexagonal heatmap of 2d bin counts |
||
Histograms and frequency polygons |
||
Jittered points |
||
|
Vertical intervals: lines, crossbars & errorbars |
|
Polygons from a reference map |
||
Connect observations |
||
Points |
||
Polygons |
||
A quantile-quantile plot |
||
Quantile regression |
||
Ribbons and area plots |
||
Rug plots in the margins |
||
Line segments and curves |
||
Smoothed conditional means |
||
Line segments parameterised by location, direction and distance |
||
Text |
||
Rectangles |
||
Violin plot |
||
|
Visualise sf objects |
|
Layer: statsA handful of layers are more easily specified with a |
||
Compute empirical cumulative distribution |
||
Compute normal confidence ellipses |
||
Compute function for each x value |
||
Leave data as is |
||
Bin and summarise in 2d (rectangle & hexagons) |
||
Summarise y values at unique/binned x |
||
Remove duplicates |
||
Extract coordinates from 'sf' objects |
||
Calculated aesthetics |
||
Layer: position adjustmentAll layers have a position adjustment that resolves overlapping geoms. Override the default by using the |
||
Dodge overlapping objects side-to-side |
||
Don't adjust position |
||
Jitter points to avoid overplotting |
||
Simultaneously dodge and jitter |
||
Nudge points a fixed distance |
||
Stack overlapping objects on top of each another |
||
Layer: annotationsAnnotations are a special type of layer that don’t inherit global settings from the plot. They are used to add fixed reference data to plots. |
||
Reference lines: horizontal, vertical, and diagonal |
||
Create an annotation layer |
||
Annotation: Custom grob |
||
Annotation: log tick marks |
||
Annotation: a maps |
||
Annotation: high-performance rectangular tiling |
||
Create a layer of map borders |
||
AestheticsThe following help topics give a broad overview of some of the ways you can use each aesthetic. |
||
Colour related aesthetics: colour, fill and alpha |
||
Aesthetics: grouping |
||
Differentiation related aesthetics: linetype, size, shape |
||
Position related aesthetics: x, y, xmin, xmax, ymin, ymax, xend, yend |
||
ScalesScales control the details of how data values are translated to visual properties. Override the default scales to tweak details like the axis labels or legend keys, or to use a completely different translation from data to aesthetic. |
||
Modify axis, legend, and plot labels |
||
Set scale limits |
||
Expand the plot limits, using data |
||
Generate expansion vector for scales. |
||
|
Alpha transparency scales |
|
|
Sequential, diverging and qualitative colour scales from colorbrewer.org |
|
Continuous colour scales |
||
|
Position scales for continuous data (x & y) |
|
|
Position scales for date/time data |
|
Position scales for discrete data |
||
|
Gradient colour scales |
|
Sequential grey colour scales |
||
Evenly spaced colours for discrete data |
||
|
Use values without scaling |
|
|
Scale for line patterns |
|
|
Create your own discrete scale |
|
Scales for shapes, aka glyphs |
||
Scales for area or radius |
||
|
Viridis colour scales from viridisLite |
|
Guides: axes and legendsThe guides (the axes and legends) help readers interpret your plots. Guides are mostly controlled via the scale (e.g. with the |
||
Continuous colour bar guide |
||
Legend guide |
||
Set guides for each scale |
||
Specify a secondary axis |
||
FacettingFacetting generates small multiples, each displaying a different subset of the data. Facets are an alternative to aesthetics for displaying additional discrete variables. |
||
Lay out panels in a grid |
||
Wrap a 1d ribbon of panels into 2d |
||
Quote faceting variables |
||
Facetting: labelsThese functions provide a flexible toolkit for controlling the display of the “strip” labels on facets. |
||
Construct labelling specification |
||
|
Useful labeller functions |
|
Label with mathematical expressions |
||
Coordinate systemsThe coordinate system determines how the |
||
Cartesian coordinates |
||
Cartesian coordinates with fixed "aspect ratio" |
||
Cartesian coordinates with x and y flipped |
||
Map projections |
||
Polar coordinates |
||
Transformed Cartesian coordinate system |
||
ThemesThemes control the display of all non-data elements of the plot. You can override all settings with a complete theme like |
||
Modify components of a theme |
||
|
Complete themes |
|
|
Get, set, and modify the active theme |
|
|
Theme elements |
|
Programming with ggplot2These functions provides tools to help you program with ggplot2, creating functions and for-loops that generate plots for you. |
||
Define aesthetic mappings programmatically |
||
Explicitly draw plot |
||
Extending ggplot2To create your own geoms, stats, scales, and facets, you’ll need to learn a bit about the object oriented system that ggplot2 uses. Start by reading |
||
Create a new ggproto object |
||
Format or print a ggproto object |
||
Vector helpersggplot2 also provides a handful of helpers that are useful for creating visualisations. |
||
Discretise numeric data into categorical |
||
A selection of summary functions from Hmisc |
||
Calculate mean and standard error |
||
Compute the "resolution" of a numeric vector |
||
Dataggplot2 comes with a selection of built-in datasets that are used in examples to illustrate various visualisation challenges. |
||
Prices of 50,000 round cut diamonds |
||
US economic time series |
||
2d density estimate of Old Faithful data |
||
Midwest demographics |
||
Fuel economy data from 1999 and 2008 for 38 popular models of car |
||
An updated and expanded version of the mammals sleep dataset |
||
Terms of 11 presidents from Eisenhower to Obama |
||
Vector field of seal movements |
||
Housing sales in TX |
||
|
||
Autoplot and fortify
|
||
Create a complete ggplot appropriate to a particular data type |
||
Create a ggplot layer appropriate to a particular data type |
||
Fortify a model with data. |
||
Create a data frame of map data |