Skip to content
An implementation of the Grammar of Graphics in R
R
Branch: master
Clone or download

Latest commit

Files

Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.github Explicitly specify the R version on test-coverage action (#3981) May 3, 2020
R Minor documentation fixes. (#4026) May 25, 2020
data-raw Update economics data (#2962) Mar 6, 2019
data Update economics data (#2962) Mar 6, 2019
icons seq function calls should use full name of 'length.out' (#3817) Feb 12, 2020
inst Correct url link in citation (#3077) Jan 19, 2019
man Minor documentation fixes. (#4026) May 25, 2020
pkgdown/favicon Use retina logo and generate favicons Nov 13, 2018
revdep revdep update (#3808) Mar 3, 2020
tests Fix geom_ribbon() on non-cartesian Coords (#4025) May 25, 2020
vignettes Fix the name of Albert H. Munsell (#3947) Apr 13, 2020
.Rbuildignore Don't send profiling vignette to CRAN Jan 10, 2020
.gitattributes Avoid merge conflicts in NEWS file Feb 25, 2014
.gitignore Ignore docs dir Jan 5, 2019
.travis.yml Test R 4.0 on CI (#3961) Apr 29, 2020
CODE_OF_CONDUCT.md Move CODE_OF_CONDUCT.md to the main directory (#2973) Nov 2, 2018
CONTRIBUTING.md Fixed broken link to CODE_OF_CONDUCT.md (#3288) Jun 4, 2019
DESCRIPTION Configurable qualitative color scales (#3833) May 19, 2020
GOVERNANCE.md add Dewey Dunnington to package authors (#3603, closes #3588) Nov 1, 2019
ISSUE_TEMPLATE.md Updates link to reprex how-to in issues template (#2385) Jan 2, 2018
LICENSE Make GPL-2 license explicit Sep 15, 2016
LICENSE.md Add LICENSE.md Nov 6, 2019
NAMESPACE export binned_scale (#3912) May 18, 2020
NEWS Recreate NEWS.md and move new entry froms NEWS to NEWS.md (#3861) Mar 6, 2020
NEWS.md Better binning algorithm for contours (#4006) May 18, 2020
README.Rmd Move the domain of ggplot2-exts to exts.ggplot2.tidyverse.org (#3920) Apr 16, 2020
README.md Move the domain of ggplot2-exts to exts.ggplot2.tidyverse.org (#3920) Apr 16, 2020
_pkgdown.yml Add link to authors in pkgdown and orchid ID (#3886) May 15, 2020
appveyor.yml Use vdiffr for visual unit tests (#1874) Feb 1, 2017
codecov.yml Enable Github Action (#3862) Mar 15, 2020
cran-comments.md update cran comments Mar 3, 2020
ggplot2.Rproj Upgrade RStudio Jun 1, 2017

README.md

ggplot2

R build status Coverage Status CRAN_Status_Badge

Overview

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.

Installation

# The easiest way to get ggplot2 is to install the whole tidyverse:
install.packages("tidyverse")

# Alternatively, install just ggplot2:
install.packages("ggplot2")

# Or the development version from GitHub:
# install.packages("devtools")
devtools::install_github("tidyverse/ggplot2")

Cheatsheet

Usage

It’s hard to succinctly 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()).

library(ggplot2)

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

Lifecycle

lifecycle

ggplot2 is now over 10 years old and is used by hundreds of thousands of people to make millions of plots. That means, by-and-large, ggplot2 itself changes relatively little. When we do make changes, they will be generally to add new functions or arguments rather than changing the behaviour of existing functions, and if we do make changes to existing behaviour we will do them for compelling reasons.

If you are looking for innovation, look to ggplot2’s rich ecosystem of extensions. See a community maintained list at https://exts.ggplot2.tidyverse.org/gallery/.

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 for communication 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 get you up to speed with the essentials of ggplot2 as quickly as possible.

  2. If you’d like to take an online course, try Data Visualization in R With ggplot2 by Kara Woo.

  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.

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 graphics specifically tailored to your needs. The book is not available for free, but you can find the complete source for the book at https://github.com/hadley/ggplot2-book.

Getting help

There are two main places to get help with ggplot2:

  1. The RStudio community is a friendly place to ask any questions about ggplot2.

  2. Stack Overflow 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.

You can’t perform that action at this time.