ggplot2 v2.2.1


Monthly downloads



by Hadley Wickham

Create Elegant Data Visualisations Using the Grammar of Graphics

A system for 'declaratively' creating graphics, based on "The Grammar of Graphics". You provide the data, tell 'ggplot2' how to map variables to aesthetics, what graphical primitives to use, and it takes care of the details.



Build Status Coverage Status CRAN\_Status\_Badge


ggplot2 is a system for declaratively creating graphics, based on The Grammar of Graphics. You provide the data, tell ggplot2 how to map variables to aesthetics, what graphical primitives to use, and it takes care of the details.


# The easiest way to get ggplot2 is to install the whole tidyverse:

# Alternatively, install just ggplot2:

# Or the the development version from GitHub:
# install.packages("devtools")


It's hard to succintly describe how ggplot2 works because it embodies a deep philosophy of visualisation. However, in most cases you start with ggplot(), supply a dataset and aesthetic mapping (with aes()). You then add on layers (like geom_point() or geom_histogram()), scales (like scale_colour_brewer()), faceting specifications (like facet_wrap()) and coordinate systems (like coord_flip()).


ggplot(mpg, aes(displ, hwy, colour = class)) + 

Learning ggplot2

If you are new to ggplot2 you are better off starting with a systematic introduction, rather than trying to learn from reading individual documentation pages. Currently, there are three good places to start:

  1. The data visualisation and graphics forcommunication chapters in R for data science. R for data science is designed to give you a comprehensive introduction to the tidyverse, and these two chapters will you get up to speed with the essentials of ggplot2 as quickly as possible.

  2. If you'd like to take an interactive online course, try Data visualisation with ggplot2 by Rick Scavetta on datacamp.

  3. If you want to dive into making common graphics as quickly as possible, I recommend The R Graphics Cookbook by Winston Chang. It provides a set of recipes to solve common graphics problems. A 2nd edition will is due out in 2017.

If you've mastered the basics and want to learn more, read ggplot2: Elegant Graphics for Data Analysis. It describes the theoretical underpinnings of ggplot2 and shows you how all the pieces fit together. This book helps you understand the theory that underpins ggplot2, and will help you create new types of graphic specifically tailored to your needs. The book is not available for free, but you can find the complete source for the book at

Getting help

There are two main places to get help with ggplot2:

  1. The ggplot2 mailing list is a friendly place to ask any questions about ggplot2. You must be a member to post messages, but anyone can read the archived discussions.

  2. stackoverflow is a great source of answers to common ggplot2 questions. It is also a great place to get help, once you have created a reproducible example that illustrates your problem.

Functions in ggplot2

