Show Menu
Cheatography

ggplot2 Cheat Sheet (DRAFT) by [deleted]

Quick reference to the plotting interface of R's package ggplot2.

This is a draft cheat sheet. It is a work in progress and is not finished yet.

ggPlot2: Basics

Basic Plot
ggplot­(da­taset, aes(x, y, colour=z)

ggPlot2: layers

mapping
Some asthetic mappings (aes)
data
The dataset to use
geom
Override default geom
stat
Override default stat
position
Adjustment for overla­pping objects (dodge, fill, identity, jitter, stack)
...
Parameters for geom or stat; also aesthetics with constant values
Layers may be added to plot objects using the layer command or stat_... and geom_... functions. Parameters not set are taken from the function's or plot's default values.

ggPlot2: Stats

bin
boxplot
contour
density
density2d
function
idendity
qq
quantile
smooth
spoke
step
sum
summary
unique
 

ggPlot2: Geoms

abline
intercept, linetype, size, slope
area
fill, linetype, size, x, y
bar
fill, linetype, size, weight, x, y
bin2d
fill, linetype, size, weight, xmin, xmax, ymin, ymax
boxplot
fill, lower, middle, size, upper, weight, x, ymax, ymin
contour
linetype, size, weight, x, y
crossbar
fill, linetype, size, x, y, ymax, ymin
density
fill, linetype, size, weight, x, y
density2d
linetype, size, weight, x, y
errorbar
fill, linetype, size, x, y, ymax, *ymin
freqpoly
linetype, size
hex
fill, size, x, y
histogram
fill, linetype, size, weight, x
hline
linetype, size
jitter
fill, shape, size, x, y
line
linetype, size, x, y
linerange
linetype, size, x, ymax, ymin
path
linetype, size, x, y
point
fill, shape, size, x, y
pointrange
fill, linetype, shape, size, x, y, ymax, ymin
polygon
fill, linetype, size, x, y
quantile
linetype, size, weight, x, y
rect
fill, linetype, size, xmax, xmin, ymax, ymin
ribbon
fill, linetype, size, x, ymax, ymin
rug
linetype, size
segment
colour, linetype, size, x, xend, y, yend
smooth
fill, linetype, size, weight, x, y
step
linetype, size, x, y
text
angle, hjust, label, size, vjust, x, y
tile
fill, linetype, size, x, y
vline
linetype, size
Additi­onally, all geoms have colour and alpha aesthe­tics. Bold values are required (or provided by used statis­tics).