Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
9 contributors

Users who have contributed to this file

@hadley @batpigandme @StefanBRas @wibeasley @karawoo @dvcv @delferts @darrkj @dpseidel
106 lines (73 sloc) 5.1 KB
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, echo = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-"
)
```
# ggplot2 <img src="man/figures/logo.png" align="right" width="120" />
[![Travis Build Status](https://travis-ci.org/tidyverse/ggplot2.svg?branch=master)](https://travis-ci.org/tidyverse/ggplot2)
[![AppVeyor Build Status](https://ci.appveyor.com/api/projects/status/github/tidyverse/ggplot2?branch=master&svg=true)](https://ci.appveyor.com/project/tidyverse/ggplot2)
[![Coverage Status](https://img.shields.io/codecov/c/github/tidyverse/ggplot2/master.svg)](https://codecov.io/github/tidyverse/ggplot2?branch=master)
[![CRAN_Status_Badge](http://www.r-pkg.org/badges/version/ggplot2)](https://cran.r-project.org/package=ggplot2)
## Overview
ggplot2 is a system for declaratively creating graphics, based on [The Grammar of Graphics](http://amzn.to/2ef1eWp). 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
```{r, eval = FALSE}
# The easiest way to get ggplot2 is to install the whole tidyverse:
install.packages("tidyverse")
# Alternatively, install just ggplot2:
install.packages("ggplot2")
# Or the the development version from GitHub:
# install.packages("devtools")
devtools::install_github("tidyverse/ggplot2")
```
## Cheatsheet
<a href="https://github.com/rstudio/cheatsheets/blob/master/data-visualization-2.1.pdf"><img src="https://raw.githubusercontent.com/rstudio/cheatsheets/master/pngs/thumbnails/data-visualization-cheatsheet-thumbs.png" width="630" height="252"/></a>
## 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()`).
```{r example}
library(ggplot2)
ggplot(mpg, aes(displ, hwy, colour = class)) +
geom_point()
```
## Lifecycle
[![lifecycle](https://img.shields.io/badge/lifecycle-stable-brightgreen.svg)](https://www.tidyverse.org/lifecycle/#stable)
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 <http://www.ggplot2-exts.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][r4ds-vis] and
[graphics for communication][r4ds-comm] chapters in
[R for data science][r4ds]. R for data science is designed to
give you a comprehensive introduction to the
[tidyverse](http://tidyverse.org), and these two chapters will
get you up to speed with the essentials of ggplot2 as quickly as
possible.
1. If you'd like to take an online course, try
[Data Visualization in R With ggplot2][oreilly] by Kara Woo.
1. If you want to dive into making common graphics as quickly
as possible, I recommend [The R Graphics Cookbook][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][ggplot2-book]. 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][community] is a friendly place to ask any
questions about ggplot2.
1. [Stack Overflow][so] 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.
[community]: https://community.rstudio.com/
[ggplot2-book]: http://amzn.to/2fncG50
[gg-book]: http://amzn.to/2ef1eWp
[so]: http://stackoverflow.com/questions/tagged/ggplot2?sort=frequent&pageSize=50
[cookbook]: https://amzn.to/2TU78ip
[r4ds]: http://r4ds.had.co.nz
[r4ds-vis]: http://r4ds.had.co.nz/data-visualisation.html
[r4ds-comm]: http://r4ds.had.co.nz/graphics-for-communication.html
[oreilly]: http://shop.oreilly.com/product/0636920052807.do
You can’t perform that action at this time.