Name Description
aes_all Given a character vector, create a set of identity mappings
aes_ Define aesthetic mappings programatically
aes_linetype_size_shape Differentiation related aesthetics: linetype, size, shape
aes_group_order Aesthetics: grouping
aes_colour_fill_alpha Colour related aesthetics: colour, fill and alpha
aes_auto Automatic aesthetic mapping
absoluteGrob Absolute grob
add_theme Modify properties of an element in a theme object
aes Construct aesthetic mappings
aes_position Position related aesthetics: x, y, xmin, xmax, ymin, ymax, xend, yend
annotate Create an annotation layer
annotation_custom Annotation: Custom grob
as.list.ggproto Convert a ggproto object to a list
autoplot Create a complete ggplot appropriate to a particular data type
borders Create a layer of map borders
benchplot Benchmark plot creation time. Broken down into construct, build, render and draw times.
annotation_logticks Annotation: log tick marks
annotation_map Annotation: a maps
annotation_raster Annotation: high-performance rectangular tiling
as_labeller Coerce to labeller function
coord_flip Cartesian coordinates with x and y flipped
coord_fixed Cartesian coordinates with fixed "aspect ratio"
fortify Fortify a model with data.
draw_key Key drawing functions
discrete_scale Discrete scale constructor.
fortify.lm Supplement the data fitted to a linear model with model fit statistics.
coord_map Map projections
coord_munch Munch coordinates data
facet_grid Lay out panels in a grid
facet_null Facet specification: a single panel.
geom_count Count overlapping points
geom_density_2d Contours of a 2d density estimate
geom_hex Hexagonal heatmap of 2d bin counts
geom_freqpoly Histograms and frequency polygons
geom_errorbarh Horizontal error bars
geom_jitter Jittered points
geom_raster Rectangles
geom_label Text
ggsave Save a ggplot (or other grid object) with sensible defaults
calc_element Calculate the element properties, by inheriting properties from its parents
combine_vars Take input data and define a mapping between facetting variables and ROW, COL and PANEL keys
economics US economic time series
element_grob Generate grid grob from theme element
facet_wrap Wrap a 1d ribbon of panels into 2d
faithfuld 2d density estimate of Old Faithful data
continuous_scale Continuous scale constructor.
cut_interval Discretise numeric data into categorical
coord_cartesian Cartesian coordinates
diamonds Prices of 50,000 round cut diamonds
find_panel Find panels in a gtable
fortify-multcomp Fortify methods for objects produced by multcomp
geom_polygon Polygons
geom_smooth Smoothed conditional means
geom_qq A quantile-quantile plot
geom_spoke Line segments parameterised by location, direction and distance
ggplot_gtable Build a plot with all the usual bits and pieces.
guide_legend Legend guide
ggplot Create a new ggplot
margin Theme elements
guides Set guides for each scale
expand_limits Expand the plot limits, using data Fortify method for map objects
geom_boxplot A box and whiskers plot (in the style of Tukey)
fortify.sp Fortify method for classes from the sp package.
geom_contour 2d contours of a 3d surface
limits Generate correct scale type for specified limits
lims Set scale limits
presidential Terms of 11 presidents from Eisenhower to Obama
render_axes Render panel axes
print.ggplot Explicitly draw plot
render_strips Render panel strips
geom_density Smoothed density estimates
geom_violin Violin plot
geom_dotplot Dot plot
is.rel Reports whether x is a rel object
gg_dep Give a deprecation error, warning, or message, depending on version number.
mean_se Calculate mean and standard error
is.theme Reports whether x is a theme object
hmisc A selection of summary functions from Hmisc
ggtheme Complete themes
is.Coord Is this object a coordinate system?
labs Modify axis, legend, and plot labels
labellers Useful labeller functions
position_nudge Nudge points a fixed distance
geom_quantile Quantile regression
geom_ribbon Ribbons and area plots
geom_rug Rug plots in the margins
geom_segment Line segments and curves
graphical-units Graphical units
guide_colourbar Continuous colour bar guide
print.ggproto Format or print a ggproto object
scale_linetype Scale for line patterns
qplot Quick plot
scale_manual Create your own discrete scale
stat_identity Leave data as is
stat_summary_2d Bin and summarise in 2d (rectangle & hexagons)
coord_polar Polar coordinates
coord_trans Transformed Cartesian coordinate system
geom_abline Reference lines: horizontal, vertical, and diagonal
geom_bar Bars charts
geom_bin2d Heatmap of 2d bin counts
geom_path Connect observations
geom_blank Draw nothing Add components to a plot
geom_point Points
ggplot_build Build ggplot for rendering.
ggplot2-ggproto Base ggproto classes for ggplot2
label_bquote Label with mathematical expressions
ggplot2-package ggplot2: Create Elegant Data Visualisations Using the Grammar of Graphics
labeller Construct labelling specification
last_plot Retrieve the last plot to be modified or created.
mpg Fuel economy data from 1999 and 2008 for 38 popular models of car
layer Create a new layer
msleep An updated and expanded version of the mammals sleep dataset
reexports Objects exported from other packages
position_stack Stack overlapping objects on top of each another
resolution Compute the "resolution" of a numeric vector
scale_alpha Alpha transparency scales
scale_size Scales for area or radius
scale_shape Scales for shapes, aka glyphs
update_geom_defaults Modify geom/stat aesthetic defaults for future plots
position_jitter Jitter points to avoid overplotting
stat_ellipse Compute normal confidence ellipses
scale_colour_gradient Gradient colour scales
position_jitterdodge Simultaneously dodge and jitter
scale_colour_grey Sequential grey colour scales
stat_function Compute function for each x value
midwest Midwest demographics
scale_colour_hue Evenly spaced colours for discrete data
waiver A waiver object.
scale_identity Use values without scaling
should_stop Used in examples to illustrate when errors should occur.
theme Modify components of a theme
transform_position Convenience function to transform all position variables.
translate_qplot_lattice Translating between qplot and lattice
translate_qplot_ggplot Translating between qplot and ggplot
stat_ecdf Compute empirical cumulative distribution
remove_missing Convenience function to remove missing values from a data.frame
scale_date Position scales for date/time data
scale_x_discrete Position scales for discrete data
wrap_dims Arrange 1d structure into a grid
geom_crossbar Vertical intervals: lines, crossbars & errorbars
geom_map Polygons from a reference map
sec_axis Specify a secondary axis
update_labels Update axis/legend labels
seals Vector field of seal movements
ggproto Create a new ggproto object
is.facet Is this object a facetting specification?
map_data Create a data frame of map data
ggplotGrob Generate a ggplot2 plot grob.
is.ggplot Reports whether x is a ggplot object
position_identity Don't adjust position
max_height Get the maximal width/length of a list of grobs
position_dodge Dodge overlapping objects side-to-side
stat_summary_bin Summarise y values at unique/binned x
scale_continuous Position scales for continuous data (x & y)
scale_colour_brewer Sequential, diverging and qualitative colour scales from
stat_unique Remove duplicates
zeroGrob The zero grob draws nothing and has zero size.
summary.ggplot Displays a useful description of a ggplot object
theme_get Get, set, and modify the active theme
No Results!

