1 2<!-- README.md is generated from README.Rmd. Please edit that file --> 3 4# ggplot2 <img src="man/figures/logo.png" align="right" width="120" /> 5 6[![R build 7status](https://github.com/tidyverse/ggplot2/workflows/R-CMD-check/badge.svg)](https://github.com/tidyverse/ggplot2/actions) 8[![Coverage 9Status](https://img.shields.io/codecov/c/github/tidyverse/ggplot2/master.svg)](https://codecov.io/github/tidyverse/ggplot2?branch=master) 10[![CRAN\_Status\_Badge](https://www.r-pkg.org/badges/version/ggplot2)](https://cran.r-project.org/package=ggplot2) 11 12## Overview 13 14ggplot2 is a system for declaratively creating graphics, based on [The 15Grammar of 16Graphics](https://www.amazon.com/Grammar-Graphics-Statistics-Computing/dp/0387245448/ref=as_li_ss_tl). 17You provide the data, tell ggplot2 how to map variables to aesthetics, 18what graphical primitives to use, and it takes care of the details. 19 20## Installation 21 22``` r 23# The easiest way to get ggplot2 is to install the whole tidyverse: 24install.packages("tidyverse") 25 26# Alternatively, install just ggplot2: 27install.packages("ggplot2") 28 29# Or the development version from GitHub: 30# install.packages("devtools") 31devtools::install_github("tidyverse/ggplot2") 32``` 33 34## Cheatsheet 35 36<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> 37 38## Usage 39 40It’s hard to succinctly describe how ggplot2 works because it embodies a 41deep philosophy of visualisation. However, in most cases you start with 42`ggplot()`, supply a dataset and aesthetic mapping (with `aes()`). You 43then add on layers (like `geom_point()` or `geom_histogram()`), scales 44(like `scale_colour_brewer()`), faceting specifications (like 45`facet_wrap()`) and coordinate systems (like `coord_flip()`). 46 47``` r 48library(ggplot2) 49 50ggplot(mpg, aes(displ, hwy, colour = class)) + 51 geom_point() 52``` 53 54![](man/figures/README-example-1.png)<!-- --> 55 56## Lifecycle 57 58[![lifecycle](https://img.shields.io/badge/lifecycle-stable-brightgreen.svg)](https://lifecycle.r-lib.org/articles/stages.html) 59 60ggplot2 is now over 10 years old and is used by hundreds of thousands of 61people to make millions of plots. That means, by-and-large, ggplot2 62itself changes relatively little. When we do make changes, they will be 63generally to add new functions or arguments rather than changing the 64behaviour of existing functions, and if we do make changes to existing 65behaviour we will do them for compelling reasons. 66 67If you are looking for innovation, look to ggplot2’s rich ecosystem of 68extensions. See a community maintained list at 69<https://exts.ggplot2.tidyverse.org/gallery/>. 70 71## Learning ggplot2 72 73If you are new to ggplot2 you are better off starting with a systematic 74introduction, rather than trying to learn from reading individual 75documentation pages. Currently, there are three good places to start: 76 771. The [Data 78 Visualisation](https://r4ds.had.co.nz/data-visualisation.html) and 79 [Graphics for 80 communication](https://r4ds.had.co.nz/graphics-for-communication.html) 81 chapters in [R for Data Science](https://r4ds.had.co.nz). R for Data 82 Science is designed to give you a comprehensive introduction to the 83 [tidyverse](https://www.tidyverse.org), and these two chapters will 84 get you up to speed with the essentials of ggplot2 as quickly as 85 possible. 86 872. If you’d like to take an online course, try [Data Visualization in R 88 With 89 ggplot2](https://learning.oreilly.com/videos/data-visualization-in/9781491963661/) 90 by Kara Woo. 91 923. If you’d like to follow a webinar, try [Plotting Anything with 93 ggplot2](https://youtu.be/h29g21z0a68) by Thomas Lin Pedersen. 94 954. If you want to dive into making common graphics as quickly as 96 possible, I recommend [The R Graphics 97 Cookbook](https://r-graphics.org) by Winston Chang. It provides a 98 set of recipes to solve common graphics problems. 99 100If you’ve mastered the basics and want to learn more, read [ggplot2: 101Elegant Graphics for Data Analysis](https://ggplot2-book.org). It 102describes the theoretical underpinnings of ggplot2 and shows you how all 103the pieces fit together. This book helps you understand the theory that 104underpins ggplot2, and will help you create new types of graphics 105specifically tailored to your needs. 106 107## Getting help 108 109There are two main places to get help with ggplot2: 110 1111. The [RStudio community](https://community.rstudio.com/) is a 112 friendly place to ask any questions about ggplot2. 113 1142. [Stack 115 Overflow](https://stackoverflow.com/questions/tagged/ggplot2?sort=frequent&pageSize=50) 116 is a great source of answers to common ggplot2 questions. It is also 117 a great place to get help, once you have created a reproducible 118 example that illustrates your problem. 119