R 패키지 메타데이터와 수집 신호를 모아 봅니다.
첫 화면에서 판단해야 할 수집 신호를 먼저 배치합니다.
DESCRIPTION에서 감지한 backend 관련 package입니다.
기본 메타데이터를 작은 카드와 토큰으로 압축합니다.
sp| Package | Type | Spec |
|---|---|---|
| cli CRAN · 4.0.3 · 2026-05-30 | Imports | cli |
| grDevices CRAN · 4.0.3 · 2026-05-30 | Imports | grDevices |
| grid CRAN · 4.0.3 · 2026-05-30 | Imports | grid |
| gtable CRAN · 4.0.3 · 2026-05-30 | Imports | gtable (>= 0.3.6) |
| isoband CRAN · 4.0.3 · 2026-05-30 | Imports | isoband |
| lifecycle CRAN · 4.0.3 · 2026-05-30 | Imports | lifecycle (> 1.0.1) |
| rlang CRAN · 4.0.3 · 2026-05-30 | Imports | rlang (>= 1.1.0) |
| S7 CRAN · 4.0.3 · 2026-05-30 | Imports | S7 |
| scales CRAN · 4.0.3 · 2026-05-30 | Imports | scales (>= 1.4.0) |
| stats CRAN · 4.0.3 · 2026-05-30 | Imports | stats |
| vctrs CRAN · 4.0.3 · 2026-05-30 | Imports | vctrs (>= 0.6.0) |
| withr CRAN · 4.0.3 · 2026-05-30 | Imports | withr (>= 2.5.0) |
| broom CRAN · 4.0.3 · 2026-05-30 | Suggests | broom |
| covr CRAN · 4.0.3 · 2026-05-30 | Suggests | covr |
| dplyr CRAN · 4.0.3 · 2026-05-30 | Suggests | dplyr |
| ggplot2movies CRAN · 4.0.3 · 2026-05-30 | Suggests | ggplot2movies |
| hexbin CRAN · 4.0.3 · 2026-05-30 | Suggests | hexbin |
| Hmisc CRAN · 4.0.3 · 2026-05-30 | Suggests | Hmisc |
| hms CRAN · 4.0.3 · 2026-05-30 | Suggests | hms |
| knitr CRAN · 4.0.3 · 2026-05-30 | Suggests | knitr |
| mapproj CRAN · 4.0.3 · 2026-05-30 | Suggests | mapproj |
| maps CRAN · 4.0.3 · 2026-05-30 | Suggests | maps |
| MASS CRAN · 4.0.3 · 2026-05-30 | Suggests | MASS |
| mgcv CRAN · 4.0.3 · 2026-05-30 | Suggests | mgcv |
| multcomp CRAN · 4.0.3 · 2026-05-30 | Suggests | multcomp |
| munsell CRAN · 4.0.3 · 2026-05-30 | Suggests | munsell |
| nlme CRAN · 4.0.3 · 2026-05-30 | Suggests | nlme |
| profvis CRAN · 4.0.3 · 2026-05-30 | Suggests | profvis |
| quantreg CRAN · 4.0.3 · 2026-05-30 | Suggests | quantreg |
| quarto CRAN · 4.0.3 · 2026-05-30 | Suggests | quarto |
| ragg CRAN · 4.0.3 · 2026-05-30 | Suggests | ragg (>= 1.2.6) |
| RColorBrewer CRAN · 4.0.3 · 2026-05-30 | Suggests | RColorBrewer |
| roxygen2 CRAN · 4.0.3 · 2026-05-30 | Suggests | roxygen2 |
| rpart CRAN · 4.0.3 · 2026-05-30 | Suggests | rpart |
| sf CRAN · 4.0.3 · 2026-05-30 | Suggests | sf (>= 0.7-3) |
| svglite CRAN · 4.0.3 · 2026-05-30 | Suggests | svglite (>= 2.1.2) |
| testthat CRAN · 4.0.3 · 2026-05-30 | Suggests | testthat (>= 3.1.5) |
| tibble CRAN · 4.0.3 · 2026-05-30 | Suggests | tibble |
| vdiffr CRAN · 4.0.3 · 2026-05-30 | Suggests | vdiffr (>= 1.0.6) |
| xml2 CRAN · 4.0.3 · 2026-05-30 | Suggests | xml2 |
| sp CRAN · 4.0.3 · 2026-05-30 | Enhances | sp |
| 검색 결과가 없습니다. | ||
| Package | Type | Spec |
|---|---|---|
| accessrmd 1.0.0 CRAN · 2026-05-30 | Depends | ggplot2 |
| AFheritability 0.1.0 CRAN · 2026-05-08 | Depends | ggplot2 |
| afmToolkit 1.0.0 CRAN · 2026-05-30 | Depends | ggplot2 |
| alakazam 1.4.3 CRAN · 2026-05-30 | Depends | ggplot2 (>= 3.4.0) |
| alookr 0.5.1 CRAN · 2026-05-30 | Depends | ggplot2 (>= 3.0.0) |
| AmpliconDuo 1.1.1 CRAN · 2026-05-30 | Depends | ggplot2 |
| Anaconda 0.1.5 CRAN · 2026-05-30 | Depends | ggplot2 |
| apisensr 2.0.0 CRAN · 2026-05-30 | Depends | ggplot2 (>= 3.5.0) |
| applicable 0.2.1 CRAN · 2026-05-30 | Depends | ggplot2 (>= 4.0.2) |
| ausplotsR 2.0.5 CRAN · 2026-05-30 | Depends | ggplot2 |
| BasketballAnalyzeR 0.8.1 CRAN · 2026-05-30 | Depends | ggplot2 (>= 3.4.0) |
| bayesDP 1.3.7 CRAN · 2026-05-30 | Depends | ggplot2 |
| bayesnec 2.1.3.1 CRAN · 2026-05-30 | Depends | ggplot2 |
| bbnet 1.2.1 CRAN · 2026-05-30 | Depends | ggplot2 |
| bde 1.0.1.1 CRAN · 2026-05-30 | Depends | ggplot2 |
| bhm 1.19 CRAN · 2026-05-30 | Depends | ggplot2 |
| bmscstan 1.2.1.0 CRAN · 2026-05-30 | Depends | ggplot2 |
| bootnet 1.8 CRAN · 2026-05-30 | Depends | ggplot2 |
| bpcp 1.5.1 CRAN · 2026-05-30 | Depends | ggplot2 |
| braidReports 1.0.5 CRAN · 2026-05-30 | Depends | ggplot2 |
| bunching 0.8.6 CRAN · 2026-05-30 | Depends | ggplot2 (>= 3.1.1) |
| CalibrationCurves 3.1.0 CRAN · 2026-05-30 | Depends | ggplot2 |
| caret 7.0-1 CRAN · 2026-05-30 | Depends | ggplot2 |
| ceterisParibus 0.6 CRAN · 2026-05-30 | Depends | ggplot2 |
| cfda 0.12.1 CRAN · 2026-05-30 | Depends | ggplot2 |
| changepoint.geo 1.0.3 CRAN · 2026-05-30 | Depends | ggplot2 |
| changeS 1.0.1 CRAN · 2026-05-30 | Depends | ggplot2 |
| circhelp 1.1 CRAN · 2026-05-30 | Depends | ggplot2 |
| cjoint 2.1.3 CRAN · 2026-05-30 | Depends | ggplot2 |
| ClassificationEnsembles 1.0.2 CRAN · 2026-05-30 | Depends | ggplot2 |
| classifierplots 1.4.0 CRAN · 2026-05-30 | Depends | ggplot2 (>= 2.2) |
| clustEff 0.3.1 CRAN · 2026-05-30 | Depends | ggplot2 |
| ClusteredMutations 1.0.2 CRAN · 2026-05-30 | Depends | ggplot2 |
| clustrd 1.4.0 CRAN · 2026-05-30 | Depends | ggplot2 |
| CNVScope 3.7.2 CRAN · 2026-05-30 | Depends | ggplot2 |
| coefplot 1.2.9 CRAN · 2026-05-30 | Depends | ggplot2 (>= 2.0.0) |
| cohorttools 0.1.8 CRAN · 2026-05-30 | Depends | ggplot2 |
| ConconiAnaerobicThresholdTest 1.0.0 CRAN · 2026-05-30 | Depends | ggplot2 |
| ContourFunctions 0.1.2 CRAN · 2026-05-30 | Depends | ggplot2 |
| corkscrew 1.1 CRAN · 2026-05-30 | Depends | ggplot2 |
| CoSMoS 2.2.0 CRAN · 2026-05-30 | Depends | ggplot2 |
| CRABS 1.2.0 CRAN · 2026-05-30 | Depends | ggplot2 |
| crmPack 2.1.0 CRAN · 2026-05-30 | Depends | ggplot2 (>= 3.0.0) |
| Crossover 0.1-22 CRAN · 2026-05-30 | Depends | ggplot2 |
| CRTgeeDR 2.0.1 CRAN · 2026-05-30 | Depends | ggplot2 |
| CTxCC 0.4.0 CRAN · 2026-05-30 | Depends | ggplot2 |
| cystiSim 0.1.0 CRAN · 2026-05-30 | Depends | ggplot2 |
| cytofan 0.1.1 CRAN · 2026-05-30 | Depends | ggplot2 (>= 2.2.0) |
| dae 3.2.32 CRAN · 2026-05-30 | Depends | ggplot2 |
| dampack 1.0.2.1000 CRAN · 2026-05-30 | Depends | ggplot2 (>= 3.3.0) |
| dartR 2.9.9.5 CRAN · 2026-05-30 | Depends | ggplot2 |
| dartR.base 1.2.3 CRAN · 2026-05-30 | Depends | ggplot2 |
| dartR.sim 1.2.2 CRAN · 2026-05-30 | Depends | ggplot2 |
| ddecompose 1.0.0 CRAN · 2026-05-30 | Depends | ggplot2 |
| Deducer 0.9-2 CRAN · 2026-05-30 | Depends | ggplot2 (>= 2.0.0) |
| DendroSync 0.1.5 CRAN · 2026-05-30 | Depends | ggplot2 |
| DepthProc 2.1.6 CRAN · 2026-05-30 | Depends | ggplot2 |
| DHBins 1.1 CRAN · 2026-05-30 | Depends | ggplot2 |
| diathor 0.1.5 CRAN · 2026-05-30 | Depends | ggplot2 |
| diffEnrich 0.1.2 CRAN · 2026-05-30 | Depends | ggplot2 |
| diffeR 0.0-8 CRAN · 2026-05-30 | Depends | ggplot2 |
| DiSCos 0.1.3 CRAN · 2026-05-30 | Depends | ggplot2 |
| dittoViz 1.0.6 CRAN · 2026-05-30 | Depends | ggplot2 |
| dnn 0.0.7 CRAN · 2026-05-30 | Depends | ggplot2 |
| donutsk 0.1.1 CRAN · 2026-05-30 | Depends | ggplot2 (>= 3.5.0) |
| dotwhisker 0.8.4 CRAN · 2026-05-30 | Depends | ggplot2 (>= 2.2.1) |
| dowser 2.4.1 CRAN · 2026-05-30 | Depends | ggplot2 (>= 3.4.0) |
| dpGMM 1.0.0 CRAN · 2026-05-30 | Depends | ggplot2 |
| dslice 1.2.2 CRAN · 2026-05-30 | Depends | ggplot2 (>= 0.9.3.1) |
| dynr 0.1.16-114 CRAN · 2026-05-30 | Depends | ggplot2 |
| Eagle 2.5 CRAN · 2026-05-30 | Depends | ggplot2 |
| echoice2 0.2.5 CRAN · 2026-05-30 | Depends | ggplot2 |
| eeptools 1.2.7 CRAN · 2026-05-30 | Depends | ggplot2 |
| egg 0.4.5 CRAN · 2026-05-30 | Depends | ggplot2 |
| embryogrowth 2025.12.22 CRAN · 2026-05-30 | Depends | ggplot2 |
| EnsCat 1.1 CRAN · 2026-05-30 | Depends | ggplot2 |
| EpiCurve 2.4-2 CRAN · 2026-05-30 | Depends | ggplot2 |
| episensr 2.1.0 CRAN · 2026-05-30 | Depends | ggplot2 (>= 4.0.0) |
| EQUALCompareImages 0.1.0 CRAN · 2026-05-30 | Depends | ggplot2 |
| EQUALPrognosis 0.1.3 CRAN · 2026-05-30 | Depends | ggplot2 |
| EQUALrepeat 0.4.5 CRAN · 2026-05-30 | Depends | ggplot2 |
| eVCGsampler 1.0.0 CRAN · 2026-05-30 | Depends | ggplot2 |
| FactoClass 1.2.9 CRAN · 2026-05-30 | Depends | ggplot2 |
| factoextra 2.0.0 CRAN · 2026-05-30 | Depends | ggplot2 (>= 3.5.2) |
| factorplot 1.3 CRAN · 2026-05-30 | Depends | ggplot2 |
| Factoshiny 2.7 CRAN · 2026-05-30 | Depends | ggplot2 |
| fbroc 0.4.1 CRAN · 2026-05-30 | Depends | ggplot2 |
| findGSEP 1.2.0 CRAN · 2026-05-30 | Depends | ggplot2 |
| FisherEM 1.6 CRAN · 2026-05-30 | Depends | ggplot2 |
| flippant 1.5.7 CRAN · 2026-05-30 | Depends | ggplot2 (>= 2.2.1) |
| ForecastingEnsembles 0.5.1 CRAN · 2026-05-30 | Depends | ggplot2 |
| forestmodel 0.6.2 CRAN · 2026-05-30 | Depends | ggplot2 (>= 3.1.0) |
| FormulR 1.0.0 CRAN · 2026-05-30 | Depends | ggplot2 |
| freqparcoord 1.0.1 CRAN · 2026-05-30 | Depends | ggplot2 |
| frequency 0.4.1 CRAN · 2026-05-30 | Depends | ggplot2 |
| func2vis 1.0-3 CRAN · 2026-05-30 | Depends | ggplot2 |
| funMoDisco 1.1.5 CRAN · 2026-05-30 | Depends | ggplot2 |
| gam.hp 0.0-5 CRAN · 2026-05-30 | Depends | ggplot2 |
| gapmap 1.0.0 CRAN · 2026-05-30 | Depends | ggplot2 |
| garma 1.0.1 CRAN · 2026-05-30 | Depends | ggplot2 |
| gcerisk 19.05.24 CRAN · 2026-05-30 | Depends | ggplot2 |
| gde 0.2.1 CRAN · 2026-05-30 | Depends | ggplot2 |
| GenericML 0.2.2 CRAN · 2026-05-30 | Depends | ggplot2 |
| genlogis 1.0.2 CRAN · 2026-05-30 | Depends | ggplot2 |
| geomtextpath 0.2.0 CRAN · 2026-05-30 | Depends | ggplot2 (>= 3.5.2) |
| geotoolsR 1.2.1 CRAN · 2026-05-30 | Depends | ggplot2 |
| GerminaR 2.1.6 CRAN · 2026-05-30 | Depends | ggplot2 |
| ggalign 1.2.0 CRAN · 2026-05-30 | Depends | ggplot2 (>= 4.0.0) |
| ggallin 0.1.2 CRAN · 2026-05-30 | Depends | ggplot2 (>= 2.2.1) |
| ggalluvial 0.12.6 CRAN · 2026-05-30 | Depends | ggplot2 (>= 2.2) |
| GGally 2.4.0 CRAN · 2026-05-30 | Depends | ggplot2 (>= 3.5.2) |
| gganimate 1.0.11 CRAN · 2026-05-30 | Depends | ggplot2 (>= 3.5.2) |
| ggarrow 0.1.1 CRAN · 2026-05-30 | Depends | ggplot2 (>= 3.5.0) |
| ggbeeswarm 0.7.3 CRAN · 2026-05-30 | Depends | ggplot2 (>= 3.3.0) |
| ggbiplot 0.6.2 CRAN · 2026-05-30 | Depends | ggplot2 |
| ggbuildr 0.1.0 CRAN · 2026-05-30 | Depends | ggplot2 |
| ggcharts 0.2.1 CRAN · 2026-05-30 | Depends | ggplot2 (>= 3.0.0) |
| ggcorrplot 0.1.4.1 CRAN · 2026-05-30 | Depends | ggplot2 (>= 3.3.6) |
| ggcube 0.1.0 CRAN · 2026-05-30 | Depends | ggplot2 |
| ggdemetra 0.2.9 CRAN · 2026-05-30 | Depends | ggplot2 (>= 2.0.0) |
| 검색 결과가 없습니다. | ||
| Type | Packages |
|---|---|
| Depends | 397 |
| Imports | 4,236 |
| Suggests | 1,905 |
| Enhances | 6 |
CRAN: ggplot2 citation info To cite ggplot2 in publications, please use Wickham H (2016). ggplot2: Elegant Graphics for Data Analysis . Springer-Verlag New York. ISBN 978-3-319-24277-4, https://ggplot2.tidyverse.org . Corresponding BibTeX entry: @Book{, author = {Hadley Wickham}, title = {ggplot2: Elegant Graphics for Data Analysis}, publisher = {Springer-Verlag New York}, year = {2016}, isbn = {978-3-319-24277-4}, url = {https://ggplot2.tidyverse.org}, }NEWS code{white-space: pre-wrap;} span.smallcaps{font-variant: small-caps;} span.underline{text-decoration: underline;} div.column{display: inline-block; vertical-align: top; width: 50%;} div.hanging-indent{margin-left: 1.5em; text-indent: -1.5em;} ul.task-list{list-style: none;} pre > code.sourceCode { white-space: pre; position: relative; } pre > code.sourceCode > span { display: inline-block; line-height: 1.25; } pre > code.sourceCode > span:empty { height: 1.2em; } .sourceCode { overflow: visible; } code.sourceCode > span { color: inherit; text-decoration: inherit; } div.sourceCode { margin: 1em 0; } pre.sourceCode { margin: 0; } @media screen { div.sourceCode { overflow: auto; } } @media print { pre > code.sourceCode { white-space: pre-wrap; } pre > code.sourceCode > span { text-indent: -5em; padding-left: 5em; } } pre.numberSource code { counter-reset: source-line 0; } pre.numberSource code > span { position: relative; left: -4em; counter-increment: source-line; } pre.numberSource code > span > a:first-child::before { content: counter(source-line); position: relative; left: -1em; text-align: right; vertical-align: baseline; border: none; display: inline-block; -webkit-touch-callout: none; -webkit-user-select: none; -khtml-user-select: none; -moz-user-select: none; -ms-user-select: none; user-select: none; padding: 0 4px; width: 4em; color: #aaaaaa; } pre.numberSource { margin-left: 3em; border-left: 1px solid #aaaaaa; padding-left: 4px; } div.sourceCode { } @media screen { pre > code.sourceCode > span > a:first-child::before { text-decoration: underline; } } code span.al { color: #ff0000; font-weight: bold; } /* Alert */ code span.an { color: #60a0b0; font-weight: bold; font-style: italic; } /* Annotation */ code span.at { color: #7d9029; } /* Attribute */ code span.bn { color: #40a070; } /* BaseN */ code span.bu { color: #008000; } /* BuiltIn */ code span.cf { color: #007020; font-weight: bold; } /* ControlFlow */ code span.ch { color: #4070a0; } /* Char */ code span.cn { color: #880000; } /* Constant */ code span.co { color: #60a0b0; font-style: italic; } /* Comment */ code span.cv { color: #60a0b0; font-weight: bold; font-style: italic; } /* CommentVar */ code span.do { color: #ba2121; font-style: italic; } /* Documentation */ code span.dt { color: #902000; } /* DataType */ code span.dv { color: #40a070; } /* DecVal */ code span.er { color: #ff0000; font-weight: bold; } /* Error */ code span.ex { } /* Extension */ code span.fl { color: #40a070; } /* Float */ code span.fu { color: #06287e; } /* Function */ code span.im { color: #008000; font-weight: bold; } /* Import */ code span.in { color: #60a0b0; font-weight: bold; font-style: italic; } /* Information */ code span.kw { color: #007020; font-weight: bold; } /* Keyword */ code span.op { color: #666666; } /* Operator */ code span.ot { color: #007020; } /* Other */ code span.pp { color: #bc7a00; } /* Preprocessor */ code span.sc { color: #4070a0; } /* SpecialChar */ code span.ss { color: #bb6688; } /* SpecialString */ code span.st { color: #4070a0; } /* String */ code span.va { color: #19177c; } /* Variable */ code span.vs { color: #4070a0; } /* VerbatimString */ code span.wa { color: #60a0b0; font-weight: bold; font-style: italic; } /* Warning */ ggplot2 4.0.3 This is a hotfix release fixing a test, a bug and introducing a feature. Adapt to changes in rlang::warn_dots_used() ( @lionel -, #6830). Fixed bug where guide_axis_theta() didn’t anticipate old-style text elements (#6803). geom_boxplot() / stat_boxplot() gain a quantile.type parameter (default 7 ) to control the percentile definition used for hinges and median; set quantile.type = 2 to match SAS’s default PCTLDEF = 5 , enabling parity with SAS boxplots out-of-the-box. ( @munoztd0 , #6819) ggplot2 4.0.2 This hotfix release makes ggplot2 more interoperable between rlang versions. make_constructor() no longer captures rlang::list2() at build time. ggplot2 4.0.1 This is a smaller patch release focussed on fixing regressions from 4.0.0 and polishing the recent features. Bug fixes Fixed regression where geom_area() didn’t draw panels with single groups when stat = "align" ( @teunbrand , #6680) Fixed regression where position_stack(vjust) was ignored when there are only single groups (#6692) Fixed bug where NA handling in geom_path() was ignoring panels ( @teunbrand , #6533) Fixed bug where stat_bin(boundary) was ignored (#6682). geom_text() and geom_label() accept expressions as the label aesthetic ( @teunbrand , #6638) Fixed regression where draw_key_rect() stopped using fill colours ( @mitchelloharawild , #6609). Fixed regression where scale_{x,y}_*() threw an error when an expression object is set to labels argument ( @yutannihilation , #6617). Fixed regression where the first (unnamed) argument to colour/fill scales was not passed as the name argument ( @teunbrand , #6623) Fixed issue where vectorised arrow() s caused errors in drawing the legend glyphs ( @teunbrand , #6594) Fixed regression where NULL -aesthetics contributed to plot labels too insistently. Now they contribute only as fallback labels ( @teunbrand , #6616) Fixed regression where empty arguments to colour/fill scale caused errors ( @jmbarbone , #6710) Fixed axis misplacement in coor_radial() when labels are blank ( @teunbrand , #6574) Improvements Improved palette fallback mechanism in scales ( @teunbrand , #6669). Allow stat in geom_hline , geom_vline , and geom_abline . ( @sierrajohnson , #6559) stat_boxplot() treats width as an optional aesthetic ( @Yunuuuu , #6575) The theme(panel.widths, panel.heights) setting attempts to preserve the plot’s aspect ratio when only one of the two settings is given, and the plot has a single panel ( @teunbrand , #6701). Logical values for the linetype aesthetic will be interpreted numerically, so that linetype = FALSE becomes 0/‘blank’ and linetype = TRUE becomes 1/‘solid’ ( @teunbrand , #6641) Out-of-bounds datapoints used as padding by stat_align() now get removed silently rather than verbosely ( @teunbrand , #6667) ggplot2 4.0.0 User facing Breaking changes The S3 parts of ggplot2 have been replaced with S7 bits (#6352). (breaking) geom_violin(quantiles) now has actual quantiles based on the data, rather than inferred quantiles based on the computed density. The quantiles parameter that replaces draw_quantiles now belongs to stat_ydensity() instead of geom_violin() ( @teunbrand , #4120). (Breaking) The defaults for all geoms can be set at one in the theme. ( @teunbrand based on pioneering work by @dpseidel , #2239) A new theme(geom) argument is used to track these defaults. The element_geom() function can be used to populate that argument. The from_theme() function allows access to the theme default fields from inside the aes() function. Moved the following packages in the description. If your package depended on ggplot2 to install these dependencies, you may need to list these in your own DESCRIPTION file now (#5986). Moved mgcv from Imports to Suggests Moved tibble from Imports to Suggests Removed glue dependency Default labels are derived in build_ggplot() (previously ggplot_build() ) rather than in the layer method of update_ggplot() (previously ggplot_add.Layer() ). This may affect code that accessed the plot$labels property ( @teunbrand , #5894). In binning stats, the default boundary is now chosen to better adhere to the nbin argument. This may affect plots that use default binning ( @teunbrand , #5882, #5036) Lifecycle changes Deprecated functions and arguments prior to ggplot2 3.0.0 throw errors instead of warnings. Functions and arguments that were soft-deprecated up to ggplot2 3.4.0 now throw warnings. annotation_borders() replaces the now-deprecated borders() ( @teunbrand , #6392) Turned off fallback for size to linewidth translation in geom_bar() / geom_col() (#4848). The fatten argument has been deprecated in geom_boxplot() , geom_crossbar() and geom_pointrange() ( @teunbrand , #4881). The following meREADME code{white-space: pre-wrap;} span.smallcaps{font-variant: small-caps;} span.underline{text-decoration: underline;} div.column{display: inline-block; vertical-align: top; width: 50%;} div.hanging-indent{margin-left: 1.5em; text-indent: -1.5em;} ul.task-list{list-style: none;} pre > code.sourceCode { white-space: pre; position: relative; } pre > code.sourceCode > span { display: inline-block; line-height: 1.25; } pre > code.sourceCode > span:empty { height: 1.2em; } .sourceCode { overflow: visible; } code.sourceCode > span { color: inherit; text-decoration: inherit; } div.sourceCode { margin: 1em 0; } pre.sourceCode { margin: 0; } @media screen { div.sourceCode { overflow: auto; } } @media print { pre > code.sourceCode { white-space: pre-wrap; } pre > code.sourceCode > span { text-indent: -5em; padding-left: 5em; } } pre.numberSource code { counter-reset: source-line 0; } pre.numberSource code > span { position: relative; left: -4em; counter-increment: source-line; } pre.numberSource code > span > a:first-child::before { content: counter(source-line); position: relative; left: -1em; text-align: right; vertical-align: baseline; border: none; display: inline-block; -webkit-touch-callout: none; -webkit-user-select: none; -khtml-user-select: none; -moz-user-select: none; -ms-user-select: none; user-select: none; padding: 0 4px; width: 4em; color: #aaaaaa; } pre.numberSource { margin-left: 3em; border-left: 1px solid #aaaaaa; padding-left: 4px; } div.sourceCode { } @media screen { pre > code.sourceCode > span > a:first-child::before { text-decoration: underline; } } code span.al { color: #ff0000; font-weight: bold; } /* Alert */ code span.an { color: #60a0b0; font-weight: bold; font-style: italic; } /* Annotation */ code span.at { color: #7d9029; } /* Attribute */ code span.bn { color: #40a070; } /* BaseN */ code span.bu { color: #008000; } /* BuiltIn */ code span.cf { color: #007020; font-weight: bold; } /* ControlFlow */ code span.ch { color: #4070a0; } /* Char */ code span.cn { color: #880000; } /* Constant */ code span.co { color: #60a0b0; font-style: italic; } /* Comment */ code span.cv { color: #60a0b0; font-weight: bold; font-style: italic; } /* CommentVar */ code span.do { color: #ba2121; font-style: italic; } /* Documentation */ code span.dt { color: #902000; } /* DataType */ code span.dv { color: #40a070; } /* DecVal */ code span.er { color: #ff0000; font-weight: bold; } /* Error */ code span.ex { } /* Extension */ code span.fl { color: #40a070; } /* Float */ code span.fu { color: #06287e; } /* Function */ code span.im { color: #008000; font-weight: bold; } /* Import */ code span.in { color: #60a0b0; font-weight: bold; font-style: italic; } /* Information */ code span.kw { color: #007020; font-weight: bold; } /* Keyword */ code span.op { color: #666666; } /* Operator */ code span.ot { color: #007020; } /* Other */ code span.pp { color: #bc7a00; } /* Preprocessor */ code span.sc { color: #4070a0; } /* SpecialChar */ code span.ss { color: #bb6688; } /* SpecialString */ code span.st { color: #4070a0; } /* String */ code span.va { color: #19177c; } /* Variable */ code span.vs { color: #4070a0; } /* VerbatimString */ code span.wa { color: #60a0b0; font-weight: bold; font-style: italic; } /* Warning */ ggplot2 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("pak") pak :: pak ( "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 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 several good places to start: The Data Visualization and 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. If you’d like to take an online course, try Data Visualization in R With ggplot2 by Kara Woo. If you’d like to follow a webinar, try Plotting Anything with ggplot2 by Thomas Lin Pedersen. 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. For articles about announcements and deep-dives you can visit the tidyverse blog . Getting help There are two main places to get help with ggplot2: The Posit Community (formerly RStudio Community) is a friendly place to ask any questions about ggplot2. 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.Help for package ggplot2 const macros = { "\\R": "\\textsf{R}", "\\mbox": "\\text", "\\code": "\\texttt"}; function processMathHTML() { var l = document.getElementsByClassName('reqn'); for (let e of l) { katex.render(e.textContent, e, { throwOnError: false, macros }); } return; } Package {ggplot2} Contents ggplot2-package Coord CoordSf Facet Geom Guide Layer-class Layout Position Scale Stat absoluteGrob add_gg add_theme aes aes_ aes_all aes_auto aes_colour_fill_alpha aes_eval aes_group_order aes_linetype_size_shape aes_position annotate annotation_borders annotation_custom annotation_logticks annotation_map annotation_raster as.list.ggproto as_labeller autolayer automatic_plotting autoplot benchplot bidirection binned_scale calc_element check_device class_definitions class_ggplot class_ggplot_built class_labels class_mapping class_theme combine_vars complete_theme continuous_scale coord_cartesian coord_fixed coord_flip coord_map coord_munch coord_polar coord_transform cut_interval datetime_scale diamonds discrete_scale draw_key economics element_grob element_render expand_limits expansion facet_grid facet_null facet_wrap faithfuld fill_alpha find_panel fortify fortify-multcomp fortify.lm fortify.map fortify.sp geom_abline geom_bar geom_bin_2d geom_blank geom_boxplot geom_contour geom_count geom_crossbar geom_density geom_density_2d geom_dotplot geom_freqpoly geom_function geom_hex geom_jitter geom_label geom_map geom_path geom_point geom_polygon geom_qq_line geom_quantile geom_raster geom_ribbon geom_rug geom_segment geom_smooth geom_spoke geom_violin get_alt_text get_geom_defaults get_guide_data get_last_plot get_strip_labels get_theme gg_dep gg_par ggplot ggplot2-ggproto ggplotGrob ggplot_build ggplot_gtable ggproto ggsave ggtheme graphical-units guide_axis guide_axis_logticks guide_axis_stack guide_axis_theta guide_bins guide_colourbar guide_coloursteps guide_custom guide_legend guide_none guides hmisc ignoring_data is_ggproto is_rel label_bquote labeller labellers labs layer layer_geoms layer_positions layer_sf layer_stats limits lims luv_colours make_constructor map_data margin max_height mean_se merge_element midwest mpg msleep new_guide old_guide pattern_alpha position_dodge position_identity position_jitter position_jitterdodge position_nudge position_stack presidential print.ggplot print.ggproto qplot reexports register_theme_elements remove_missing render_axes render_strips resolution scale_alpha scale_binned scale_colour_brewer scale_colour_continuous scale_colour_discrete scale_colour_gradient scale_colour_grey scale_colour_hue scale_colour_steps scale_colour_viridis_d scale_continuous scale_date scale_identity scale_linetype scale_linewidth scale_manual scale_shape scale_size scale_type scale_x_discrete seals sec_axis set_last_plot sf_transform_xy should_stop standardise_aes_names stat_connect stat_ecdf stat_ellipse stat_identity stat_manual stat_sf_coordinates stat_summary_2d stat_summary_bin stat_unique subtheme summarise_plot theme tidyeval transform_position translate_shape_string txhousing update_geom_defaults update_ggplot update_labels vars waiver wrap_dims zeroGrob Title: Create Elegant Data Visualisations Using the Grammar of Graphics Version: 4.0.3 Description: 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. License: MIT + file LICENSE URL: https://ggplot2.tidyverse.org , https://github.com/tidyverse/ggplot2 BugReports: https://github.com/tidyverse/ggplot2/issues Depends: R (≥ 4.1) Imports: cli, grDevices, grid, gtable (≥ 0.3.6), isoband, lifecycle (> 1.0.1), rlang (≥ 1.1.0), S7, scales (≥ 1.4.0), stats, vctrs (≥ 0.6.0), withr (≥ 2.5.0) Suggests: broom, covr, dplyr, ggplot2movies, hexbin, Hmisc, hms, knitr, mapproj, maps, MASS, mgcv, multcomp, munsell, nlme, profvis, quantreg, quarto, ragg (≥ 1.2.6), RColorBrewer, roxygen2, rpart, sf (≥ 0.7-3), svglite (≥ 2.1.2), testthat (≥ 3.1.5), tibble, vdiffr (≥ 1.0.6), xml2 Enhances: sp VignetteBuilder: quarto Config/Needs/website: ggtext, tidyr, forcats, tidyverse/tidytemplate Config/testthat/edition: 3 Config/usethis/last-upkeep: 2025-04-23 Encoding: UTF-8 LazyData: true RoxygenNote: 7.3.3 Collate: 'ggproto.R' 'ggplot-global.R' 'aaa-.R' 'aes-colour-fill-alpha.R' 'aes-evaluation.R' 'aes-group-order.R' 'aes-linetype-size-shape.R' 'aes-position.R' 'all-classes.R' 'compat-plyr.R' 'utilities.R' 'aes.R' 'annotation-borders.R' 'utilities-checks.R' 'legend-draw.R' 'geom-.R' 'annotation-custom.R' 'annotation-logticks.R' 'scale-type.R' 'layer.R' 'make-constructor.R' 'geom-polygon.R' 'geom-map.R' 'annotation-map.R' 'geom-raster.R' 'annotation-raster.R' 'annotation.R' 'autolayer.R' 'autoplot.R' 'axis-secondary.R' 'backports.R' 'bench.R' 'bin.R' 'coord-.R' 'coord-cartesian-.R' 'coord-fixed.R' 'coord-flip.R' 'coord-map.R' 'coord-munch.R' 'coord-polar.R' 'coord-quickmap.R' 'coord-radial.R' 'coord-sf.R' 'coord-transform.R' 'data.R' 'docs_layer.R' 'facet-.R' 'facet-grid-.R' 'facet-null.R' 'facet-wrap.R' 'fortify-map.R' 'fortify-models.R' 'fortify-spatial.R' 'fortify.R' 'stat-.R' 'geom-abline.R' 'geom-rect.R' 'geom-bar.R' 'geom-tile.R' 'geom-bin2d.R' 'geom-blank.R' 'geom-boxplot.R' 'geom-col.R' 'geom-path.R' 'geom-contour.R' 'geom-point.R' 'geom-count.R' 'geom-crossbar.R' 'geom-segment.R' 'geom-curve.R' 'geom-defaults.R' 'geom-ribbon.R' 'geom-density.R' 'geom-density2d.R' 'geom-dotplot.R' 'geom-errorbar.R' 'geom-freqpoly.R' 'geom-function.R' 'geom-hex.R' 'geom-histogram.R' 'geom-hline.R' 'geom-jitter.R' 'geom-label.R' 'geom-linerange.R' 'geom-pointrange.R' 'geom-quantile.R' 'geom-rug.R' 'geom-sf.R' 'geom-smooth.R' 'geom-spoke.R' 'geom-text.R' 'geom-violin.R' 'geom-vline.R' 'ggplot2-package.R' 'grob-absolute.R' 'grob-dotstack.R' 'grob-null.R' 'grouping.R' 'properties.R' 'margins.R' 'theme-elements.R' 'guide-.R' 'guide-axis.R' 'guide-axis-logticks.R' 'guide-axis-stack.R' 'guide-axis-theta.R' 'guide-legend.R' 'guide-bins.R' 'guide-colorbar.R' 'guide-colorsteps.R' 'guide-custom.R' 'guide-none.R' 'guide-old.R' 'guides-.R' 'guides-grid.R' 'hexbin.R' 'import-standalone-obj-type.R' 'import-standalone-types-check.R' 'labeller.R' 'labels.R' 'layer-sf.R' 'layout.R' 'limits.R' 'performance.R' 'plot-build.R' 'plot-construction.R' 'plot-last.R' 'plot.R' 'position-.R' 'position-collide.R' 'position-dodge.R' 'position-dodge2.R' 'position-identity.R' 'position-jitter.R' 'position-jitterdodge.R' 'position-nudge.R' 'position-stack.R' 'quick-plot.R' 'reshape-add-margins.R' 'save.R' 'scale-.R' 'scale-alpha.R' 'scale-binned.R' 'scale-brewer.R' 'scale-colour.R' 'scale-continuous.R' 'scale-date.R' 'scale-discrete-.R' 'scale-expansion.R' 'scale-gradient.R' 'scale-grey.R' 'scale-hue.R' 'scale-identity.R' 'scale-linetype.R' 'scale-linewidth.R' 'scale-manual.R' 'scale-shape.R' 'scale-size.R' 'scale-steps.R' 'scale-view.R' 'scale-viridis.R' 'scales-.R' 'stat-align.R' 'stat-bin.R' 'stat-summary-2d.R' 'stat-bin2d.R' 'stat-bindot.R' 'stat-binhex.R' 'stat-boxplot.R' 'stat-connect.R' 'stat-contour.R' 'stat-count.R' 'stat-density-2d.R' 'stat-density.R' 'stat-ecdf.R' 'stat-ellipse.R' 'stat-function.R' 'stat-identity.R' 'stat-manual.R' 'stat-qq-line.R' 'stat-qq.R' 'stat-quantilemethods.R' 'stat-sf-coordinates.R' 'stat-sf.R' 'stat-smooth-methods.R' 'stat-smooth.R' 'stat-sum.R' 'stat-summary-bin.R' 'stat-summary-hex.R' 'stat-summary.R' 'stat-unique.R' 'stat-ydensity.R' 'summarise-plot.R' 'summary.R' 'theme.R' 'theme-defaults.R' 'theme-current.R' 'theme-sub.R' 'utilities-break.R' 'utilities-grid.R' 'utilities-help.R' 'utilities-patterns.R' 'utilities-resolution.R' 'utilities-tidy-eval.R' 'zxx.R' 'zzz.R' NeedsCompilation: no Packaged: 2026-04-21 12:47:29 UTC; thomas Author: Hadley Wickham [aut], Winston Chang [aut], Lionel Henry [aut], Thomas Lin Pedersen [aut, cre], Kohske Takahashi [aut], Claus Wilke [aut], Kara Woo [aut], Hiroaki Yutani [aut],Package 'ggplot2' reference manual Package 'ggplot2' Title: Create Elegant Data Visualisations Using the Grammar of Graphics Description: 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. Authors: Hadley Wickham [aut] (ORCID: <https://orcid.org/0000-0003-4757-117X>), Winston Chang [aut] (ORCID: <https://orcid.org/0000-0002-1576-2126>), Lionel Henry [aut], Thomas Lin Pedersen [aut, cre] (ORCID: <https://orcid.org/0000-0002-5147-4711>), Kohske Takahashi [aut], Claus Wilke [aut] (ORCID: <https://orcid.org/0000-0002-7470-9261>), Kara Woo [aut] (ORCID: <https://orcid.org/0000-0002-5125-4188>), Hiroaki Yutani [aut] (ORCID: <https://orcid.org/0000-0002-3385-7233>), Dewey Dunnington [aut] (ORCID: <https://orcid.org/0000-0002-9415-4582>), Teun van den Brand [aut] (ORCID: <https://orcid.org/0000-0002-9335-7468>), Posit, PBC [cph, fnd] (ROR: <https://ror.org/03wc8by49>) Maintainer: Thomas Lin Pedersen < [email protected] > License: MIT + file LICENSE Version: 4.0.3.9000 Built: 2026-04-25 13:56:20 UTC Source: https://github.com/tidyverse/ggplot2 Help Index Add components to a plot Construct aesthetic mappings Colour related aesthetics: colour, fill, and alpha Control aesthetic evaluation Aesthetics: grouping Differentiation related aesthetics: linetype, size, shape Position related aesthetics: x, y, xmin, xmax, ymin, ymax, xend, yend Create an annotation layer Create a layer of map borders Annotation: Custom grob Annotation: log tick marks Annotation: a map Annotation: high-performance rectangular tiling Create a ggplot layer appropriate to a particular data type Tailoring plots to particular data types Create a complete ggplot appropriate to a particular data type Cartesian coordinates Cartesian coordinates with fixed "aspect ratio" Cartesian coordinates with x and y flipped Map projections Polar coordinates Transformed Cartesian coordinate system Visualise sf objects Discretise numeric data into categorical Prices of over 50,000 round cut diamonds Key glyphs for legends US economic time series Expand the plot limits, using data Generate expansion vector for scales Lay out panels in a grid Wrap a 1d ribbon of panels into 2d 2d density estimate of Old Faithful data Fortify a model with data. Reference lines: horizontal, vertical, and diagonal Bar charts Heatmap of 2d bin counts Draw nothing A box and whiskers plot (in the style of Tukey) 2D contours of a 3D surface Count overlapping points Vertical intervals: lines, crossbars & errorbars Smoothed density estimates Contours of a 2D density estimate Dot plot Histograms and frequency polygons Draw a function as a continuous curve Hexagonal heatmap of 2d bin counts Jittered points Text Polygons from a reference map Connect observations Points Polygons A quantile-quantile plot Quantile regression Rectangles Ribbons and area plots Rug plots in the margins Line segments and curves Smoothed conditional means Line segments parameterised by location, direction and distance Violin plot Extract alt text from a plot Get, set, and modify the active theme Create a new ggplot Create a new ggproto object Save a ggplot (or other grid object) with sensible defaults Complete themes Axis guide Axis with logarithmic tick marks Stacked axis guides Angle axis guide A binned version of guide_legend Continuous colour bar guide Discretized colourbar guide Custom guides Legend guide Empty guide Set guides for each scale A selection of summary functions from Hmisc Label with mathematical expressions Construct labelling specification Useful labeller functions Modify axis, legend, and plot labels Layer geometry display Layer position adjustments Layer statistical transformations Set scale limits colors() in Luv space Theme elements Calculate mean and standard error of the mean Midwest demographics Fuel economy data from 1999 to 2008 for 38 popular models of cars An updated and expanded version of the mammals sleep dataset Dodge overlapping objects side-to-side Don't adjust position Jitter points to avoid overplotting Simultaneously dodge and jitter Nudge points a fixed distance Stack overlapping objects on top of each another Terms of 12 presidents from Eisenhower to Trump Explicitly draw plot Format or print a ggproto object Quick plot Compute the "resolution" of a numeric vector Alpha transparency scales Positional scales for binning continuous data (x & y) Sequential, diverging and qualitative colour scales from ColorBrewer Continuous and binned colour scales Discrete colour scales Gradient colour scales Sequential grey colour scales Evenly spaced colours for discrete data Binned gradient colour scales Viridis colour scales from viridisLite Position scales for continuous data (x & y) Position scales for date/time data Use values without scaling Scale for line patterns Scales for line width Create your own discrete scale Scales for shapes, aka glyphs Scales for area or radius Position scales for discrete data Vector field of seal movements Specify a secondary axis Connect observations Compute empirical cumulative distribution Compute normal data ellipses Leave data as is Manually compute transformations Extract coordinates from 'sf' objects Bin and summarise in 2d (rectangle & hexagons) Summarise y values at unique/binned x Remove duplicates Shortcuts for theme settings Modify components of a theme Housing sales in TX Quote faceting variables Add components to a plot Description + is the key to constructing sophisticated ggplot2 graphics. It allows you to start simple, then get more and more complex, checking your work at each step. Usage add_gg(e1, e2) e1 %+% e2 add_gg ( e1 , e2 ) e1 %+% e2 Arguments e1 An object of class ggplot() or a theme() . e2 A plot component, as described below. What can you add? You can add any of the following types of objects: An aes() object replaces the default aesthetics. A layer created by a geom_ or stat_ function adds a new layer. A scale overrides the existing scale. A theme() modifies the current theme. A coord overrides the current coordinate system. A facet specification overrides the current faceting. To replace the current default data frame, you must use %+% , due to S3 method precedence issues. You can also supply a list, in which case each element of the list will be added in turn. See Also theme() Examples base <- ggplot(mpg, aes(displ, hwy)) + geom_point() base + geom_smooth() # To override the data, you must use %+% base %+% subset(mpg, fl == "p") # Alternatively, you can add multiple components with a list. # This can be useful to return from a function. base + list(subset(mpg, fl == "p"), geom_smooth()) base <- ggplot ( mpg , aes ( displ , hwy ) ) + geom_point ( ) base + geom_smooth ( ) # To override the data, you must use %+% base %+% subset ( mpg , fl == "p" ) # Alternatively, you can add multiple components with a list. # This can be useful to return from a function. base + list ( subset ( mpg , fl == "p" ) , geom_smooth ( ) ) Construct aesthetic mappings Description Aesthetic mappings describe how variables in the data are mapped to visual properties (aesthetics) of geoms. Aesthetic mappings can be set in ggplot() and in individual layers. Usage aes(x, y, ...) aes ( x , y , ... ) Arguments x , y , ... < data-masking > List of name-value pairs in the form aesthetic = variable describing which variables in the layer data should be mapped to which aesthetics used by the paired geom/stat. The expression variable is evaluated within the layer data, so there is no need to refer to the original dataset (i.e., use ggplot(df, aes(variable)) instead of ggplot(df, aes(df$variable)) ). The names for x and y aesthetics are typically omitted because they are so common; all other aesthetics must be named. Details This function also standardises aesthetic names by converting color to colour (also in substrings, e.g., point_coPackage 'ggplot2' reference manual Package 'ggplot2' Title: Create Elegant Data Visualisations Using the Grammar of Graphics Description: 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. Authors: Hadley Wickham [aut] (ORCID: <https://orcid.org/0000-0003-4757-117X>), Winston Chang [aut] (ORCID: <https://orcid.org/0000-0002-1576-2126>), Lionel Henry [aut], Thomas Lin Pedersen [aut, cre] (ORCID: <https://orcid.org/0000-0002-5147-4711>), Kohske Takahashi [aut], Claus Wilke [aut] (ORCID: <https://orcid.org/0000-0002-7470-9261>), Kara Woo [aut] (ORCID: <https://orcid.org/0000-0002-5125-4188>), Hiroaki Yutani [aut] (ORCID: <https://orcid.org/0000-0002-3385-7233>), Dewey Dunnington [aut] (ORCID: <https://orcid.org/0000-0002-9415-4582>), Teun van den Brand [aut] (ORCID: <https://orcid.org/0000-0002-9335-7468>), Posit, PBC [cph, fnd] (ROR: <https://ror.org/03wc8by49>) Maintainer: Thomas Lin Pedersen < [email protected] > License: MIT + file LICENSE Version: 4.0.3.9000 Built: 2026-04-25 13:56:20 UTC Source: https://github.com/tidyverse/ggplot2 Help Index Add components to a plot Construct aesthetic mappings Colour related aesthetics: colour, fill, and alpha Control aesthetic evaluation Aesthetics: grouping Differentiation related aesthetics: linetype, size, shape Position related aesthetics: x, y, xmin, xmax, ymin, ymax, xend, yend Create an annotation layer Create a layer of map borders Annotation: Custom grob Annotation: log tick marks Annotation: a map Annotation: high-performance rectangular tiling Create a ggplot layer appropriate to a particular data type Tailoring plots to particular data types Create a complete ggplot appropriate to a particular data type Cartesian coordinates Cartesian coordinates with fixed "aspect ratio" Cartesian coordinates with x and y flipped Map projections Polar coordinates Transformed Cartesian coordinate system Visualise sf objects Discretise numeric data into categorical Prices of over 50,000 round cut diamonds Key glyphs for legends US economic time series Expand the plot limits, using data Generate expansion vector for scales Lay out panels in a grid Wrap a 1d ribbon of panels into 2d 2d density estimate of Old Faithful data Fortify a model with data. Reference lines: horizontal, vertical, and diagonal Bar charts Heatmap of 2d bin counts Draw nothing A box and whiskers plot (in the style of Tukey) 2D contours of a 3D surface Count overlapping points Vertical intervals: lines, crossbars & errorbars Smoothed density estimates Contours of a 2D density estimate Dot plot Histograms and frequency polygons Draw a function as a continuous curve Hexagonal heatmap of 2d bin counts Jittered points Text Polygons from a reference map Connect observations Points Polygons A quantile-quantile plot Quantile regression Rectangles Ribbons and area plots Rug plots in the margins Line segments and curves Smoothed conditional means Line segments parameterised by location, direction and distance Violin plot Extract alt text from a plot Get, set, and modify the active theme Create a new ggplot Create a new ggproto object Save a ggplot (or other grid object) with sensible defaults Complete themes Axis guide Axis with logarithmic tick marks Stacked axis guides Angle axis guide A binned version of guide_legend Continuous colour bar guide Discretized colourbar guide Custom guides Legend guide Empty guide Set guides for each scale A selection of summary functions from Hmisc Label with mathematical expressions Construct labelling specification Useful labeller functions Modify axis, legend, and plot labels Layer geometry display Layer position adjustments Layer statistical transformations Set scale limits colors() in Luv space Theme elements Calculate mean and standard error of the mean Midwest demographics Fuel economy data from 1999 to 2008 for 38 popular models of cars An updated and expanded version of the mammals sleep dataset Dodge overlapping objects side-to-side Don't adjust position Jitter points to avoid overplotting Simultaneously dodge and jitter Nudge points a fixed distance Stack overlapping objects on top of each another Terms of 12 presidents from Eisenhower to Trump Explicitly draw plot Format or print a ggproto object Quick plot Compute the "resolution" of a numeric vector Alpha transparency scales Positional scales for binning continuous data (x & y) Sequential, diverging and qualitative colour scales from ColorBrewer Continuous and binned colour scales Discrete colour scales Gradient colour scales Sequential grey colour scales Evenly spaced colours for discrete data Binned gradient colour scales Viridis colour scales from viridisLite Position scales for continuous data (x & y) Position scales for date/time data Use values without scaling Scale for line patterns Scales for line width Create your own discrete scale Scales for shapes, aka glyphs Scales for area or radius Position scales for discrete data Vector field of seal movements Specify a secondary axis Connect observations Compute empirical cumulative distribution Compute normal data ellipses Leave data as is Manually compute transformations Extract coordinates from 'sf' objects Bin and summarise in 2d (rectangle & hexagons) Summarise y values at unique/binned x Remove duplicates Shortcuts for theme settings Modify components of a theme Housing sales in TX Quote faceting variables Add components to a plot Description + is the key to constructing sophisticated ggplot2 graphics. It allows you to start simple, then get more and more complex, checking your work at each step. Usage add_gg(e1, e2) e1 %+% e2 add_gg ( e1 , e2 ) e1 %+% e2 Arguments e1 An object of class ggplot() or a theme() . e2 A plot component, as described below. What can you add? You can add any of the following types of objects: An aes() object replaces the default aesthetics. A layer created by a geom_ or stat_ function adds a new layer. A scale overrides the existing scale. A theme() modifies the current theme. A coord overrides the current coordinate system. A facet specification overrides the current faceting. To replace the current default data frame, you must use %+% , due to S3 method precedence issues. You can also supply a list, in which case each element of the list will be added in turn. See Also theme() Examples base <- ggplot(mpg, aes(displ, hwy)) + geom_point() base + geom_smooth() # To override the data, you must use %+% base %+% subset(mpg, fl == "p") # Alternatively, you can add multiple components with a list. # This can be useful to return from a function. base + list(subset(mpg, fl == "p"), geom_smooth()) base <- ggplot ( mpg , aes ( displ , hwy ) ) + geom_point ( ) base + geom_smooth ( ) # To override the data, you must use %+% base %+% subset ( mpg , fl == "p" ) # Alternatively, you can add multiple components with a list. # This can be useful to return from a function. base + list ( subset ( mpg , fl == "p" ) , geom_smooth ( ) ) Construct aesthetic mappings Description Aesthetic mappings describe how variables in the data are mapped to visual properties (aesthetics) of geoms. Aesthetic mappings can be set in ggplot() and in individual layers. Usage aes(x, y, ...) aes ( x , y , ... ) Arguments x , y , ... < data-masking > List of name-value pairs in the form aesthetic = variable describing which variables in the layer data should be mapped to which aesthetics used by the paired geom/stat. The expression variable is evaluated within the layer data, so there is no need to refer to the original dataset (i.e., use ggplot(df, aes(variable)) instead of ggplot(df, aes(df$variable)) ). The names for x and y aesthetics are typically omitted because they are so common; all other aesthetics must be named. Details This function also standardises aesthetic names by converting color to colour (also in substrings, e.g., point_coPackage 'ggplot2' reference manual Package 'ggplot2' Title: Create Elegant Data Visualisations Using the Grammar of Graphics Description: 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. Authors: Hadley Wickham [aut] (ORCID: <https://orcid.org/0000-0003-4757-117X>), Winston Chang [aut] (ORCID: <https://orcid.org/0000-0002-1576-2126>), Lionel Henry [aut], Thomas Lin Pedersen [aut, cre] (ORCID: <https://orcid.org/0000-0002-5147-4711>), Kohske Takahashi [aut], Claus Wilke [aut] (ORCID: <https://orcid.org/0000-0002-7470-9261>), Kara Woo [aut] (ORCID: <https://orcid.org/0000-0002-5125-4188>), Hiroaki Yutani [aut] (ORCID: <https://orcid.org/0000-0002-3385-7233>), Dewey Dunnington [aut] (ORCID: <https://orcid.org/0000-0002-9415-4582>), Teun van den Brand [aut] (ORCID: <https://orcid.org/0000-0002-9335-7468>), Posit, PBC [cph, fnd] (ROR: <https://ror.org/03wc8by49>) Maintainer: Thomas Lin Pedersen < [email protected] > License: MIT + file LICENSE Version: 4.0.3.9000 Built: 2026-04-25 13:56:20 UTC Source: https://github.com/tidyverse/ggplot2 Help Index Add components to a plot Construct aesthetic mappings Colour related aesthetics: colour, fill, and alpha Control aesthetic evaluation Aesthetics: grouping Differentiation related aesthetics: linetype, size, shape Position related aesthetics: x, y, xmin, xmax, ymin, ymax, xend, yend Create an annotation layer Create a layer of map borders Annotation: Custom grob Annotation: log tick marks Annotation: a map Annotation: high-performance rectangular tiling Create a ggplot layer appropriate to a particular data type Tailoring plots to particular data types Create a complete ggplot appropriate to a particular data type Cartesian coordinates Cartesian coordinates with fixed "aspect ratio" Cartesian coordinates with x and y flipped Map projections Polar coordinates Transformed Cartesian coordinate system Visualise sf objects Discretise numeric data into categorical Prices of over 50,000 round cut diamonds Key glyphs for legends US economic time series Expand the plot limits, using data Generate expansion vector for scales Lay out panels in a grid Wrap a 1d ribbon of panels into 2d 2d density estimate of Old Faithful data Fortify a model with data. Reference lines: horizontal, vertical, and diagonal Bar charts Heatmap of 2d bin counts Draw nothing A box and whiskers plot (in the style of Tukey) 2D contours of a 3D surface Count overlapping points Vertical intervals: lines, crossbars & errorbars Smoothed density estimates Contours of a 2D density estimate Dot plot Histograms and frequency polygons Draw a function as a continuous curve Hexagonal heatmap of 2d bin counts Jittered points Text Polygons from a reference map Connect observations Points Polygons A quantile-quantile plot Quantile regression Rectangles Ribbons and area plots Rug plots in the margins Line segments and curves Smoothed conditional means Line segments parameterised by location, direction and distance Violin plot Extract alt text from a plot Get, set, and modify the active theme Create a new ggplot Create a new ggproto object Save a ggplot (or other grid object) with sensible defaults Complete themes Axis guide Axis with logarithmic tick marks Stacked axis guides Angle axis guide A binned version of guide_legend Continuous colour bar guide Discretized colourbar guide Custom guides Legend guide Empty guide Set guides for each scale A selection of summary functions from Hmisc Label with mathematical expressions Construct labelling specification Useful labeller functions Modify axis, legend, and plot labels Layer geometry display Layer position adjustments Layer statistical transformations Set scale limits colors() in Luv space Theme elements Calculate mean and standard error of the mean Midwest demographics Fuel economy data from 1999 to 2008 for 38 popular models of cars An updated and expanded version of the mammals sleep dataset Dodge overlapping objects side-to-side Don't adjust position Jitter points to avoid overplotting Simultaneously dodge and jitter Nudge points a fixed distance Stack overlapping objects on top of each another Terms of 12 presidents from Eisenhower to Trump Explicitly draw plot Format or print a ggproto object Quick plot Compute the "resolution" of a numeric vector Alpha transparency scales Positional scales for binning continuous data (x & y) Sequential, diverging and qualitative colour scales from ColorBrewer Continuous and binned colour scales Discrete colour scales Gradient colour scales Sequential grey colour scales Evenly spaced colours for discrete data Binned gradient colour scales Viridis colour scales from viridisLite Position scales for continuous data (x & y) Position scales for date/time data Use values without scaling Scale for line patterns Scales for line width Create your own discrete scale Scales for shapes, aka glyphs Scales for area or radius Position scales for discrete data Vector field of seal movements Specify a secondary axis Connect observations Compute empirical cumulative distribution Compute normal data ellipses Leave data as is Manually compute transformations Extract coordinates from 'sf' objects Bin and summarise in 2d (rectangle & hexagons) Summarise y values at unique/binned x Remove duplicates Shortcuts for theme settings Modify components of a theme Housing sales in TX Quote faceting variables Add components to a plot Description + is the key to constructing sophisticated ggplot2 graphics. It allows you to start simple, then get more and more complex, checking your work at each step. Usage add_gg(e1, e2) e1 %+% e2 add_gg ( e1 , e2 ) e1 %+% e2 Arguments e1 An object of class ggplot() or a theme() . e2 A plot component, as described below. What can you add? You can add any of the following types of objects: An aes() object replaces the default aesthetics. A layer created by a geom_ or stat_ function adds a new layer. A scale overrides the existing scale. A theme() modifies the current theme. A coord overrides the current coordinate system. A facet specification overrides the current faceting. To replace the current default data frame, you must use %+% , due to S3 method precedence issues. You can also supply a list, in which case each element of the list will be added in turn. See Also theme() Examples base <- ggplot(mpg, aes(displ, hwy)) + geom_point() base + geom_smooth() # To override the data, you must use %+% base %+% subset(mpg, fl == "p") # Alternatively, you can add multiple components with a list. # This can be useful to return from a function. base + list(subset(mpg, fl == "p"), geom_smooth()) base <- ggplot ( mpg , aes ( displ , hwy ) ) + geom_point ( ) base + geom_smooth ( ) # To override the data, you must use %+% base %+% subset ( mpg , fl == "p" ) # Alternatively, you can add multiple components with a list. # This can be useful to return from a function. base + list ( subset ( mpg , fl == "p" ) , geom_smooth ( ) ) Construct aesthetic mappings Description Aesthetic mappings describe how variables in the data are mapped to visual properties (aesthetics) of geoms. Aesthetic mappings can be set in ggplot() and in individual layers. Usage aes(x, y, ...) aes ( x , y , ... ) Arguments x , y , ... < data-masking > List of name-value pairs in the form aesthetic = variable describing which variables in the layer data should be mapped to which aesthetics used by the paired geom/stat. The expression variable is evaluated within the layer data, so there is no need to refer to the original dataset (i.e., use ggplot(df, aes(variable)) instead of ggplot(df, aes(df$variable)) ). The names for x and y aesthetics are typically omitted because they are so common; all other aesthetics must be named. Details This function also standardises aesthetic names by converting color to colour (also in substrings, e.g., point_coAll coord_*() functions (like coord_transform()) return a Coord* object (like CoordTransform). These objects contain methods that support the coordinate systems in ggplot2.
# Extending the class CoordJitter <- ggproto( "CoordJitter", CoordCartesian, # Fields amount = 0, # Methods is_linear = function() FALSE, transform = function(self, data, panel_params) data <- ggproto_parent(CoordCartesian, self)$transform(data, panel_params) data$x <- jitter(data$x, amount = self$amount) data$y <- jitter(data$y, amount = self$amount) data ) # Building a constructor coord_jitter <- function(amount = 0.005, xlim = NULL, ylim = NULL, expand = TRUE, clip = "on", reverse = "none") ggproto( NULL, CoordJitter, amount = amount, limits = list(x = xlim, y = ylim), reverse = reverse, expand = expand, clip = clip ) # Use new coord in plot set.seed(42) ggplot(mpg, aes(drv, displ)) + geom_boxplot() + coord_jitter()This set of geom, stat, and coord are used to visualise simple feature (sf) objects. For simple plots, you will only need geom_sf() as it uses stat_sf() and adds coord_sf() for you. geom_sf() is an unusual geom because it will draw different geometric objects depending on what simple features are present in the data: you can get points, lines, or polygons. For text and labels, you can use geom_sf_text() and geom_sf_label().
coord_sf( xlim = NULL, ylim = NULL, expand = TRUE, crs = NULL, default_crs = NULL, datum = sf::st_crs(4326), label_graticule = waiver(), label_axes = waiver(), lims_method = "cross", ndiscr = 100, default = FALSE, clip = "on", reverse = "none" ) geom_sf( mapping = aes(), data = NULL, stat = "sf", position = "identity", na.rm = FALSE, show.legend = NA, inherit.aes = TRUE, ... ) geom_sf_label( mapping = aes(), data = NULL, stat = "sf_coordinates", position = "nudge", ..., parse = FALSE, label.padding = unit(0.25, "lines"), label.r = unit(0.15, "lines"), label.size = deprecated(), border.colour = NULL, border.color = NULL, text.colour = NULL, text.color = NULL, na.rm = FALSE, show.legend = NA, inherit.aes = TRUE, fun.geometry = NULL ) geom_sf_text( mapping = aes(), data = NULL, stat = "sf_coordinates", position = "nudge", ..., parse = FALSE, check_overlap = FALSE, na.rm = FALSE, show.legend = NA, inherit.aes = TRUE, fun.geometry = NULL ) stat_sf( mapping = NULL, data = NULL, geom = "rect", position = "identity", na.rm = FALSE, show.legend = NA, inherit.aes = TRUE, ... )if (requireNamespace("sf", quietly = TRUE)) nc <- sf::st_read(system.file("shape/nc.shp", package = "sf"), quiet = TRUE) ggplot(nc) + geom_sf(aes(fill = AREA)) # If not supplied, coord_sf() will take the CRS from the first layer # and automatically transform all other layers to use that CRS. This # ensures that all data will correctly line up nc_3857 <- sf::st_transform(nc, 3857) ggplot() + geom_sf(data = nc) + geom_sf(data = nc_3857, colour = "red", fill = NA) # Unfortunately if you plot other types of feature you'll need to use # show.legend to tell ggplot2 what type of legend to use nc_3857$mid <- sf::st_centroid(nc_3857$geometry) ggplot(nc_3857) + geom_sf(colour = "white") + geom_sf(aes(geometry = mid, size = AREA), show.legend = "point") # You can also use layers with x and y aesthetics. To have these interpreted # as longitude/latitude you need to set the default CRS in coord_sf() ggplot(nc_3857) + geom_sf() + annotate("point", x = -80, y = 35, colour = "red", size = 4) + coord_sf(default_crs = sf::st_crs(4326)) # To add labels, use geom_sf_label(). ggplot(nc_3857[1:3, ]) + geom_sf(aes(fill = AREA)) + geom_sf_label(aes(label = NAME)) # Thanks to the power of sf, a geom_sf nicely handles varying projections # setting the aspect ratio correctly. if (requireNamespace('maps', quietly = TRUE)) library(maps) world1 <- sf::st_as_sf(map('world', plot = FALSE, fill = TRUE)) ggplot() + geom_sf(data = world1) world2 <- sf::st_transform( world1, "+proj=laea +y_0=0 +lon_0=155 +lat_0=-90 +ellps=WGS84 +no_defs" ) ggplot() + geom_sf(data = world2)All facet_*() functions returns a Facet object or an object of a Facet subclass. This object describes how to assign data to different panels, how to apply positional scales and how to lay out the panels, once rendered.
# Please see extension vignette NULLAll geom_*() functions (like geom_point()) return a layer that contains a Geom* object (like GeomPoint). The Geom* object is responsible for rendering the data in the plot.
# Extending the class GeomSimplePoint <- ggproto( "GeomSimplePoint", Geom, # Fields required_aes = c("x", "y"), draw_key = draw_key_point, # Methods draw_panel = function(data, panel_params, coord) data <- coord$transform(data, panel_params) grid::pointsGrob(data$x, data$y) ) # Building a constructor geom_simple_point <- function(mapping = NULL, data = NULL, stat = "identity", position = "identity", ..., na.rm = FALSE, show.legend = NA, inherit.aes = TRUE) layer( mapping = mapping, data = data, geom = GeomSimplePoint, stat = stat, position = position, show.legend = show.legend, inherit.aes = inherit.aes, params = list(na.rm = na.rm, ...) ) # Use new geom in plot ggplot(mpg, aes(displ, hwy)) + geom_simple_point()The guide_* functions (like guide_legend()) return Guide* objects (like GuideLegend). The Guide* object is responsible for rendering the guide for at least one aesthetic.
# Extending the class GuideDescribe <- ggproto( "GuideDescribe", Guide, # Fields elements = list(text = "legend.text", margin = "legend.margin"), hashables = rlang::exprs(key$.label), # Methods build_title = function(...) zeroGrob(), # Turn off title build_labels = function(key, elements, params) labels <- key$.label n <- length(labels) labels <- paste0(paste0(labels[-n], collapse = ", "), ", and ", labels[n]) labels <- paste0("A guide showing ", labels, " categories") element_grob(elements$text, label = labels, margin_x = TRUE, margin_y = TRUE) , measure_grobs = function(grobs, params, elements) # Measuring in centimetres is the convention width <- grid::convertWidth(grid::grobWidth(grobs$labels), "cm", valueOnly = TRUE) height <- grid::convertHeight(grid::grobHeight(grobs$labels), "cm", valueOnly = TRUE) list(width = unit(width, "cm"), height = unit(height, "cm")) , assemble_drawing = function(self, grobs, layout, sizes, params, elements) gt <- gtable::as.gtable(grobs$labels, width = sizes$width, height = sizes$height) gt <- gtable::gtable_add_padding(gt, elements$margin) gt ) # Building a constructor guide_describe <- function(position = NULL) new_guide(position = position, super = GuideDescribe) # Use new guide plot ggplot(mpg, aes(displ, hwy, colour = class)) + geom_point() + guides(colour = guide_describe("bottom"))The Layer class is a chaperone class not available for extension. The class fulfils the following tasks. The class houses the Geom, Stat and Position trinity and tracks their stateful parameters. Furthermore, its methods are responsible for managing the layer data and exposing it to other components of the plot at the right time.
# None: Layer is not intended to be extendedThe Layout class is a chaperone class discouraged for extension. The class fulfils the following tasks. The class houses the Coord and Facet classes and tracks their stateful parameters. In addition, it manages the position scales for each panel. It is responsible for keeping track of panel specifications and matching pieces of the data to scales and parameters in panel-wise manners.
# Some dummy layout components facet <- facet_null() coord <- coord_cartesian() # Use in custom `ggplot_build()` methods layout <- ggproto(NULL, Layout, facet = facet, coord = coord)All position_*() functions (like position_dodge()) return a Position* object (like PositionDodge). The Position* object is responsible for adjusting the position of overlapping geoms.
# Extending the class PositionRank <- ggproto( "PositionRank", Position, # Fields required_aes = c("x", "y"), # Methods setup_params = function(self, data) list(width = self$width), compute_panel = function(data, params, scales) width <- params$width if (is.null(width)) width <- resolution(data$x, zero = FALSE, TRUE) * 0.4 rank <- stats::ave(data$y, data$group, FUN = rank) rank <- scales::rescale(rank, to = c(-width, width) / 2) data$x <- data$x + rank data ) # Building a constructor position_rank <- function(width = NULL) ggproto(NULL, PositionRank, width = width) # Use new position in plot ggplot(mpg, aes(drv, displ)) + geom_point(position = position_rank(width = 0.5))All scale_*() functions (like scale_fill_continuous()) return a Scale* object. The main purpose of these objects is to translate data values to aesthetic values and populating breaks and labels.
# TODO: find easy to digest example NULLAll stat_*() functions (like stat_bin()) return a layer that contains a Stat* object (like StatBin). The Stat* object is responsible for rendering the data in the plot.
# Extending the class StatKmeans <- ggproto( "StatKmeans", Stat, # Fields required_aes = c("x", "y"), # You can relate computed variables to aesthetics using `after_stat()` # in defaults default_aes = aes(colour = after_stat(cluster)), # Methods compute_panel = function(data, scales, k = 2L) km <- kmeans(cbind(scale(data$x), scale(data$y)), centers = k) data$cluster <- factor(km$cluster) data ) # Building a constructor stat_kmeans <- function(mapping = NULL, data = NULL, geom = "point", position = "identity", ..., k = 2L, na.rm = FALSE, show.legend = NA, inherit.aes = TRUE) layer( mapping = mapping, data = data, geom = geom, stat = StatKmeans, position = position, show.legend = show.legend, inherit.aes = inherit.aes, params = list(na.rm = na.rm, k = k, ...) ) # Use new stat in plot ggplot(mpg, aes(displ, hwy)) + stat_kmeans(k = 3)This grob has fixed dimensions and position.
absoluteGrob( grob, width = NULL, height = NULL, xmin = NULL, ymin = NULL, vp = NULL )+ is the key to constructing sophisticated ggplot2 graphics. It allows you to start simple, then get more and more complex, checking your work at each step.
add_gg(e1, e2) e1 %+% e2base <- ggplot(mpg, aes(displ, hwy)) + geom_point() base + geom_smooth() # To override the data, you must use %+% base %+% subset(mpg, fl == "p") # Alternatively, you can add multiple components with a list. # This can be useful to return from a function. base + list(subset(mpg, fl == "p"), geom_smooth())Modify properties of an element in a theme object
add_theme(t1, t2, t2name, call = caller_env())Aesthetic mappings describe how variables in the data are mapped to visual properties (aesthetics) of geoms. Aesthetic mappings can be set in [=ggplot]ggplot() and in individual layers.
aes(x, y, ...)aes(x = mpg, y = wt) aes(mpg, wt) # You can also map aesthetics to functions of variables aes(x = mpg ^ 2, y = wt / cyl) # Or to constants aes(x = 1, colour = "smooth") # Aesthetic names are automatically standardised aes(col = x) aes(fg = x) aes(color = x) aes(colour = x) # aes() is passed to either ggplot() or specific layer. Aesthetics supplied # to ggplot() are used as defaults for every layer. ggplot(mpg, aes(displ, hwy)) + geom_point() ggplot(mpg) + geom_point(aes(displ, hwy)) # Tidy evaluation ---------------------------------------------------- # aes() automatically quotes all its arguments, so you need to use tidy # evaluation to create wrappers around ggplot2 pipelines. The # simplest case occurs when your wrapper takes dots: scatter_by <- function(data, ...) ggplot(data) + geom_point(aes(...)) scatter_by(mtcars, disp, drat) # If your wrapper has a more specific interface with named arguments, # you need the "embrace operator": scatter_by <- function(data, x, y) ggplot(data) + geom_point(aes( x , y )) scatter_by(mtcars, disp, drat) # Note that users of your wrapper can use their own functions in the # quoted expressions and all will resolve as it should! cut3 <- function(x) cut_number(x, 3) scatter_by(mtcars, cut3(disp), drat)htmlhttps://lifecycle.r-lib.org/articles/stages.html#deprecatedlifecycle-deprecated.svgoptions: alt='[Deprecated]'[Deprecated] Aesthetic mappings describe how variables in the data are mapped to visual properties (aesthetics) of geoms. [=aes]aes() uses non-standard evaluation to capture the variable names. aes_() and aes_string() require you to explicitly quote the inputs either with "" for aes_string(), or with quote or ~ for aes_(). (aes_q() is an alias to aes_()). This makes aes_() and aes_string() easy to program with. aes_string() and aes_() are particularly useful when writing functions that create plots because you can use strings or quoted names/calls to define the aesthetic mappings, rather than having to use [=substitute]substitute() to generate a call to aes(). I recommend using aes_(), because creating the equivalents of aes(colour = "my colour") or aes(x = `X$1`) with aes_string() is quite clunky.
aes_(x, y, ...) aes_string(x, y, ...) aes_q(x, y, ...)Given a character vector, create a set of identity mappings
aes_all(vars)aes_all(names(mtcars)) aes_all(c("x", "y", "col", "pch"))htmlhttps://lifecycle.r-lib.org/articles/stages.html#deprecatedlifecycle-deprecated.svgoptions: alt='[Deprecated]'[Deprecated]
aes_auto(data = NULL, ...)These aesthetics parameters change the colour (colour and fill) and the opacity (alpha) of geom elements on a plot. Almost every geom has either colour or fill (or both), as well as can have their alpha modified. Modifying colour on a plot is a useful way to enhance the presentation of data, often especially when a plot graphs more than two variables.
# Bar chart example p <- ggplot(mtcars, aes(factor(cyl))) # Default plotting p + geom_bar() # To change the interior colouring use fill aesthetic p + geom_bar(fill = "red") # Compare with the colour aesthetic which changes just the bar outline p + geom_bar(colour = "red") # Combining both, you can see the changes more clearly p + geom_bar(fill = "white", colour = "red") # Both colour and fill can take an rgb specification. p + geom_bar(fill = "#00abff") # Use NA for a completely transparent colour. p + geom_bar(fill = NA, colour = "#00abff") # Colouring scales differ depending on whether a discrete or # continuous variable is being mapped. For example, when mapping # fill to a factor variable, a discrete colour scale is used. ggplot(mtcars, aes(factor(cyl), fill = factor(vs))) + geom_bar() # When mapping fill to continuous variable a continuous colour # scale is used. ggplot(faithfuld, aes(waiting, eruptions)) + geom_raster(aes(fill = density)) # Some geoms only use the colour aesthetic but not the fill # aesthetic (e.g. geom_point() or geom_line()). p <- ggplot(economics, aes(x = date, y = unemploy)) p + geom_line() p + geom_line(colour = "green") p + geom_point() p + geom_point(colour = "red") # For large datasets with overplotting the alpha # aesthetic will make the points more transparent. set.seed(1) df <- data.frame(x = rnorm(5000), y = rnorm(5000)) p <- ggplot(df, aes(x,y)) p + geom_point() p + geom_point(alpha = 0.5) p + geom_point(alpha = 1/10) # Alpha can also be used to add shading. p <- ggplot(economics, aes(x = date, y = unemploy)) + geom_line() p yrng <- range(economics$unemploy) p <- p + geom_rect( aes(NULL, NULL, xmin = start, xmax = end, fill = party), ymin = yrng[1], ymax = yrng[2], data = presidential ) p p + scale_fill_manual(values = alpha(c("blue", "red"), .3))Most [=aes]aesthetics are mapped from variables found in the data. Sometimes, however, you want to delay the mapping until later in the rendering process. ggplot2 has three stages of the data that you can map aesthetics from, and three functions to control at which stage aesthetics should be evaluated. after_stat() replaces the old approaches of using either stat(), e.g. stat(density), or surrounding the variable names with .., e.g. ..density...
# These functions can be used inside the `aes()` function # used as the `mapping` argument in layers, for example: # geom_density(mapping = aes(y = after_stat(scaled))) after_stat(x) after_scale(x) from_theme(x) stage(start = NULL, after_stat = NULL, after_scale = NULL)# Default histogram display ggplot(mpg, aes(displ)) + geom_histogram(aes(y = after_stat(count))) # Scale tallest bin to 1 ggplot(mpg, aes(displ)) + geom_histogram(aes(y = after_stat(count / max(count)))) # Use a transparent version of colour for fill ggplot(mpg, aes(class, hwy)) + geom_boxplot(aes(colour = class, fill = after_scale(alpha(colour, 0.4)))) # Use stage to modify the scaled fill ggplot(mpg, aes(class, hwy)) + geom_boxplot(aes(fill = stage(class, after_scale = alpha(fill, 0.4)))) # Making a proportional stacked density plot ggplot(mpg, aes(cty)) + geom_density( aes( colour = factor(cyl), fill = after_scale(alpha(colour, 0.3)), y = after_stat(count / sum(n[!duplicated(group)])) ), position = "stack", bw = 1 ) + geom_density(bw = 1) # Imitating a ridgeline plot ggplot(mpg, aes(cty, colour = factor(cyl))) + geom_ribbon( stat = "density", outline.type = "upper", aes( fill = after_scale(alpha(colour, 0.3)), ymin = after_stat(group), ymax = after_stat(group + ndensity) ) ) # Labelling a bar plot ggplot(mpg, aes(class)) + geom_bar() + geom_text( aes( y = after_stat(count + 2), label = after_stat(count) ), stat = "count" ) # Labelling the upper hinge of a boxplot, # inspired by June Choe ggplot(mpg, aes(displ, class)) + geom_boxplot(outlier.shape = NA) + geom_text( aes( label = after_stat(xmax), x = stage(displ, after_stat = xmax) ), stat = "boxplot", hjust = -0.5 )The group aesthetic is by default set to the interaction of all discrete variables in the plot. This choice often partitions the data correctly, but when it does not, or when no discrete variable is used in the plot, you will need to explicitly define the grouping structure by mapping group to a variable that has a different value for each group.
p <- ggplot(mtcars, aes(wt, mpg)) # A basic scatter plot p + geom_point(size = 4) # Using the colour aesthetic p + geom_point(aes(colour = factor(cyl)), size = 4) # Using the shape aesthetic p + geom_point(aes(shape = factor(cyl)), size = 4) # Using fill p <- ggplot(mtcars, aes(factor(cyl))) p + geom_bar() p + geom_bar(aes(fill = factor(cyl))) p + geom_bar(aes(fill = factor(vs))) # Using linetypes ggplot(economics_long, aes(date, value01)) + geom_line(aes(linetype = variable)) # Multiple groups with one aesthetic p <- ggplot(nlme::Oxboys, aes(age, height)) # The default is not sufficient here. A single line tries to connect all # the observations. p + geom_line() # To fix this, use the group aesthetic to map a different line for each # subject. p + geom_line(aes(group = Subject)) # Different groups on different layers p <- p + geom_line(aes(group = Subject)) # Using the group aesthetic with both geom_line() and geom_smooth() # groups the data the same way for both layers p + geom_smooth(aes(group = Subject), method = "lm", se = FALSE) # Changing the group aesthetic for the smoother layer # fits a single line of best fit across all boys p + geom_smooth(aes(group = 1), size = 2, method = "lm", se = FALSE) # Overriding the default grouping # Sometimes the plot has a discrete scale but you want to draw lines # that connect across groups. This is the strategy used in interaction # plots, profile plots, and parallel coordinate plots, among others. # For example, we draw boxplots of height at each measurement occasion. p <- ggplot(nlme::Oxboys, aes(Occasion, height)) + geom_boxplot() p # There is no need to specify the group aesthetic here; the default grouping # works because occasion is a discrete variable. To overlay individual # trajectories, we again need to override the default grouping for that layer # with aes(group = Subject) p + geom_line(aes(group = Subject), colour = "blue")The linetype, linewidth, size, and shape aesthetics modify the appearance of lines and/or points. They also apply to the outlines of polygons (linetype and linewidth) or to text (size).
df <- data.frame(x = 1:10 , y = 1:10) p <- ggplot(df, aes(x, y)) p + geom_line(linetype = 2) p + geom_line(linetype = "dotdash") # An example with hex strings; the string "33" specifies three units on followed # by three off and "3313" specifies three units on followed by three off followed # by one on and finally three off. p + geom_line(linetype = "3313") # Mapping line type from a grouping variable ggplot(economics_long, aes(date, value01)) + geom_line(aes(linetype = variable)) # Linewidth examples ggplot(economics, aes(date, unemploy)) + geom_line(linewidth = 2, lineend = "round") ggplot(economics, aes(date, unemploy)) + geom_line(aes(linewidth = uempmed), lineend = "round") # Size examples p <- ggplot(mtcars, aes(wt, mpg)) p + geom_point(size = 4) p + geom_point(aes(size = qsec)) p + geom_point(size = 2.5) + geom_hline(yintercept = 25, size = 3.5) # Shape examples p + geom_point() p + geom_point(shape = 5) p + geom_point(shape = "k", size = 3) p + geom_point(shape = ".") p + geom_point(shape = NA) p + geom_point(aes(shape = factor(cyl))) # A look at all 25 symbols df2 <- data.frame(x = 1:5 , y = 1:25, z = 1:25) p <- ggplot(df2, aes(x, y)) p + geom_point(aes(shape = z), size = 4) + scale_shape_identity() # While all symbols have a foreground colour, symbols 19-25 also take a # background colour (fill) p + geom_point(aes(shape = z), size = 4, colour = "Red") + scale_shape_identity() p + geom_point(aes(shape = z), size = 4, colour = "Red", fill = "Black") + scale_shape_identity()The following aesthetics can be used to specify the position of elements: x, y, xmin, xmax, ymin, ymax, xend, yend.
# Generate data: means and standard errors of means for prices # for each type of cut dmod <- lm(price ~ cut, data = diamonds) cut <- unique(diamonds$cut) cuts_df <- data.frame( cut, predict(dmod, data.frame(cut), se = TRUE)[c("fit", "se.fit")] ) ggplot(cuts_df) + aes( x = cut, y = fit, ymin = fit - se.fit, ymax = fit + se.fit, colour = cut ) + geom_pointrange() # Using annotate p <- ggplot(mtcars, aes(x = wt, y = mpg)) + geom_point() p p + annotate( "rect", xmin = 2, xmax = 3.5, ymin = 2, ymax = 25, fill = "dark grey", alpha = .5 ) # Geom_segment examples p + geom_segment( aes(x = 2, y = 15, xend = 2, yend = 25), arrow = arrow(length = unit(0.5, "cm")) ) p + geom_segment( aes(x = 2, y = 15, xend = 3, yend = 15), arrow = arrow(length = unit(0.5, "cm")) ) p + geom_segment( aes(x = 5, y = 30, xend = 3.5, yend = 25), arrow = arrow(length = unit(0.5, "cm")) ) # You can also use geom_segment() to recreate plot(type = "h") # from base R: set.seed(1) counts <- as.data.frame(table(x = rpois(100, 5))) counts$x <- as.numeric(as.character(counts$x)) with(counts, plot(x, Freq, type = "h", lwd = 10)) ggplot(counts, aes(x = x, y = Freq)) + geom_segment(aes(yend = 0, xend = x), size = 10)This function adds geoms to a plot, but unlike a typical geom function, the properties of the geoms are not mapped from variables of a data frame, but are instead passed in as vectors. This is useful for adding small annotations (such as text labels) or if you have your data in vectors, and for some reason don't want to put them in a data frame.
annotate( geom, x = NULL, y = NULL, xmin = NULL, xmax = NULL, ymin = NULL, ymax = NULL, xend = NULL, yend = NULL, ..., na.rm = FALSE )p <- ggplot(mtcars, aes(x = wt, y = mpg)) + geom_point() p + annotate("text", x = 4, y = 25, label = "Some text") p + annotate("text", x = 2:5, y = 25, label = "Some text") p + annotate("rect", xmin = 3, xmax = 4.2, ymin = 12, ymax = 21, alpha = .2) p + annotate("segment", x = 2.5, xend = 4, y = 15, yend = 25, colour = "blue") p + annotate("pointrange", x = 3.5, y = 20, ymin = 12, ymax = 28, colour = "red", size = 2.5, linewidth = 1.5) p + annotate("text", x = 2:3, y = 20:21, label = c("my label", "label 2")) p + annotate("text", x = 4, y = 25, label = "italic(R) ^ 2 == 0.75", parse = TRUE) p + annotate("text", x = 4, y = 25, label = "paste(italic(R) ^ 2, \" = .75\")", parse = TRUE)This is a quick and dirty way to get map data (from the maps package) onto your plot. This is a good place to start if you need some crude reference lines, but you'll typically want something more sophisticated for communication graphics.
annotation_borders( database = "world", regions = ".", fill = NA, colour = "grey50", xlim = NULL, ylim = NULL, ... ) borders(...) # Deprecatedif (require("maps")) data(us.cities) capitals <- subset(us.cities, capital == 2) ggplot(capitals, aes(long, lat)) + annotation_borders("state") + geom_point(aes(size = pop)) + scale_size_area() + coord_quickmap() if (require("maps")) # Same map, with some world context ggplot(capitals, aes(long, lat)) + annotation_borders("world", xlim = c(-130, -60), ylim = c(20, 50)) + geom_point(aes(size = pop)) + scale_size_area() + coord_quickmap()This is a special geom intended for use as static annotations that are the same in every panel. These annotations will not affect scales (i.e. the x and y axes will not grow to cover the range of the grob, and the grob will not be modified by any ggplot settings or mappings).
annotation_custom(grob, xmin = -Inf, xmax = Inf, ymin = -Inf, ymax = Inf)# Dummy plot df <- data.frame(x = 1:10, y = 1:10) base <- ggplot(df, aes(x, y)) + geom_blank() + theme_bw() # Full panel annotation base + annotation_custom( grob = grid::roundrectGrob(), xmin = -Inf, xmax = Inf, ymin = -Inf, ymax = Inf ) # Inset plot df2 <- data.frame(x = 1 , y = 1) g <- ggplotGrob(ggplot(df2, aes(x, y)) + geom_point() + theme(plot.background = element_rect(colour = "black"))) base + annotation_custom(grob = g, xmin = 1, xmax = 10, ymin = 8, ymax = 10)htmlhttps://lifecycle.r-lib.org/articles/stages.html#supersededlifecycle-superseded.svgoptions: alt='[Superseded]'[Superseded] This function is superseded by using [=guide_axis_logticks]guide_axis_logticks(). This annotation adds log tick marks with diminishing spacing. These tick marks probably make sense only for base 10.
annotation_logticks( base = 10, sides = "bl", outside = FALSE, scaled = TRUE, short = unit(0.1, "cm"), mid = unit(0.2, "cm"), long = unit(0.3, "cm"), colour = "black", linewidth = 0.5, linetype = 1, alpha = 1, color = NULL, ..., size = deprecated() )# Make a log-log plot (without log ticks) a <- ggplot(msleep, aes(bodywt, brainwt)) + geom_point(na.rm = TRUE) + scale_x_log10( breaks = scales::trans_breaks("log10", \(x) 10^x), labels = scales::trans_format("log10", scales::math_format(10^.x)) ) + scale_y_log10( breaks = scales::trans_breaks("log10", \(x) 10^x), labels = scales::trans_format("log10", scales::math_format(10^.x)) ) + theme_bw() a + annotation_logticks() # Default: log ticks on bottom and left a + annotation_logticks(sides = "lr") # Log ticks for y, on left and right a + annotation_logticks(sides = "trbl") # All four sides a + annotation_logticks(sides = "lr", outside = TRUE) + coord_cartesian(clip = "off") # Ticks outside plot # Hide the minor grid lines because they don't align with the ticks a + annotation_logticks(sides = "trbl") + theme(panel.grid.minor = element_blank()) # Another way to get the same results as 'a' above: log-transform the data before # plotting it. Also hide the minor grid lines. b <- ggplot(msleep, aes(log10(bodywt), log10(brainwt))) + geom_point(na.rm = TRUE) + scale_x_continuous(name = "body", labels = scales::label_math(10^.x)) + scale_y_continuous(name = "brain", labels = scales::label_math(10^.x)) + theme_bw() + theme(panel.grid.minor = element_blank()) b + annotation_logticks() # Using a coordinate transform requires scaled = FALSE t <- ggplot(msleep, aes(bodywt, brainwt)) + geom_point() + coord_transform(x = "log10", y = "log10") + theme_bw() t + annotation_logticks(scaled = FALSE) # Change the length of the ticks a + annotation_logticks( short = unit(.5,"mm"), mid = unit(3,"mm"), long = unit(4,"mm") )Display a fixed map on a plot. This function predates the [=geom_sf]geom_sf() framework and does not work with sf geometry columns as input. However, it can be used in conjunction with geom_sf() layers and/or [=coord_sf]coord_sf() (see examples).
annotation_map(map, ...)if (requireNamespace("maps", quietly = TRUE)) # location of cities in North Carolina df <- data.frame( name = c("Charlotte", "Raleigh", "Greensboro"), lat = c(35.227, 35.772, 36.073), long = c(-80.843, -78.639, -79.792) ) p <- ggplot(df, aes(x = long, y = lat)) + annotation_map( map_data("state"), fill = "antiquewhite", colour = "darkgrey" ) + geom_point(color = "blue") + geom_text( aes(label = name), hjust = 1.105, vjust = 1.05, color = "blue" ) # use without coord_sf() is possible but not recommended p + xlim(-84, -76) + ylim(34, 37.2) if (requireNamespace("sf", quietly = TRUE)) # use with coord_sf() for appropriate projection p + coord_sf( crs = sf::st_crs(3347), default_crs = sf::st_crs(4326), # data is provided as long-lat xlim = c(-84, -76), ylim = c(34, 37.2) ) # you can mix annotation_map() and geom_sf() nc <- sf::st_read(system.file("shape/nc.shp", package = "sf"), quiet = TRUE) p + geom_sf( data = nc, inherit.aes = FALSE, fill = NA, color = "black", linewidth = 0.1 ) + coord_sf(crs = sf::st_crs(3347), default_crs = sf::st_crs(4326))This is a special version of [=geom_raster]geom_raster() optimised for static annotations that are the same in every panel. These annotations will not affect scales (i.e. the x and y axes will not grow to cover the range of the raster, and the raster must already have its own colours). This is useful for adding bitmap images.
annotation_raster(raster, xmin, xmax, ymin, ymax, interpolate = FALSE)# Generate data rainbow <- matrix(hcl(seq(0, 360, length.out = 50 * 50), 80, 70), nrow = 50) ggplot(mtcars, aes(mpg, wt)) + geom_point() + annotation_raster(rainbow, 15, 20, 3, 4) # To fill up whole plot ggplot(mtcars, aes(mpg, wt)) + annotation_raster(rainbow, -Inf, Inf, -Inf, Inf) + geom_point() rainbow2 <- matrix(hcl(seq(0, 360, length.out = 10), 80, 70), nrow = 1) ggplot(mtcars, aes(mpg, wt)) + annotation_raster(rainbow2, -Inf, Inf, -Inf, Inf) + geom_point() rainbow2 <- matrix(hcl(seq(0, 360, length.out = 10), 80, 70), nrow = 1) ggplot(mtcars, aes(mpg, wt)) + annotation_raster(rainbow2, -Inf, Inf, -Inf, Inf, interpolate = TRUE) + geom_point()This will not include the object's super member.
as.listggproto(x, inherit = TRUE, ...)This transforms objects to labeller functions. Used internally by [=labeller]labeller().
as_labeller(x, default = label_value, multi_line = TRUE)p <- ggplot(mtcars, aes(disp, drat)) + geom_point() p + facet_wrap(~am) # Rename labels on the fly with a lookup character vector to_string <- as_labeller(c(`0` = "Zero", `1` = "One")) p + facet_wrap(~am, labeller = to_string) # Quickly transform a function operating on character vectors to a # labeller function: appender <- function(string, suffix = "-foo") paste0(string, suffix) p + facet_wrap(~am, labeller = as_labeller(appender)) # If you have more than one faceting variable, be sure to dispatch # your labeller to the right variable with labeller() p + facet_grid(cyl ~ am, labeller = labeller(am = to_string))autolayer() uses ggplot2 to draw a particular layer for an object of a particular class in a single command. This defines the S3 generic that other classes and packages can extend.
autolayer(object, ...)There are three functions to make plotting particular data types easier: autoplot(), autolayer() and fortify(). These are S3 generics for which other packages can write methods to display classes of data. The three functions are complementary and allow different levels of customisation. Below we'll explore implementing this series of methods to automate plotting of some class. Let's suppose we are writing a packages that has a class called 'my_heatmap', that wraps a matrix and we'd like users to easily plot this heatmap. html<div class="sourceCode r">my_heatmap <- function(...) \ m <- matrix(...) class(m) <- c("my_heatmap", class(m)) m \ my_data <- my_heatmap(volcano) html</div>
autoplot() uses ggplot2 to draw a particular plot for an object of a particular class in a single command. This defines the S3 generic that other classes and packages can extend.
autoplot(object, ...)Benchmark plot creation time. Broken down into construct, build, render and draw times.
benchplot(x)benchplot(ggplot(mtcars, aes(mpg, wt)) + geom_point()) benchplot(ggplot(mtcars, aes(mpg, wt)) + geom_point() + facet_grid(. ~ cyl)) # With tidy eval: p <- expr(ggplot(mtcars, aes(mpg, wt)) + geom_point()) benchplot(!!p)These functions are what underpins the ability of certain geoms to work automatically in both directions. See the Extending ggplot2 vignette for how they are used when implementing Geom, Stat, and Position classes.
has_flipped_aes( data, params = list(), main_is_orthogonal = NA, range_is_orthogonal = NA, group_has_equal = FALSE, ambiguous = FALSE, main_is_continuous = FALSE, main_is_optional = FALSE, default = FALSE ) flip_data(data, flip = NULL) flipped_names(flip = FALSE)Binning scale constructor
binned_scale( aesthetics, scale_name = deprecated(), palette, name = waiver(), breaks = waiver(), labels = waiver(), limits = NULL, rescaler = rescale, oob = squish, expand = waiver(), na.value = NA_real_, n.breaks = NULL, nice.breaks = TRUE, right = TRUE, transform = "identity", trans = deprecated(), show.limits = FALSE, guide = "bins", position = "left", fallback.palette = NULL, call = caller_call(), super = ScaleBinned )Calculate the element properties, by inheriting properties from its parents
calc_element( element, theme, verbose = FALSE, skip_blank = FALSE, call = caller_env() )t <- theme_grey() calc_element('text', t) # Compare the "raw" element definition to the element with calculated inheritance t$axis.text.x calc_element('axis.text.x', t, verbose = TRUE) # This reports that axis.text.x inherits from axis.text, # which inherits from text. You can view each of them with: t$axis.text.x t$axis.text t$textThis function makes an attempt to estimate whether the graphics device is able to render newer graphics features.
check_device( feature, action = "warn", op = NULL, maybe = FALSE, call = caller_env() )# Typically you'd run `check_device()` inside a function that might produce # advanced graphics. # The check is designed for use in control flow statements in the test mode if (check_device("patterns", action = "test")) print("Yay") else print("Nay") # Automatically throw a warning when unavailable if (check_device("compositing", action = "warn")) print("Yay") else print("Nay") # Possibly throw an error try(check_device("glyphs", action = "abort"))The S7 object oriented programming system requires class definitions. Here, we provide definitions of classes that are home to ggplot2.
The ggplot class collects the needed information to render a plot. This class can be constructed using the [=ggplot]ggplot() function.
class_ggplot( data = waiver(), ..., layers = list(), scales = NULL, guides = NULL, mapping = aes(), theme = NULL, coordinates = coord_cartesian(default = TRUE), facet = facet_null(), layout = NULL, labels = labs(), meta = list(), plot_env = parent.frame() )The ggplot built class is an intermediate class and represents a processed ggplot object ready for rendering. It is constructed by calling [=ggplot_build]ggplot_build() on a [=class_ggplot]ggplot object and is not meant to be instantiated directly. The class can be rendered to a gtable object by calling the [=ggplot_gtable]ggplot_gtable() function on a ggplot built class object.
class_ggplot_built(..., data = NULL, layout = NULL, plot = NULL)The labels class holds a list with label information to display as titles of plot components. The preferred way to construct an object of the labels class is to use the [=labs]labs() function.
class_labels(labels = list(), ...)The mapping class holds a list of quoted expressions ([rlang:topic-quosure]quosures) or constants. An object is typically constructed using the [=aes]aes() function.
class_mapping(x = list(), ..., env = globalenv())The theme class holds information on how non-data elements of the plot should be rendered. The preferred way to construct an object of this class is through the [=theme]theme() function.
class_theme(elements = list(), ..., complete = FALSE, validate = TRUE)Take input data and define a mapping between faceting variables and ROW, COL and PANEL keys
combine_vars(data, env = emptyenv(), vars = NULL, drop = TRUE)This function takes a theme and completes it so that it can be used downstream to render theme elements. Missing elements are filled in and every item is validated to the specifications of the element tree.
complete_theme(theme = NULL, default = theme_get())my_theme <- theme(line = element_line(colour = "red")) complete_theme(my_theme)Continuous scale constructor
continuous_scale( aesthetics, scale_name = deprecated(), palette, name = waiver(), breaks = waiver(), minor_breaks = waiver(), n.breaks = NULL, labels = waiver(), limits = NULL, rescaler = rescale, oob = censor, expand = waiver(), na.value = NA, transform = "identity", trans = deprecated(), guide = "legend", position = "left", fallback.palette = NULL, call = caller_call(), super = ScaleContinuous )The Cartesian coordinate system is the most familiar, and common, type of coordinate system. Setting limits on the coordinate system will zoom the plot (like you're looking at it with a magnifying glass), and will not change the underlying data like setting limits on a scale will.
coord_cartesian( xlim = NULL, ylim = NULL, expand = TRUE, default = FALSE, clip = "on", reverse = "none", ratio = NULL )# There are two ways of zooming the plot display: with scales or # with coordinate systems. They work in two rather different ways. p <- ggplot(mtcars, aes(disp, wt)) + geom_point() + geom_smooth() p # Setting the limits on a scale converts all values outside the range to NA. p + scale_x_continuous(limits = c(325, 500)) # Setting the limits on the coordinate system performs a visual zoom. # The data is unchanged, and we just view a small portion of the original # plot. Note how smooth continues past the points visible on this plot. p + coord_cartesian(xlim = c(325, 500)) # By default, the same expansion factor is applied as when setting scale # limits. You can set the limits precisely by setting expand = FALSE p + coord_cartesian(xlim = c(325, 500), expand = FALSE) # Similarly, we can use expand = FALSE to turn off expansion with the # default limits p + coord_cartesian(expand = FALSE) # Using a fixed ratio: 1 y-axis unit is 100 x-axis units # Plot window can be resized and aspect ratio will be maintained p + coord_cartesian(ratio = 100) # You can see the same thing with this 2d histogram d <- ggplot(diamonds, aes(carat, price)) + stat_bin_2d(bins = 25, colour = "white") d # When zooming the scale, the we get 25 new bins that are the same # size on the plot, but represent smaller regions of the data space d + scale_x_continuous(limits = c(0, 1)) # When zooming the coordinate system, we see a subset of original 50 bins, # displayed bigger d + coord_cartesian(xlim = c(0, 1))A fixed scale coordinate system forces a specified ratio between the physical representation of data units on the axes. The ratio represents the number of units on the y-axis equivalent to one unit on the x-axis. The default, ratio = 1, ensures that one unit on the x-axis is the same length as one unit on the y-axis. Ratios higher than one make units on the y axis longer than units on the x-axis, and vice versa. This is similar to [MASS:eqscplot]MASS::eqscplot(), but it works for all types of graphics.
coord_fixed(ratio = 1, ...)# ensures that the ranges of axes are equal to the specified ratio by # adjusting the plot aspect ratio p <- ggplot(mtcars, aes(mpg, wt)) + geom_point() p + coord_fixed(ratio = 1) p + coord_fixed(ratio = 5) p + coord_fixed(ratio = 1/5) p + coord_fixed(xlim = c(15, 30)) # Resize the plot to see that the specified aspect ratio is maintainedhtmlhttps://lifecycle.r-lib.org/articles/stages.html#supersededlifecycle-superseded.svgoptions: alt='[Superseded]'[Superseded] This function is superseded because in many cases, coord_flip() can easily be replaced by swapping the x and y aesthetics, or optionally setting the orientation argument in geom and stat layers. coord_flip() is useful for geoms and statistics that do not support the orientation setting, and converting the display of y conditional on x, to x conditional on y.
coord_flip(xlim = NULL, ylim = NULL, expand = TRUE, clip = "on")# The preferred method of creating horizontal instead of vertical boxplots ggplot(diamonds, aes(price, cut)) + geom_boxplot() # Using `coord_flip()` to make the same plot ggplot(diamonds, aes(cut, price)) + geom_boxplot() + coord_flip() # With swapped aesthetics, the y-scale controls the left axis ggplot(diamonds, aes(y = carat)) + geom_histogram() + scale_y_reverse() # In `coord_flip()`, the x-scale controls the left axis ggplot(diamonds, aes(carat)) + geom_histogram() + coord_flip() + scale_x_reverse() # In line and area plots, swapped aesthetics require an explicit orientation df <- data.frame(a = 1:5, b = (1:5) ^ 2) ggplot(df, aes(b, a)) + geom_area(orientation = "y") # The same plot with `coord_flip()` ggplot(df, aes(a, b)) + geom_area() + coord_flip()htmlhttps://lifecycle.r-lib.org/articles/stages.html#supersededlifecycle-superseded.svgoptions: alt='[Superseded]'[Superseded] coord_map() projects a portion of the earth, which is approximately spherical, onto a flat 2D plane using any projection defined by the mapproj package. Map projections do not, in general, preserve straight lines, so this requires considerable computation. coord_quickmap() is a quick approximation that does preserve straight lines. It works best for smaller areas closer to the equator. Both coord_map() and coord_quickmap() are superseded by [=coord_sf]coord_sf(), and should no longer be used in new code. All regular (non-sf) geoms can be used with coord_sf() by setting the default coordinate system via the default_crs argument. See also the examples for [=annotation_map]annotation_map() and [=geom_map]geom_map().
coord_map( projection = "mercator", ..., parameters = NULL, orientation = NULL, xlim = NULL, ylim = NULL, clip = "on" ) coord_quickmap(xlim = NULL, ylim = NULL, expand = TRUE, clip = "on")if (require("maps")) nz <- map_data("nz") # Prepare a map of NZ nzmap <- ggplot(nz, aes(x = long, y = lat, group = group)) + geom_polygon(fill = "white", colour = "black") # Plot it in cartesian coordinates nzmap if (require("maps")) # With correct mercator projection nzmap + coord_map() if (require("maps")) # With the aspect ratio approximation nzmap + coord_quickmap() if (require("maps")) # Other projections nzmap + coord_map("azequalarea", orientation = c(-36.92, 174.6, 0)) if (require("maps")) states <- map_data("state") usamap <- ggplot(states, aes(long, lat, group = group)) + geom_polygon(fill = "white", colour = "black") # Use cartesian coordinates usamap if (require("maps")) # With mercator projection usamap + coord_map() if (require("maps")) # See ?mapproject for coordinate systems and their parameters usamap + coord_map("gilbert") if (require("maps")) # For most projections, you'll need to set the orientation yourself # as the automatic selection done by mapproject is not available to # ggplot usamap + coord_map("orthographic") if (require("maps")) usamap + coord_map("conic", lat0 = 30) if (require("maps")) usamap + coord_map("bonne", lat0 = 50) if (require("maps")) # World map, using geom_path instead of geom_polygon world <- map_data("world") worldmap <- ggplot(world, aes(x = long, y = lat, group = group)) + geom_path() + scale_y_continuous(breaks = (-2:2) * 30) + scale_x_continuous(breaks = (-4:4) * 45) # Orthographic projection with default orientation (looking down at North pole) worldmap + coord_map("ortho") if (require("maps")) # Looking up up at South Pole worldmap + coord_map("ortho", orientation = c(-90, 0, 0)) if (require("maps")) # Centered on New York (currently has issues with closing polygons) worldmap + coord_map("ortho", orientation = c(41, -74, 0))This function "munches" lines, dividing each line into many small pieces so they can be transformed independently. Used inside geom functions.
coord_munch(coord, data, range, segment_length = 0.01, is_closed = FALSE)The polar coordinate system is most commonly used for pie charts, which are a stacked bar chart in polar coordinates. htmlhttps://lifecycle.r-lib.org/articles/stages.html#supersededlifecycle-superseded.svgoptions: alt='[Superseded]'[Superseded]: coord_polar() has been in favour of coord_radial().
coord_polar(theta = "x", start = 0, direction = 1, clip = "on") coord_radial( theta = "x", start = 0, end = NULL, thetalim = NULL, rlim = NULL, expand = TRUE, direction = deprecated(), clip = "off", r.axis.inside = NULL, rotate.angle = FALSE, inner.radius = 0, reverse = "none", r_axis_inside = deprecated(), rotate_angle = deprecated() )# NOTE: Use these plots with caution - polar coordinates has # major perceptual problems. The main point of these examples is # to demonstrate how these common plots can be described in the # grammar. Use with EXTREME caution. # A pie chart = stacked bar chart + polar coordinates pie <- ggplot(mtcars, aes(x = factor(1), fill = factor(cyl))) + geom_bar(width = 1) pie + coord_radial(theta = "y", expand = FALSE) # A coxcomb plot = bar chart + polar coordinates cxc <- ggplot(mtcars, aes(x = factor(cyl))) + geom_bar(width = 1, colour = "black") cxc + coord_radial(expand = FALSE) # A new type of plot? cxc + coord_radial(theta = "y", expand = FALSE) # The bullseye chart pie + coord_radial(expand = FALSE) # Hadley's favourite pie chart df <- data.frame( variable = c("does not resemble", "resembles"), value = c(20, 80) ) ggplot(df, aes(x = "", y = value, fill = variable)) + geom_col(width = 1) + scale_fill_manual(values = c("red", "yellow")) + coord_radial("y", start = pi / 3, expand = FALSE) + labs(title = "Pac man") # Windrose + doughnut plot if (require("ggplot2movies")) movies$rrating <- cut_interval(movies$rating, length = 1) movies$budgetq <- cut_number(movies$budget, 4) doh <- ggplot(movies, aes(x = rrating, fill = budgetq)) # Wind rose doh + geom_bar(width = 1) + coord_radial(expand = FALSE) # Race track plot doh + geom_bar(width = 0.9, position = "fill") + coord_radial(theta = "y", expand = FALSE) # A partial polar plot ggplot(mtcars, aes(disp, mpg)) + geom_point() + coord_radial(start = -0.4 * pi, end = 0.4 * pi, inner.radius = 0.3) # Similar with coord_cartesian(), you can set limits. ggplot(mtcars, aes(disp, mpg)) + geom_point() + coord_radial( start = -0.4 * pi, end = 0.4 * pi, inner.radius = 0.3, thetalim = c(200, 300), rlim = c(15, 30), )coord_transform() is different to scale transformations in that it occurs after statistical transformation and will affect the visual appearance of geoms - there is no guarantee that straight lines will continue to be straight.
coord_transform( x = "identity", y = "identity", xlim = NULL, ylim = NULL, limx = deprecated(), limy = deprecated(), clip = "on", expand = TRUE, reverse = "none" ) coord_trans(...)# See ?geom_boxplot for other examples # Three ways of doing transformation in ggplot: # * by transforming the data ggplot(diamonds, aes(log10(carat), log10(price))) + geom_point() # * by transforming the scales ggplot(diamonds, aes(carat, price)) + geom_point() + scale_x_log10() + scale_y_log10() # * by transforming the coordinate system: ggplot(diamonds, aes(carat, price)) + geom_point() + coord_transform(x = "log10", y = "log10") # The difference between transforming the scales and # transforming the coordinate system is that scale # transformation occurs BEFORE statistics, and coordinate # transformation afterwards. Coordinate transformation also # changes the shape of geoms: d <- subset(diamonds, carat > 0.5) ggplot(d, aes(carat, price)) + geom_point() + geom_smooth(method = "lm") + scale_x_log10() + scale_y_log10() ggplot(d, aes(carat, price)) + geom_point() + geom_smooth(method = "lm") + coord_transform(x = "log10", y = "log10") # Here I used a subset of diamonds so that the smoothed line didn't # drop below zero, which obviously causes problems on the log-transformed # scale # With a combination of scale and coordinate transformation, it's # possible to do back-transformations: ggplot(diamonds, aes(carat, price)) + geom_point() + geom_smooth(method = "lm") + scale_x_log10() + scale_y_log10() + coord_transform(x = scales::transform_exp(10), y = scales::transform_exp(10)) # cf. ggplot(diamonds, aes(carat, price)) + geom_point() + geom_smooth(method = "lm") # Also works with discrete scales set.seed(1) df <- data.frame(a = abs(rnorm(26)),letters) plot <- ggplot(df,aes(a,letters)) + geom_point() plot + coord_transform(x = "log10") plot + coord_transform(x = "sqrt")cut_interval() makes n groups with equal range, cut_number() makes n groups with (approximately) equal numbers of observations; cut_width() makes groups of width width.
cut_interval(x, n = NULL, length = NULL, ...) cut_number(x, n = NULL, ...) cut_width(x, width, center = NULL, boundary = NULL, closed = "right", ...)table(cut_interval(1:100, 10)) table(cut_interval(1:100, 11)) set.seed(1) table(cut_number(runif(1000), 10)) table(cut_width(runif(1000), 0.1)) table(cut_width(runif(1000), 0.1, boundary = 0)) table(cut_width(runif(1000), 0.1, center = 0)) table(cut_width(runif(1000), 0.1, labels = FALSE))Date/time scale constructor
datetime_scale( aesthetics, transform, trans = deprecated(), palette, breaks = pretty_breaks(), minor_breaks = waiver(), labels = waiver(), date_breaks = waiver(), date_labels = waiver(), date_minor_breaks = waiver(), timezone = NULL, guide = "legend", call = caller_call(), ... )A dataset containing the prices and other attributes of almost 54,000 diamonds. The variables are as follows:
diamondsDiscrete scale constructor
discrete_scale( aesthetics, scale_name = deprecated(), palette, name = waiver(), breaks = waiver(), minor_breaks = waiver(), labels = waiver(), limits = NULL, expand = waiver(), na.translate = TRUE, na.value = NA, drop = TRUE, guide = "legend", position = "left", fallback.palette = NULL, call = caller_call(), super = ScaleDiscrete )Each geom has an associated function that draws the key when the geom needs to be displayed in a legend. These functions are called draw_key_*(), where * stands for the name of the respective key glyph. The key glyphs can be customized for individual geoms by providing a geom with the key_glyph argument (see [=layer]layer() or examples below.)
draw_key_point(data, params, size) draw_key_abline(data, params, size) draw_key_rect(data, params, size) draw_key_polygon(data, params, size) draw_key_blank(data, params, size) draw_key_boxplot(data, params, size) draw_key_crossbar(data, params, size) draw_key_path(data, params, size) draw_key_vpath(data, params, size) draw_key_dotplot(data, params, size) draw_key_linerange(data, params, size) draw_key_pointrange(data, params, size) draw_key_smooth(data, params, size) draw_key_text(data, params, size) draw_key_label(data, params, size) draw_key_vline(data, params, size) draw_key_timeseries(data, params, size)p <- ggplot(economics, aes(date, psavert, color = "savings rate")) # key glyphs can be specified by their name p + geom_line(key_glyph = "timeseries") # key glyphs can be specified via their drawing function p + geom_line(key_glyph = draw_key_rect)This dataset was produced from US economic time series data available from https://fred.stlouisfed.org/. economics is in "wide" format, economics_long is in "long" format.
economics economics_longThe element_grob() function is vestigial and draw_element() should be used instead.
element_grob(element, ...)Given a theme object and element name, returns a grob for the element. Uses [=element_grob]element_grob() to generate the grob.
element_render(theme, element, ..., name = NULL)htmlhttps://lifecycle.r-lib.org/articles/stages.html#supersededlifecycle-superseded.svgoptions: alt='[Superseded]'[Superseded]: It is recommended to pass a function to the limits argument in scales instead. For example: scale_x_continuous(limits = ~range(.x, 0)) to include zero. Sometimes you may want to ensure limits include a single value, for all panels or all plots. This function is a thin wrapper around [=geom_blank]geom_blank() that makes it easy to add such values.
expand_limits(...)p <- ggplot(mtcars, aes(mpg, wt)) + geom_point() p + expand_limits(x = 0) p + expand_limits(y = c(1, 9)) p + expand_limits(x = 0, y = 0) ggplot(mtcars, aes(mpg, wt)) + geom_point(aes(colour = cyl)) + expand_limits(colour = seq(2, 10, by = 2)) ggplot(mtcars, aes(mpg, wt)) + geom_point(aes(colour = factor(cyl))) + expand_limits(colour = factor(seq(2, 10, by = 2)))This is a convenience function for generating scale expansion vectors for the expand argument of [=scale_x_continuous]scale_(x|y)_continuous and [=scale_x_discrete]scale_(x|y)_discrete. The expansion vectors are used to add some space between the data and the axes.
expansion(mult = 0, add = 0) expand_scale(mult = 0, add = 0)# No space below the bars but 10% above them ggplot(mtcars) + geom_bar(aes(x = factor(cyl))) + scale_y_continuous(expand = expansion(mult = c(0, .1))) # Add 2 units of space on the left and right of the data ggplot(subset(diamonds, carat > 2), aes(cut, clarity)) + geom_jitter() + scale_x_discrete(expand = expansion(add = 2)) # Reproduce the default range expansion used # when the 'expand' argument is not specified ggplot(subset(diamonds, carat > 2), aes(cut, price)) + geom_jitter() + scale_x_discrete(expand = expansion(add = .6)) + scale_y_continuous(expand = expansion(mult = .05))facet_grid() forms a matrix of panels defined by row and column faceting variables. It is most useful when you have two discrete variables, and all combinations of the variables exist in the data. If you have only one variable with many levels, try [=facet_wrap]facet_wrap().
facet_grid( rows = NULL, cols = NULL, scales = "fixed", space = "fixed", shrink = TRUE, labeller = "label_value", as.table = TRUE, switch = NULL, drop = TRUE, margins = FALSE, axes = "margins", axis.labels = "all", facets = deprecated() )p <- ggplot(mpg, aes(displ, cty)) + geom_point() # Use vars() to supply variables from the dataset: p + facet_grid(rows = vars(drv)) p + facet_grid(cols = vars(cyl)) p + facet_grid(vars(drv), vars(cyl)) # To change plot order of facet grid, # change the order of variable levels with factor() # If you combine a facetted dataset with a dataset that lacks those # faceting variables, the data will be repeated across the missing # combinations: df <- data.frame(displ = mean(mpg$displ), cty = mean(mpg$cty)) p + facet_grid(cols = vars(cyl)) + geom_point(data = df, colour = "red", size = 2) # When scales are constant, duplicated axes can be shown with # or without labels ggplot(mpg, aes(cty, hwy)) + geom_point() + facet_grid(year ~ drv, axes = "all", axis.labels = "all_x") # Free scales ------------------------------------------------------- # You can also choose whether the scales should be constant # across all panels (the default), or whether they should be allowed # to vary mt <- ggplot(mtcars, aes(mpg, wt, colour = factor(cyl))) + geom_point() mt + facet_grid(vars(cyl), scales = "free") # If scales and space are free, then the mapping between position # and values in the data will be the same across all panels. This # is particularly useful for categorical axes ggplot(mpg, aes(drv, model)) + geom_point() + facet_grid(manufacturer ~ ., scales = "free", space = "free") + theme(strip.text.y = element_text(angle = 0)) # Margins ---------------------------------------------------------- # Margins can be specified logically (all yes or all no) or for specific # variables as (character) variable names mg <- ggplot(mtcars, aes(x = mpg, y = wt)) + geom_point() mg + facet_grid(vs + am ~ gear, margins = TRUE) mg + facet_grid(vs + am ~ gear, margins = "am") # when margins are made over "vs", since the facets for "am" vary # within the values of "vs", the marginal facet for "vs" is also # a margin over "am". mg + facet_grid(vs + am ~ gear, margins = "vs")Facet specification: a single panel.
facet_null(shrink = TRUE)# facet_null is the default faceting specification if you # don't override it with facet_grid or facet_wrap ggplot(mtcars, aes(mpg, wt)) + geom_point()facet_wrap() wraps a 1d sequence of panels into 2d. This is generally a better use of screen space than [=facet_grid]facet_grid() because most displays are roughly rectangular.
facet_wrap( facets, nrow = NULL, ncol = NULL, scales = "fixed", space = "fixed", shrink = TRUE, labeller = "label_value", as.table = TRUE, switch = deprecated(), drop = TRUE, dir = "h", strip.position = "top", axes = "margins", axis.labels = "all" )p <- ggplot(mpg, aes(displ, hwy)) + geom_point() # Use vars() to supply faceting variables: p + facet_wrap(vars(class)) # Control the number of rows and columns with nrow and ncol p + facet_wrap(vars(class), nrow = 4) # You can facet by multiple variables ggplot(mpg, aes(displ, hwy)) + geom_point() + facet_wrap(vars(cyl, drv)) # Use the `labeller` option to control how labels are printed: ggplot(mpg, aes(displ, hwy)) + geom_point() + facet_wrap(vars(cyl, drv), labeller = "label_both") # To change the order in which the panels appear, change the levels # of the underlying factor. mpg$class2 <- reorder(mpg$class, mpg$displ) ggplot(mpg, aes(displ, hwy)) + geom_point() + facet_wrap(vars(class2)) # By default, the same scales are used for all panels. You can allow # scales to vary across the panels with the `scales` argument. # Free scales make it easier to see patterns within each panel, but # harder to compare across panels. ggplot(mpg, aes(displ, hwy)) + geom_point() + facet_wrap(vars(class), scales = "free") # When scales are constant, duplicated axes can be shown with # or without labels ggplot(mpg, aes(displ, hwy)) + geom_point() + facet_wrap(vars(class), axes = "all", axis.labels = "all_y") # To repeat the same data in every panel, simply construct a data frame # that does not contain the faceting variable. ggplot(mpg, aes(displ, hwy)) + geom_point(data = transform(mpg, class = NULL), colour = "grey85") + geom_point() + facet_wrap(vars(class)) # Use `strip.position` to display the facet labels at the side of your # choice. Setting it to `bottom` makes it act as a subtitle for the axis. # This is typically used with free scales and a theme without boxes around # strip labels. ggplot(economics_long, aes(date, value)) + geom_line() + facet_wrap(vars(variable), scales = "free_y", nrow = 2, strip.position = "top") + theme(strip.background = element_blank(), strip.placement = "outside") # The two letters determine the starting position, so 'tr' starts # in the top-right. # The first letter determines direction, so 'tr' fills top-to-bottom. # `dir = "tr"` is equivalent to `dir = "v", as.table = FALSE` ggplot(mpg, aes(displ, hwy)) + geom_point() + facet_wrap(vars(class), dir = "tr")A 2d density estimate of the waiting and eruptions variables data faithful.
faithfuldThis works much like [scales:alpha]alpha() in that it modifies the transparency of fill colours. It differs in that fill_alpha() also attempts to set the transparency of <GridPattern> objects.
fill_alpha(fill, alpha)# Typical colour input fill_alpha("red", 0.5) if (utils::packageVersion("grid") > "4.2") # Pattern input fill_alpha(list(grid::linearGradient()), 0.5)These functions help detect the placement of panels in a gtable, if they are named with "panel" in the beginning. find_panel() returns the extend of the panel area, while panel_cols() and panel_rows() returns the columns and rows that contains panels respectively.
find_panel(table) panel_cols(table) panel_rows(table)Rather than using this function, I now recommend using the broom package, which implements a much wider range of methods. fortify() may be deprecated in the future.
fortify(model, data, ...)htmlhttps://lifecycle.r-lib.org/articles/stages.html#deprecatedlifecycle-deprecated.svgoptions: alt='[Deprecated]'[Deprecated] This function is deprecated because using broom::tidy() is a better solution to convert model objects.
fortifyglht(model, data, ...) fortifyconfint.glht(model, data, ...) fortifysummary.glht(model, data, ...) fortifycld(model, data, ...)if (require("multcomp") && require("broom")) withAutoprint(\ # examplesIf amod <- aov(breaks ~ wool + tension, data = warpbreaks) wht <- multcomp::glht(amod, linfct = multcomp::mcp(tension = "Tukey")) tidy(wht) # recommended fortify(wht) ggplot(tidy(wht), aes(contrast, estimate)) + geom_point() ci <- confint(wht) tidy(ci) # recommended fortify(ci) ggplot(tidy(confint(wht)), aes(contrast, estimate, ymin = conf.low, ymax = conf.high)) + geom_pointrange() smry <- summary(wht) tidy(smry) # recommended fortify(smry) ggplot(mapping = aes(contrast, estimate)) + geom_linerange(aes(ymin = conf.low, ymax = conf.high), data = tidy(ci)) + geom_point(aes(size = adj.p.value), data = tidy(smry)) + scale_size(transform = "reverse") cld <- multcomp::cld(wht) tidy(cld) # recommended fortify(cld) \) # examplesIfhtmlhttps://lifecycle.r-lib.org/articles/stages.html#deprecatedlifecycle-deprecated.svgoptions: alt='[Deprecated]'[Deprecated] This method is deprecated because using broom::augment() is a better solution to supplement data from a linear model. If you have missing values in your model data, you may need to refit the model with na.action = na.exclude.
fortifylm(model, data = model$model, ...)if (require("broom")) withAutoprint(\ # examplesIf mod <- lm(mpg ~ wt, data = mtcars) # Show augmented model head(augment(mod)) head(fortify(mod)) # Using augment to convert model to ready-to-plot data ggplot(augment(mod), aes(.fitted, .resid)) + geom_point() + geom_hline(yintercept = 0) + geom_smooth(se = FALSE) # Colouring by original data not included in the model ggplot(augment(mod, mtcars), aes(.fitted, .std.resid, colour = factor(cyl))) + geom_point() \) # examplesIfhtmlhttps://lifecycle.r-lib.org/articles/stages.html#deprecatedlifecycle-deprecated.svgoptions: alt='[Deprecated]'[Deprecated] This function turns a map into a data frame that can more easily be plotted with ggplot2.
fortifymap(model, data, ...)if (require("maps")) ca <- map("county", "ca", plot = FALSE, fill = TRUE) head(fortify(ca)) ggplot(ca, aes(long, lat)) + geom_polygon(aes(group = group)) if (require("maps")) tx <- map("county", "texas", plot = FALSE, fill = TRUE) head(fortify(tx)) ggplot(tx, aes(long, lat)) + geom_polygon(aes(group = group), colour = "white")htmlhttps://lifecycle.r-lib.org/articles/stages.html#deprecatedlifecycle-deprecated.svgoptions: alt='[Deprecated]'[Deprecated] To figure out the correct variable name for region, inspect as.data.frame(model).
fortifySpatialPolygonsDataFrame(model, data, region = NULL, ...) fortifySpatialPolygons(model, data, ...) fortifyPolygons(model, data, ...) fortifyPolygon(model, data, ...) fortifySpatialLinesDataFrame(model, data, ...) fortifyLines(model, data, ...) fortifyLine(model, data, ...)These geoms add reference lines (sometimes called rules) to a plot, either horizontal, vertical, or diagonal (specified by slope and intercept). These are useful for annotating plots.
geom_abline( mapping = NULL, data = NULL, stat = "identity", ..., slope, intercept, na.rm = FALSE, show.legend = NA, inherit.aes = FALSE ) geom_hline( mapping = NULL, data = NULL, stat = "identity", position = "identity", ..., yintercept, na.rm = FALSE, show.legend = NA, inherit.aes = FALSE ) geom_vline( mapping = NULL, data = NULL, stat = "identity", position = "identity", ..., xintercept, na.rm = FALSE, show.legend = NA, inherit.aes = FALSE )p <- ggplot(mtcars, aes(wt, mpg)) + geom_point() # Fixed values p + geom_vline(xintercept = 5) p + geom_vline(xintercept = 1:5) p + geom_hline(yintercept = 20) p + geom_abline() # Can't see it - outside the range of the data p + geom_abline(intercept = 20) # Calculate slope and intercept of line of best fit coef(lm(mpg ~ wt, data = mtcars)) p + geom_abline(intercept = 37, slope = -5) # But this is easier to do with geom_smooth: p + geom_smooth(method = "lm", se = FALSE) # To show different lines in different facets, use aesthetics p <- ggplot(mtcars, aes(mpg, wt)) + geom_point() + facet_wrap(~ cyl) mean_wt <- data.frame(cyl = c(4, 6, 8), wt = c(2.28, 3.11, 4.00)) p + geom_hline(aes(yintercept = wt), mean_wt) # You can also control other aesthetics ggplot(mtcars, aes(mpg, wt, colour = wt)) + geom_point() + geom_hline(aes(yintercept = wt, colour = wt), mean_wt) + facet_wrap(~ cyl)There are two types of bar charts: geom_bar() and geom_col(). geom_bar() makes the height of the bar proportional to the number of cases in each group (or if the weight aesthetic is supplied, the sum of the weights). If you want the heights of the bars to represent values in the data, use geom_col() instead. geom_bar() uses stat_count() by default: it counts the number of cases at each x position. geom_col() uses stat_identity(): it leaves the data as is.
geom_bar( mapping = NULL, data = NULL, stat = "count", position = "stack", ..., just = 0.5, lineend = "butt", linejoin = "mitre", na.rm = FALSE, show.legend = NA, inherit.aes = TRUE ) geom_col( mapping = NULL, data = NULL, stat = "identity", position = "stack", ..., just = 0.5, lineend = "butt", linejoin = "mitre", na.rm = FALSE, show.legend = NA, inherit.aes = TRUE ) stat_count( mapping = NULL, data = NULL, geom = "bar", position = "stack", ..., orientation = NA, na.rm = FALSE, show.legend = NA, inherit.aes = TRUE )# geom_bar is designed to make it easy to create bar charts that show # counts (or sums of weights) g <- ggplot(mpg, aes(class)) # Number of cars in each class: g + geom_bar() # Total engine displacement of each class g + geom_bar(aes(weight = displ)) # Map class to y instead to flip the orientation ggplot(mpg) + geom_bar(aes(y = class)) # Bar charts are automatically stacked when multiple bars are placed # at the same location. The order of the fill is designed to match # the legend g + geom_bar(aes(fill = drv)) # If you need to flip the order (because you've flipped the orientation) # call position_stack() explicitly: ggplot(mpg, aes(y = class)) + geom_bar(aes(fill = drv), position = position_stack(reverse = TRUE)) + theme(legend.position = "top") # To show (e.g.) means, you need geom_col() df <- data.frame(trt = c("a", "b", "c"), outcome = c(2.3, 1.9, 3.2)) ggplot(df, aes(trt, outcome)) + geom_col() # But geom_point() displays exactly the same information and doesn't # require the y-axis to touch zero. ggplot(df, aes(trt, outcome)) + geom_point() # You can also use geom_bar() with continuous data, in which case # it will show counts at unique locations df <- data.frame(x = rep(c(2.9, 3.1, 4.5), c(5, 10, 4))) ggplot(df, aes(x)) + geom_bar() # cf. a histogram of the same data ggplot(df, aes(x)) + geom_histogram(binwidth = 0.5) # Use `just` to control how columns are aligned with axis breaks: df <- data.frame(x = as.Date(c("2020-01-01", "2020-02-01")), y = 1:2) # Columns centered on the first day of the month ggplot(df, aes(x, y)) + geom_col(just = 0.5) # Columns begin on the first day of the month ggplot(df, aes(x, y)) + geom_col(just = 1)Divides the plane into rectangles, counts the number of cases in each rectangle, and then (by default) maps the number of cases to the rectangle's fill. This is a useful alternative to [=geom_point]geom_point() in the presence of overplotting.
geom_bin_2d( mapping = NULL, data = NULL, stat = "bin2d", position = "identity", ..., lineend = "butt", linejoin = "mitre", na.rm = FALSE, show.legend = NA, inherit.aes = TRUE ) stat_bin_2d( mapping = NULL, data = NULL, geom = "tile", position = "identity", ..., binwidth = NULL, bins = 30, breaks = NULL, drop = TRUE, boundary = NULL, closed = NULL, center = NULL, na.rm = FALSE, show.legend = NA, inherit.aes = TRUE )d <- ggplot(diamonds, aes(x, y)) + xlim(4, 10) + ylim(4, 10) d + geom_bin_2d() # You can control the size of the bins by specifying the number of # bins in each direction: d + geom_bin_2d(bins = 10) d + geom_bin_2d(bins = list(x = 30, y = 10)) # Or by specifying the width of the bins d + geom_bin_2d(binwidth = c(0.1, 0.1))The blank geom draws nothing, but can be a useful way of ensuring common scales between different plots. See [=expand_limits]expand_limits() for more details.
geom_blank( mapping = NULL, data = NULL, stat = "identity", position = "identity", ..., show.legend = NA, inherit.aes = TRUE )ggplot(mtcars, aes(wt, mpg)) # Nothing to see here!The boxplot compactly displays the distribution of a continuous variable. It visualises five summary statistics (the median, two hinges and two whiskers), and all "outlying" points individually.
geom_boxplot( mapping = NULL, data = NULL, stat = "boxplot", position = "dodge2", ..., outliers = TRUE, outlier.colour = NULL, outlier.color = NULL, outlier.fill = NULL, outlier.shape = NULL, outlier.size = NULL, outlier.stroke = 0.5, outlier.alpha = NULL, whisker.colour = NULL, whisker.color = NULL, whisker.linetype = NULL, whisker.linewidth = NULL, staple.colour = NULL, staple.color = NULL, staple.linetype = NULL, staple.linewidth = NULL, median.colour = NULL, median.color = NULL, median.linetype = NULL, median.linewidth = NULL, box.colour = NULL, box.color = NULL, box.linetype = NULL, box.linewidth = NULL, notch = FALSE, notchwidth = 0.5, staplewidth = 0, varwidth = FALSE, na.rm = FALSE, orientation = NA, show.legend = NA, inherit.aes = TRUE ) stat_boxplot( mapping = NULL, data = NULL, geom = "boxplot", position = "dodge2", ..., orientation = NA, coef = 1.5, quantile.type = 7, na.rm = FALSE, show.legend = NA, inherit.aes = TRUE )p <- ggplot(mpg, aes(class, hwy)) p + geom_boxplot() # Orientation follows the discrete axis ggplot(mpg, aes(hwy, class)) + geom_boxplot() p + geom_boxplot(notch = TRUE) p + geom_boxplot(varwidth = TRUE) p + geom_boxplot(fill = "white", colour = "#3366FF") # By default, outlier points match the colour of the box. Use # outlier.colour to override p + geom_boxplot(outlier.colour = "red", outlier.shape = 1) # Remove outliers when overlaying boxplot with original data points p + geom_boxplot(outlier.shape = NA) + geom_jitter(width = 0.2) # Boxplots are automatically dodged when any aesthetic is a factor p + geom_boxplot(aes(colour = drv)) # You can also use boxplots with continuous x, as long as you supply # a grouping variable. cut_width is particularly useful ggplot(diamonds, aes(carat, price)) + geom_boxplot() ggplot(diamonds, aes(carat, price)) + geom_boxplot(aes(group = cut_width(carat, 0.25))) # Adjust the transparency of outliers using outlier.alpha ggplot(diamonds, aes(carat, price)) + geom_boxplot(aes(group = cut_width(carat, 0.25)), outlier.alpha = 0.1) # It's possible to draw a boxplot with your own computations if you # use stat = "identity": set.seed(1) y <- rnorm(100) df <- data.frame( x = 1, y0 = min(y), y25 = quantile(y, 0.25), y50 = median(y), y75 = quantile(y, 0.75), y100 = max(y) ) ggplot(df, aes(x)) + geom_boxplot( aes(ymin = y0, lower = y25, middle = y50, upper = y75, ymax = y100), stat = "identity" )| Repository | Version | Published | First seen | Last seen | Docs |
|---|---|---|---|---|---|
| CRAN | 4.0.2 | 2026-02-03 | 2026-05-09 | 2026-05-09 | |
| CRAN | 4.0.1 | 2025-11-14 | 2026-05-09 | 2026-05-09 | |
| CRAN | 4.0.0 | 2025-09-11 | 2026-05-09 | 2026-05-09 | |
| CRAN | 3.5.2 | 2025-04-09 | 2026-05-09 | 2026-05-09 | |
| CRAN | 3.5.1 | 2024-04-23 | 2026-05-09 | 2026-05-09 | |
| CRAN | 3.5.0 | 2024-02-23 | 2026-05-09 | 2026-05-09 | |
| CRAN | 3.4.4 | 2023-10-12 | 2026-05-09 | 2026-05-09 | |
| CRAN | 3.4.3 | 2023-08-14 | 2026-05-09 | 2026-05-09 | |
| CRAN | 3.4.2 | 2023-04-03 | 2026-05-09 | 2026-05-09 | |
| CRAN | 3.4.1 | 2023-02-10 | 2026-05-09 | 2026-05-09 | |
| CRAN | 3.4.0 | 2022-11-04 | 2026-05-09 | 2026-05-09 | |
| CRAN | 3.3.6 | 2022-05-03 | 2026-05-09 | 2026-05-09 | |
| CRAN | 3.3.5 | 2021-06-25 | 2026-05-09 | 2026-05-09 | |
| CRAN | 3.3.4 | 2021-06-16 | 2026-05-09 | 2026-05-09 | |
| CRAN | 3.3.3 | 2020-12-30 | 2026-05-09 | 2026-05-09 | |
| CRAN | 3.3.2 | 2020-06-19 | 2026-05-09 | 2026-05-09 | |
| CRAN | 3.3.1 | 2020-05-29 | 2026-05-09 | 2026-05-09 | |
| CRAN | 3.3.0 | 2020-03-05 | 2026-05-09 | 2026-05-09 | |
| CRAN | 3.2.1 | 2019-08-11 | 2026-05-09 | 2026-05-09 | |
| CRAN | 3.2.0 | 2019-06-16 | 2026-05-09 | 2026-05-09 | |
| CRAN | 3.1.1 | 2019-04-07 | 2026-05-09 | 2026-05-09 | |
| CRAN | 3.1.0 | 2018-10-25 | 2026-05-09 | 2026-05-09 | |
| CRAN | 3.0.0 | 2018-07-03 | 2026-05-09 | 2026-05-09 | |
| CRAN | 2.2.1 | 2016-12-30 | 2026-05-09 | 2026-05-09 | |
| CRAN | 2.2.0 | 2016-11-11 | 2026-05-09 | 2026-05-09 | |
| CRAN | 2.1.0 | 2016-03-01 | 2026-05-09 | 2026-05-09 | |
| CRAN | 2.0.0 | 2015-12-18 | 2026-05-09 | 2026-05-09 | |
| CRAN | 1.0.1 | 2015-03-17 | 2026-05-09 | 2026-05-09 | |
| CRAN | 1.0.0 | 2014-05-21 | 2026-05-09 | 2026-05-09 | |
| CRAN | 0.9.3.1 | 2013-03-02 | 2026-05-09 | 2026-05-09 | |
| CRAN | 0.9.3 | 2012-12-05 | 2026-05-09 | 2026-05-09 | |
| CRAN | 0.9.2.1 | 2012-09-11 | 2026-05-09 | 2026-05-09 | |
| CRAN | 0.9.2 | 2012-09-04 | 2026-05-09 | 2026-05-09 | |
| CRAN | 0.9.1 | 2012-05-08 | 2026-05-09 | 2026-05-09 | |
| CRAN | 0.9.0 | 2012-03-01 | 2026-05-09 | 2026-05-09 | |
| CRAN | 0.8.9 | 2010-12-23 | 2026-05-09 | 2026-05-09 | |
| CRAN | 0.8.8 | 2010-07-05 | 2026-05-09 | 2026-05-09 | |
| CRAN | 0.8.7 | 2010-03-02 | 2026-05-09 | 2026-05-09 | |
| CRAN | 0.8.6 | 2010-02-18 | 2026-05-09 | 2026-05-09 | |
| CRAN | 0.8.5 | 2009-12-16 | 2026-05-09 | 2026-05-09 | |
| CRAN | 0.8.4 | 2009-12-09 | 2026-05-09 | 2026-05-09 | |
| CRAN | 0.8.3 | 2009-04-20 | 2026-05-09 | 2026-05-09 | |
| CRAN | 0.8.2 | 2009-02-25 | 2026-05-09 | 2026-05-09 | |
| CRAN | 0.8.1 | 2008-12-14 | 2026-05-09 | 2026-05-09 | |
| CRAN | 0.8 | 2008-11-21 | 2026-05-09 | 2026-05-09 | |
| CRAN | 0.7 | 2008-10-05 | 2026-05-09 | 2026-05-09 | |
| CRAN | 0.6 | 2008-04-03 | 2026-05-09 | 2026-05-09 | |
| CRAN | 0.5.7 | 2008-01-11 | 2026-05-09 | 2026-05-09 | |
| CRAN | 0.5.6 | 2007-10-20 | 2026-05-09 | 2026-05-09 | |
| CRAN | 0.5.5 | 2007-09-01 | 2026-05-09 | 2026-05-09 | |
| CRAN | 0.5.4 | 2007-07-08 | 2026-05-09 | 2026-05-09 | |
| CRAN | 0.5.2 | 2007-06-18 | 2026-05-09 | 2026-05-09 | |
| CRAN | 0.5.1 | 2007-06-10 | 2026-05-09 | 2026-05-09 | |
| CRAN | 0.5 | 2007-06-01 | 2026-05-09 | 2026-05-09 | |
| CRAN | 4.0.3 | 2026-05-29 | 2026-05-30 | ||
| R-universe | 4.0.3.9000 | 2026-05-29 | 2026-05-30 |
표시할 OSV 데이터가 없습니다.
표시할 OpenAlex 데이터가 없습니다.