### CONTRIBUTING # Contributing to ggplot2 development The goal of this guide is to help you get up and contributing to ggplot2 as quickly as possible. The guide is divided into two main pieces: 1. Filing a bug report or feature request in an issue. 1. Suggesting a change via a pull request. Please note that ggplot2 is released with a [Contributor Code of Conduct](.github/CODE_OF_CONDUCT.md). By contributing to this project, you agree to abide by its terms. ## Issues When filing an issue, the most important thing is to include a minimal reproducible example so that we can quickly verify the problem, and then figure out how to fix it. There are three things you need to include to make your example reproducible: required packages, data, code. 1. **Packages** should be loaded at the top of the script, so it's easy to see which ones the example needs. 1. The easiest way to include **data** is to use `dput()` to generate the R code to recreate it. For example, to recreate the `mtcars` dataset in R, I'd perform the following steps: 1. Run `dput(mtcars)` in R 2. Copy the output 3. In my reproducible script, type `mtcars <- ` then paste. But even better is if you can create a `data.frame()` with just a handful of rows and columns that still illustrates the problem. 1. Spend a little bit of time ensuring that your **code** is easy for others to read: * make sure you've used spaces and your variable names are concise, but informative * use comments to indicate where your problem lies * do your best to remove everything that is not related to the problem. The shorter your code is, the easier it is to understand. You can check you have actually made a reproducible example by starting up a fresh R session and pasting your script in. (Unless you've been specifically asked for it, please don't include the output of `sessionInfo()`.) ## Pull requests To contribute a change to ggplot2, you follow these steps: 1. Create a branch in git and make your changes. 1. Push branch to github and issue pull request (PR). 1. Discuss the pull request. 1. Iterate until either we accept the PR or decide that it's not a good fit for ggplot2. Each of these steps are described in more detail below. This might feel overwhelming the first time you get set up, but it gets easier with practice. If you get stuck at any point, please reach out for help on the [ggplot2-dev](https://groups.google.com/forum/#!forum/ggplot2-dev) mailing list. If you're not familiar with git or github, please start by reading Pull requests will be evaluated against a seven point checklist: 1. __Motivation__. Your pull request should clearly and concisely motivate the need for change. Unfortunately neither Winston nor I have much time to work on ggplot2 these days, so you need to describe the problem and show how your pull request solves it as concisely as possible. Also include this motivation in `NEWS` so that when a new release of ggplot2 comes out it's easy for users to see what's changed. Add your item at the top of the file and use markdown for formatting. The news item should end with `(@yourGithubUsername, #the_issue_number)`. 1. __Only related changes__. Before you submit your pull request, please check to make sure that you haven't accidentally included any unrelated changes. These make it harder to see exactly what's changed, and to evaluate any unexpected side effects. Each PR corresponds to a git branch, so if you expect to submit multiple changes make sure to create multiple branches. If you have multiple changes that depend on each other, start with the first one and don't submit any others until the first one has been processed. 1. __Use ggplot2 coding style__. Please follow the [official tidyverse style](https://style.tidyverse.org). Maintaining a consistent style across the whole code base makes it much easier to jump into the code. If you're modifying existing ggplot2 code that doesn't follow the style guide, a separate pull request to fix the style would be greatly appreciated. 1. If you're adding new parameters or a new function, you'll also need to document them with [roxygen2](https://github.com/r-lib/roxygen2). Make sure to re-run `devtools::document()` on the code before submitting. 1. If fixing a bug or adding a new feature to a non-graphical function, please add a [testthat](https://github.com/r-lib/testthat) unit test. 1. If fixing a bug in the visual output, please add a visual test. (Instructions to follow soon) 1. If you're adding a new graphical feature, please add a short example to the appropriate function. This seems like a lot of work but don't worry if your pull request isn't perfect. It's a learning process and members of the ggplot2 team will be on hand to help you out. A pull request ("PR") is a process, and unless you've submitted a few in the past it's unlikely that your pull request will be accepted as is. All PRs require review and approval from at least one member of the ggplot2 development team before merge. Finally, remember that ggplot2 is a mature package used by thousands of people. This means that it's extremely difficult (i.e. impossible) to change any existing functionality without breaking someone's code (or another package on CRAN). Please don't submit pull requests that change existing behaviour. Instead, think about how you can add a new feature in a minimally invasive way. --- ### README # ggplot2 ggplot2 website [](https://github.com/tidyverse/ggplot2/actions/workflows/R-CMD-check.yaml) [](https://cran.r-project.org/package=ggplot2) [![Codecov test coverage](https://codecov.io/gh/tidyverse/ggplot2/graph/badge.svg)](https://app.codecov.io/gh/tidyverse/ggplot2) ## Overview ggplot2 is a system for declaratively creating graphics, based on [The Grammar of Graphics](https://link.springer.com/book/10.1007/0-387-28695-0). 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 # 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("pak") pak::pak("tidyverse/ggplot2") ``` ## Cheatsheet 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()`). ``` r library(ggplot2) ggplot(mpg, aes(displ, hwy, colour = class)) + geom_point() ``` Scatterplot of engine displacement versus highway miles per gallon, for 234 cars coloured by 7 'types' of car. The displacement and miles per gallon are inversely correlated. ## Lifecycle [](https://lifecycle.r-lib.org/articles/stages.html) ggplot2 is now 18 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 . ## 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 several good places to start: 1. The [Data Visualization](https://r4ds.hadley.nz/data-visualize) and [Communication](https://r4ds.hadley.nz/communication) chapters in [R for Data Science](https://r4ds.hadley.nz). R for Data Science is designed to give you a comprehensive introduction to the [tidyverse](https://tidyverse.org/), 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](https://learning.oreilly.com/videos/data-visualization-in/9781491963661/) by Kara Woo. 3. If you’d like to follow a webinar, try [Plotting Anything with ggplot2](https://youtu.be/h29g21z0a68) by Thomas Lin Pedersen. 4. If you want to dive into making common graphics as quickly as possible, I recommend [The R Graphics Cookbook](https://r-graphics.org) by Winston Chang. It provides a set of recipes to solve common graphics problems. 5. If you’ve mastered the basics and want to learn more, read [ggplot2: Elegant Graphics for Data Analysis](https://ggplot2-book.org). 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. 6. For articles about announcements and deep-dives you can visit the [tidyverse blog](https://tidyverse.org/tags/ggplot2/). ## Getting help There are two main places to get help with ggplot2: 1. The [Posit Community](https://forum.posit.co/) (formerly RStudio Community) is a friendly place to ask any questions about ggplot2. 2. [Stack Overflow](https://stackoverflow.com/questions/tagged/ggplot2?sort=frequent&pageSize=50) 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. ---