Movatterモバイル変換


[0]ホーム

URL:


ggplot2ggplot2 website

R-CMD-checkCRAN_Status_BadgeCodecov test coverage

Overview

ggplot2 is a system for declaratively creating graphics, based onThe Grammarof Graphics. You provide the data, tell ggplot2 how to map variablesto aesthetics, what graphical primitives to use, and it takes care ofthe 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("pak")pak::pak("tidyverse/ggplot2")

Cheatsheet

ggplot2 cheatsheet

Usage

It’s hard to succinctly describe how ggplot2 works because itembodies a deep philosophy of visualisation. However, in most cases youstart withggplot(), supply a dataset and aesthetic mapping(withaes()). You then add on layers (likegeom_point() orgeom_histogram()), scales(likescale_colour_brewer()), faceting specifications (likefacet_wrap()) and coordinate systems (likecoord_flip()).

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

lifecycle

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

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

Learning ggplot2

If you are new to ggplot2 you are better off starting with asystematic introduction, rather than trying to learn from readingindividual documentation pages. Currently, there are several good placesto start:

  1. TheDataVisualization andCommunication chaptersinR for Data Science. R for DataScience is designed to give you a comprehensive introduction to thetidyverse, and these two chapters willget you up to speed with the essentials of ggplot2 as quickly aspossible.

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

  3. If you’d like to follow a webinar, tryPlotting Anything with ggplot2by Thomas Lin Pedersen.

  4. If you want to dive into making common graphics as quickly aspossible, I recommendThe R GraphicsCookbook by Winston Chang. It provides a set of recipes to solvecommon graphics problems.

  5. If you’ve mastered the basics and want to learn more, readggplot2: Elegant Graphics for DataAnalysis. It describes the theoretical underpinnings of ggplot2 andshows you how all the pieces fit together. This book helps youunderstand the theory that underpins ggplot2, and will help you createnew types of graphics specifically tailored to your needs.

  6. For articles about announcements and deep-dives you can visit thetidyverseblog.

Getting help

There are two main places to get help with ggplot2:

  1. ThePosit Community(formerly RStudio Community) is a friendly place to ask any questionsabout ggplot2.

  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 areproducible example that illustrates your problem.


[8]ページ先頭

©2009-2025 Movatter.jp