Last month downloads


License GPL-2 | file LICENSE
LazyData true
Collate 'ggproto.r' 'aaa-.r' 'aes-calculated.r' 'aes-colour-fill-alpha.r' 'aes-group-order.r' 'aes-linetype-size-shape.r' 'aes-position.r' 'utilities.r' 'aes.r' 'legend-draw.r' 'geom-.r' 'annotation-custom.r' 'annotation-logticks.r' 'geom-polygon.r' 'geom-map.r' 'annotation-map.r' 'geom-raster.r' 'annotation-raster.r' 'annotation.r' 'autoplot.r' 'axis-secondary.R' 'bench.r' 'bin.R' 'coord-.r' 'coord-cartesian-.r' 'coord-fixed.r' 'coord-flip.r' 'coord-map.r' 'coord-munch.r' 'coord-polar.r' 'coord-quickmap.R' 'coord-transform.r' 'data.R' 'facet-.r' 'facet-grid-.r' 'facet-null.r' 'facet-wrap.r' 'fortify-lm.r' 'fortify-map.r' 'fortify-multcomp.r' 'fortify-spatial.r' 'fortify.r' 'stat-.r' 'geom-abline.r' 'geom-rect.r' 'geom-bar.r' 'geom-bin2d.r' 'geom-blank.r' 'geom-boxplot.r' 'geom-col.r' 'geom-path.r' 'geom-contour.r' 'geom-count.r' 'geom-crossbar.r' 'geom-segment.r' 'geom-curve.r' 'geom-defaults.r' 'geom-ribbon.r' 'geom-density.r' 'geom-density2d.r' 'geom-dotplot.r' 'geom-errorbar.r' 'geom-errorbarh.r' 'geom-freqpoly.r' 'geom-hex.r' 'geom-histogram.r' 'geom-hline.r' 'geom-jitter.r' 'geom-label.R' 'geom-linerange.r' 'geom-point.r' 'geom-pointrange.r' 'geom-quantile.r' 'geom-rug.r' 'geom-smooth.r' 'geom-spoke.r' 'geom-text.r' 'geom-tile.r' 'geom-violin.r' 'geom-vline.r' 'ggplot2.r' 'grob-absolute.r' 'grob-dotstack.r' 'grob-null.r' 'grouping.r' 'guide-colorbar.r' 'guide-legend.r' 'guides-.r' 'guides-axis.r' 'guides-grid.r' 'hexbin.R' 'labeller.r' 'labels.r' 'layer.r' 'layout.R' 'limits.r' 'margins.R' 'plot-build.r' 'plot-construction.r' 'plot-last.r' 'plot.r' 'position-.r' 'position-collide.r' 'position-dodge.r' 'position-identity.r' 'position-jitter.r' 'position-jitterdodge.R' 'position-nudge.R' 'position-stack.r' 'quick-plot.r' 'range.r' 'save.r' 'scale-.r' 'scale-alpha.r' 'scale-brewer.r' 'scale-continuous.r' 'scale-date.r' 'scale-discrete-.r' 'scale-gradient.r' 'scale-grey.r' 'scale-hue.r' 'scale-identity.r' 'scale-linetype.r' 'scale-manual.r' 'scale-shape.r' 'scale-size.r' 'scale-type.R' 'scales-.r' 'stat-bin.r' 'stat-bin2d.r' 'stat-bindot.r' 'stat-binhex.r' 'stat-boxplot.r' 'stat-contour.r' 'stat-count.r' 'stat-density-2d.r' 'stat-density.r' 'stat-ecdf.r' 'stat-ellipse.R' 'stat-function.r' 'stat-identity.r' 'stat-qq.r' 'stat-quantile.r' 'stat-smooth-methods.r' 'stat-smooth.r' 'stat-sum.r' 'stat-summary-2d.r' 'stat-summary-bin.R' 'stat-summary-hex.r' 'stat-summary.r' 'stat-unique.r' 'stat-ydensity.r' 'summary.r' 'theme-elements.r' 'theme.r' 'theme-defaults.r' 'theme-current.R' 'translate-qplot-ggplot.r' 'translate-qplot-lattice.r' 'utilities-break.r' 'utilities-grid.r' 'utilities-help.r' 'utilities-matrix.r' 'utilities-resolution.r' 'utilities-table.r' 'zxx.r' 'zzz.r'
VignetteBuilder knitr
NeedsCompilation no
Packaged 2016-12-30 17:10:52 UTC; hadley
Repository CRAN
Date/Publication 2016-12-30 22:45:17

Include our badge in your README