[med-svn] [r-cran-ggplot2] 01/06: Imported Upstream version 2.1.0
Andreas Tille
tille at debian.org
Wed Apr 27 19:46:04 UTC 2016
This is an automated email from the git hooks/post-receive script.
tille pushed a commit to branch master
in repository r-cran-ggplot2.
commit 05bdd4ddd16f466a0afc7ee668545840476d1fc6
Author: Andreas Tille <tille at debian.org>
Date: Wed Apr 27 21:35:39 2016 +0200
Imported Upstream version 2.1.0
---
DESCRIPTION | 49 +--
MD5 | 344 ++++++++++---------
NAMESPACE | 11 +
NEWS.md | 635 +++++++++++++++++++++++++++++++++++
R/aes.r | 2 +-
R/annotation-custom.r | 17 +-
R/annotation.r | 3 +-
R/bin.R | 171 ++++++++++
R/data.R | 6 +-
R/facet-grid-.r | 140 +++-----
R/facet-wrap.r | 29 +-
R/fortify.r | 9 +-
R/geom-.r | 5 +-
R/geom-abline.r | 9 +-
R/geom-bar.r | 12 +-
R/geom-bin2d.r | 10 +-
R/geom-blank.r | 24 +-
R/geom-boxplot.r | 32 +-
R/geom-contour.r | 15 +-
R/geom-count.r | 10 +-
R/geom-crossbar.r | 10 +-
R/geom-curve.r | 15 +-
R/geom-density.r | 10 +-
R/geom-density2d.r | 15 +-
R/geom-dotplot.r | 24 +-
R/geom-errorbar.r | 9 +-
R/geom-errorbarh.r | 10 +-
R/geom-freqpoly.r | 20 +-
R/geom-hex.r | 10 +-
R/geom-histogram.r | 16 +-
R/geom-hline.r | 3 +-
R/geom-jitter.r | 11 +-
R/geom-label.R | 16 +-
R/geom-linerange.r | 10 +-
R/geom-map.r | 10 +-
R/geom-path.r | 18 +-
R/geom-point.r | 42 +--
R/geom-pointrange.r | 10 +-
R/geom-polygon.r | 12 +-
R/geom-quantile.r | 14 +-
R/geom-raster.r | 13 +-
R/geom-rect.r | 11 +-
R/geom-ribbon.r | 16 +-
R/geom-rug.r | 11 +-
R/geom-segment.r | 13 +-
R/geom-smooth.r | 21 +-
R/geom-spoke.r | 10 +-
R/geom-text.r | 16 +-
R/geom-tile.r | 14 +-
R/geom-violin.r | 15 +-
R/geom-vline.r | 3 +-
R/ggproto.r | 7 +-
R/guide-legend.r | 45 ++-
R/hexbin.R | 38 +++
R/labels.r | 10 +-
R/layer.r | 70 +++-
R/margins.R | 4 +-
R/panel.r | 4 +-
R/plot-build.r | 4 +-
R/plot-construction.r | 2 +-
R/plot.r | 2 +-
R/position-jitterdodge.R | 15 +-
R/position-nudge.R | 4 +-
R/save.r | 2 +-
R/scale-.r | 5 +-
R/scale-discrete-.r | 36 +-
R/scale-shape.r | 2 +
R/scale-size.r | 16 +
R/scale-type.R | 66 ++++
R/scales-.r | 57 +---
R/stat-bin.r | 169 +++++-----
R/stat-bin2d.r | 19 +-
R/stat-bindot.r | 19 +-
R/stat-binhex.r | 59 +---
R/stat-boxplot.r | 10 +-
R/stat-contour.r | 9 +-
R/stat-count.r | 10 +-
R/stat-density-2d.r | 19 +-
R/stat-density.r | 24 +-
R/stat-ecdf.r | 41 ++-
R/stat-ellipse.R | 18 +-
R/stat-function.r | 37 +-
R/stat-identity.r | 28 +-
R/stat-qq.r | 17 +-
R/stat-quantile.r | 18 +-
R/stat-smooth-methods.r | 6 +-
R/stat-smooth.r | 19 +-
R/stat-sum.r | 12 +-
R/stat-summary-2d.r | 29 +-
R/stat-summary-bin.R | 18 +-
R/stat-summary-hex.r | 55 +--
R/stat-summary.r | 57 ++--
R/stat-unique.r | 14 +-
R/stat-ydensity.r | 27 +-
R/theme-defaults.r | 35 +-
R/theme.r | 59 ++--
R/translate-qplot-base.r | 145 --------
R/translate-qplot-lattice.r | 13 +-
R/utilities-grid.r | 8 +-
R/zxx.r | 29 ++
build/partial.rdb | Bin 175862 -> 186675 bytes
build/vignette.rds | Bin 245 -> 250 bytes
inst/CITATION | 4 +-
inst/doc/extending-ggplot2.Rmd | 12 +-
inst/doc/extending-ggplot2.html | 196 ++++++-----
inst/doc/ggplot2-specs.Rmd | 6 +-
inst/doc/ggplot2-specs.html | 97 +++---
inst/staticdocs/index.r | 3 +-
man/aes_.Rd | 2 +-
man/annotate.Rd | 6 +-
man/annotation_custom.Rd | 17 +-
man/discrete_scale.Rd | 5 +-
man/facet_grid.Rd | 146 +++-----
man/geom_abline.Rd | 38 ++-
man/geom_bar.Rd | 40 ++-
man/geom_bin2d.Rd | 44 +--
man/geom_blank.Rd | 53 ++-
man/geom_boxplot.Rd | 56 +--
man/geom_contour.Rd | 45 +--
man/geom_count.Rd | 44 +--
man/geom_density.Rd | 50 +--
man/geom_density_2d.Rd | 45 +--
man/geom_dotplot.Rd | 40 ++-
man/geom_errorbarh.Rd | 40 ++-
man/geom_hex.Rd | 44 +--
man/geom_histogram.Rd | 86 +++--
man/geom_jitter.Rd | 54 +--
man/geom_linerange.Rd | 48 +--
man/geom_map.Rd | 46 +--
man/geom_path.Rd | 46 +--
man/geom_point.Rd | 40 ++-
man/geom_polygon.Rd | 40 ++-
man/geom_quantile.Rd | 47 +--
man/geom_ribbon.Rd | 40 ++-
man/geom_rug.Rd | 40 ++-
man/geom_segment.Rd | 44 +--
man/geom_smooth.Rd | 59 ++--
man/geom_spoke.Rd | 40 ++-
man/geom_text.Rd | 41 ++-
man/geom_tile.Rd | 49 +--
man/geom_violin.Rd | 57 ++--
man/gg-add.Rd | 2 +-
man/ggtheme.Rd | 1 +
man/guide_legend.Rd | 29 +-
man/layer.Rd | 41 ++-
man/margin.Rd | 4 +-
man/presidential.Rd | 6 +-
man/scale_discrete.Rd | 6 +-
man/scale_gradient.Rd | 4 +
man/scale_shape.Rd | 4 -
man/scale_size.Rd | 2 +
man/stat_ecdf.Rd | 42 ++-
man/stat_ellipse.Rd | 39 ++-
man/stat_function.Rd | 43 ++-
man/stat_identity.Rd | 37 +-
man/stat_qq.Rd | 43 ++-
man/stat_summary.Rd | 92 +++--
man/stat_summary_2d.Rd | 51 ++-
man/stat_unique.Rd | 39 ++-
man/theme.Rd | 29 --
man/theme_update.Rd | 25 +-
man/translate_qplot_base.Rd | 150 ---------
man/translate_qplot_lattice.Rd | 13 +-
tests/testthat/Rplots.pdf | Bin 0 -> 3831 bytes
tests/testthat/test-aes-setting.r | 19 ++
tests/testthat/test-boxplot.r | 33 +-
tests/testthat/test-empty-data.r | 8 +
tests/testthat/test-facet-strips.r | 112 ++++++
tests/testthat/test-geom-boxplot.R | 9 +
tests/testthat/test-geom-freqpoly.R | 12 +
tests/testthat/test-geom-ribbon.R | 10 +
tests/testthat/test-geom-tile.R | 13 +
tests/testthat/test-grid-utils.R | 8 +
tests/testthat/test-layer.r | 13 +
tests/testthat/test-scale-discrete.R | 18 +
tests/testthat/test-stat-bin.R | 84 +++++
tests/testthat/test-stat-bin2d.R | 4 +-
tests/testthat/test-stats-function.r | 11 +
vignettes/extending-ggplot2.Rmd | 12 +-
vignettes/ggplot2-specs.Rmd | 6 +-
180 files changed, 3816 insertions(+), 2441 deletions(-)
diff --git a/DESCRIPTION b/DESCRIPTION
index 40b5cf6..c1584ef 100644
--- a/DESCRIPTION
+++ b/DESCRIPTION
@@ -1,5 +1,5 @@
Package: ggplot2
-Version: 2.0.0
+Version: 2.1.0
Authors at R: c(
person("Hadley", "Wickham", , "hadley at rstudio.com", c("aut", "cre")),
person("Winston", "Chang", , "winston at rstudio.com", "aut"),
@@ -13,11 +13,12 @@ Description: An implementation of the grammar of graphics in R. It combines the
multidimensional conditioning system and a consistent interface to map
data to aesthetic attributes. See http://ggplot2.org for more information,
documentation and examples.
-Depends: R (>= 2.14)
+Depends: R (>= 3.1)
Imports: digest, grid, gtable (>= 0.1.1), MASS, plyr (>= 1.7.1),
reshape2, scales (>= 0.3.0), stats
-Suggests: ggplot2movies, hexbin, Hmisc, mapproj, maps, maptools, mgcv,
- multcomp, nlme, testthat, quantreg, knitr
+Suggests: covr, ggplot2movies, hexbin, Hmisc, lattice, mapproj, maps,
+ maptools, mgcv, multcomp, nlme, testthat (>= 0.11.0), quantreg,
+ knitr, rpart, rmarkdown, svglite
Enhances: sp
License: GPL-2
URL: http://ggplot2.org, https://github.com/hadley/ggplot2
@@ -29,7 +30,7 @@ Collate: 'ggproto.r' 'aaa-.r' 'aes-calculated.r'
'aes.r' 'legend-draw.r' 'geom-.r' 'annotation-custom.r'
'annotation-logticks.r' 'geom-polygon.r' 'geom-map.r'
'annotation-map.r' 'geom-raster.r' 'annotation-raster.r'
- 'annotation.r' 'autoplot.r' 'bench.r' 'coord-.r'
+ 'annotation.r' 'autoplot.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-transform.r' 'data.R' 'facet-.r'
@@ -50,36 +51,36 @@ Collate: 'ggproto.r' 'aaa-.r' 'aes-calculated.r'
'geom-violin.r' 'geom-vline.r' 'ggplot2.r' 'grob-absolute.r'
'grob-dotstack.r' 'grob-null.r' 'grouping.r' 'guide-colorbar.r'
'guide-legend.r' 'guides-.r' 'guides-axis.r' 'guides-grid.r'
- 'labels.r' 'layer.r' 'limits.r' 'margins.R' 'panel.r'
- 'plot-build.r' 'plot-construction.r' 'plot-last.r' 'plot.r'
- 'position-.r' 'position-collide.r' 'position-dodge.r'
+ 'hexbin.R' 'labels.r' 'layer.r' 'limits.r' 'margins.R'
+ 'panel.r' 'plot-build.r' 'plot-construction.r' 'plot-last.r'
+ 'plot.r' 'position-.r' 'position-collide.r' 'position-dodge.r'
'position-fill.r' 'position-identity.r' 'position-jitter.r'
'position-jitterdodge.R' 'position-nudge.R' 'position-stack.r'
'quick-plot.r' 'range.r' 'save.r' 'scale-.r' 'scale-alpha.r'
'scale-brewer.r' 'scale-continuous.r' 'scale-date.r'
'scale-discrete-.r' 'scale-gradient.r' 'scale-grey.r'
'scale-hue.r' 'scale-identity.r' 'scale-linetype.r'
- 'scale-manual.r' 'scale-shape.r' 'scale-size.r' 'scales-.r'
- 'stat-bin.r' 'stat-bin2d.r' 'stat-bindot.r' 'stat-binhex.r'
- 'stat-boxplot.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-qq.r' 'stat-quantile.r' 'stat-smooth-methods.r'
- 'stat-smooth.r' 'stat-sum.r' 'stat-summary-2d.r'
- 'stat-summary-bin.R' 'stat-summary-hex.r' 'stat-summary.r'
- 'stat-unique.r' 'stat-ydensity.r' 'summary.r'
+ 'scale-manual.r' 'scale-shape.r' 'scale-size.r' 'scale-type.R'
+ 'scales-.r' 'stat-bin.r' 'stat-bin2d.r' 'stat-bindot.r'
+ 'stat-binhex.r' 'stat-boxplot.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-qq.r' 'stat-quantile.r'
+ 'stat-smooth-methods.r' 'stat-smooth.r' 'stat-sum.r'
+ 'stat-summary-2d.r' 'stat-summary-bin.R' 'stat-summary-hex.r'
+ 'stat-summary.r' 'stat-unique.r' 'stat-ydensity.r' 'summary.r'
'theme-defaults.r' 'theme-elements.r' 'theme.r'
- 'translate-qplot-base.r' 'translate-qplot-ggplot.r'
- 'translate-qplot-lattice.r' 'utilities-break.r'
- 'utilities-grid.r' 'utilities-help.r' 'utilities-matrix.r'
- 'utilities-resolution.r' 'utilities-table.r' 'zxx.r' 'zzz.r'
+ 'translate-qplot-ggplot.r' 'translate-qplot-lattice.r'
+ 'utilities-break.r' 'utilities-grid.r' 'utilities-help.r'
+ 'utilities-matrix.r' 'utilities-resolution.r'
+ 'utilities-table.r' 'zxx.r' 'zzz.r'
VignetteBuilder: knitr
-RoxygenNote: 5.0.0
+RoxygenNote: 5.0.1
NeedsCompilation: no
-Packaged: 2015-12-15 13:04:37 UTC; hadley
+Packaged: 2016-02-29 20:47:22 UTC; hadley
Author: Hadley Wickham [aut, cre],
Winston Chang [aut],
RStudio [cph]
Maintainer: Hadley Wickham <hadley at rstudio.com>
Repository: CRAN
-Date/Publication: 2015-12-18 10:45:15
+Date/Publication: 2016-03-01 15:47:24
diff --git a/MD5 b/MD5
index 162ed7d..68242b5 100644
--- a/MD5
+++ b/MD5
@@ -1,19 +1,21 @@
-128c13758924244b835c69aed44c94a7 *DESCRIPTION
-c6f6758c306983417f8c23f0d038525a *NAMESPACE
+c6072e44c868630c920dc1ce36693a4a *DESCRIPTION
+f513b3f13d3b51210d938a711ee41b14 *NAMESPACE
+b6159543e84fe4d451aef0cbee94b7df *NEWS.md
7171046778fbb6a06b96a48bb9c6cb75 *R/aaa-.r
41c9ba0c55c5b2dac5c2ba80a9e6f0f0 *R/aes-calculated.r
a744d7b67886c9a66068cffb5e71699a *R/aes-colour-fill-alpha.r
d901c095dc98fd19f788ed7814152f8d *R/aes-group-order.r
53f129179804c8dbeb9a5fba52d5b056 *R/aes-linetype-size-shape.r
9b2ae79db47a3528738807199529ff3c *R/aes-position.r
-fa764c0f3d99ed90d728bbf57c41e186 *R/aes.r
-7197b034fc85230edffc479af5cd1f5d *R/annotation-custom.r
+8a425278ff1b9e474098872a0c5e9493 *R/aes.r
+bb54062d751148cfc3c9fe4a2827a537 *R/annotation-custom.r
1c56152690873e5cb80a9ede93222a45 *R/annotation-logticks.r
23a65ca6c3e4ce2ffa1d11b94171e524 *R/annotation-map.r
39f637bb6e438cfbe001e2f86eedc1f2 *R/annotation-raster.r
-61cd6012d06c8f01a7574f7bf48bfc31 *R/annotation.r
+f74649f9a228d8953f2b7bdf2f47ecb6 *R/annotation.r
eb4a7f643fd1a9c47fb64ed576a10e87 *R/autoplot.r
57939239ee7146de73a2aba6de11f5a0 *R/bench.r
+c008fbcae7264267eb84acb684e18ec7 *R/bin.R
8081549496f51360a79570c233a1929f *R/coord-.r
7f06acc0754ed9be0e8499cf393c1d25 *R/coord-cartesian-.r
09cadc86b4cc436f073d468b5024b7bc *R/coord-fixed.r
@@ -23,152 +25,153 @@ c7a07694ef7c686f232fe3c0ba4e673a *R/coord-flip.r
5a85a120c7c97d7528035e105a76a24b *R/coord-polar.r
e042de925de133ab9978221438997b4e *R/coord-quickmap.R
5b7efc37f850dba08b4dffb964122000 *R/coord-transform.r
-d38997c46c827930f845c5f239aff407 *R/data.R
+75a46d8776159cc4d2290536a459d524 *R/data.R
1cc34cbdb97662693545d1f09f53c080 *R/facet-.r
-3f8b216d933c934fea5407033678b5e6 *R/facet-grid-.r
+f6db1c26ddf5b3c7452b5252b7f04fb3 *R/facet-grid-.r
455f53f8eeafdb025e1923f8fafc1105 *R/facet-labels.r
bf8ddb7258fdc55f31454b5f6b82ab1e *R/facet-layout.r
10fead8ab5f75e313766eef213ca175d *R/facet-locate.r
9fabb1104100303c97d6132cf7aceb64 *R/facet-null.r
97efe28b15c4317698b0ec49e5c2b279 *R/facet-viewports.r
-d2e160b5c7f9037554062df1ce3a274b *R/facet-wrap.r
+2e72831c1bb7a5c459f5acc2d0d66fae *R/facet-wrap.r
185ec0bbe6e5fb2900d3bcb8b3a98947 *R/fortify-lm.r
5ab10594c4dae94d6118c0a2655d5736 *R/fortify-map.r
1e6a486f18bfe39121a436f47922f67c *R/fortify-multcomp.r
c48d8fa6657357fbaaca6335107e0fc9 *R/fortify-spatial.r
-4f2c97115990bc2a207aa4cb1d54ae45 *R/fortify.r
-045b781a9d085ecbd8f6fbd6fc14ce8c *R/geom-.r
-af5f4983deed90c750742a47190d4bc4 *R/geom-abline.r
-87f066dc91ba0cce9b707a412380bd4c *R/geom-bar.r
-5acd1dfba0920f7bc074c3b97a9a49c3 *R/geom-bin2d.r
-32e1513b9e272076f40db4989a0124c1 *R/geom-blank.r
-807f7c8a54d5cb65ba518ad6abd2a579 *R/geom-boxplot.r
-e647994ca5e70887fca98af44e0082e1 *R/geom-contour.r
-5e0493d8775001ac459c2d6efb6b0821 *R/geom-count.r
-842f2e7f5d39d180dd3d9a7a51914ed3 *R/geom-crossbar.r
-60b7162c3ab48cee151496229a820b32 *R/geom-curve.r
+b6b4ce36f91452eddf970ab0f84360e3 *R/fortify.r
+fa9c44fc3c22fbfd1a9f352cfec46845 *R/geom-.r
+a77a946e74889047cc19b28693cbf4f5 *R/geom-abline.r
+a96676255590b096e27992e915a8447f *R/geom-bar.r
+c88130f984e10e44374e3c35eda15fa0 *R/geom-bin2d.r
+101aa2d1ab6e1b7508b8f62021fad144 *R/geom-blank.r
+6c26af5529d24130f4310186e8f99c31 *R/geom-boxplot.r
+2cce6a316c345907fbcbf31e24d3a2bd *R/geom-contour.r
+891b1fe7dce6e7e8b9bb87e38f40f541 *R/geom-count.r
+3505ee228499af84d0e284e0208ad4e5 *R/geom-crossbar.r
+41365dd70a4fcc77afe2f53aa2d900df *R/geom-curve.r
55172848e9beb54df54b8d6d2d2f91ae *R/geom-defaults.r
-f1298f9045e22ac4799c23205c62440a *R/geom-density.r
-a349028790f849972489c2d65f3f9ce8 *R/geom-density2d.r
-dfa78318176fbc810488bda4231b0856 *R/geom-dotplot.r
-f06b64fc0383b9b48ff468d0325a5438 *R/geom-errorbar.r
-2593f86192e79334bc9e29ebb3ae1674 *R/geom-errorbarh.r
-36d7c7bee86501f609fc799081852f0a *R/geom-freqpoly.r
-1deee106b67853189207fb765d388376 *R/geom-hex.r
-cdfe6e9751445c5e20f51aad0f909796 *R/geom-histogram.r
-fd337aca62b5bc57c6cdb9463a22d22b *R/geom-hline.r
-b7855c6dd4d98aecd805621a9e65f49c *R/geom-jitter.r
-29b89a9cdb090bd89a4bcd1d042f3d2e *R/geom-label.R
-74e854863fe5d088782bf0fb828a3d92 *R/geom-linerange.r
-d70b6e894ae2eb0161de5b5cb3986c65 *R/geom-map.r
-f2fcfe75931bb242a205d2a1f4630e24 *R/geom-path.r
-8cc237ce23b928aa87b1e58c74f5d607 *R/geom-point.r
-62eeb8af6b42aec1b772d3fcf63f2fd0 *R/geom-pointrange.r
-09143a1f81d3422e5ead8a6ef39db9eb *R/geom-polygon.r
-d3eb045bf5cf536cee2d68428b365451 *R/geom-quantile.r
-7ea959a7d466659333a8c1398edf624b *R/geom-raster.r
-3117863095c2652d0c61609c47e304e8 *R/geom-rect.r
-c1d8b2f823b4c5c6c2bdad80768e61e2 *R/geom-ribbon.r
-19bc5cc0f8b3c8bf49a65039bf9d6fb2 *R/geom-rug.r
-f6d8792e03c246a5398c5e623237c221 *R/geom-segment.r
-616550b16de176986b8d76d56ff7bb83 *R/geom-smooth.r
-2b93a744cc60d182de6554aebc2f2a94 *R/geom-spoke.r
-ee049b1fa8922d3492401cc7554c71ba *R/geom-text.r
-945dadbab75c776e940086f27ac49ec6 *R/geom-tile.r
-c078dd69473252fcf572d48eda009b2e *R/geom-violin.r
-6aaa2cb92cda27382ff4b613a8f646cc *R/geom-vline.r
+33391cdb47cecb97415532e78cda470e *R/geom-density.r
+b3befdd4d6f980a4f531b2e7f28864d0 *R/geom-density2d.r
+ce66841aba9df11233df963837056900 *R/geom-dotplot.r
+3bbf79cbeaccc53bc972d3319a516156 *R/geom-errorbar.r
+8fd6a340781ae915960ac7ddc7fc327e *R/geom-errorbarh.r
+8129ffb0edb8c565179efe069dfb1f26 *R/geom-freqpoly.r
+f00e72a4a83b7ea9196379d7dadc37a7 *R/geom-hex.r
+2f32e6222a2f78fc94cad3cb759f6eac *R/geom-histogram.r
+ecfc67b8ccd284fac23b27874bd0e936 *R/geom-hline.r
+539e1374e446d7adc6964aaca1e8a36b *R/geom-jitter.r
+1e701b7fca39e919d4d97e5b084c53c1 *R/geom-label.R
+29bcde9102012f50218481e7d97dc781 *R/geom-linerange.r
+bba9be6242a5126a96740fdb97f0641f *R/geom-map.r
+ae5dce0abc8a0243754835a42caa684c *R/geom-path.r
+3c3c64fae74f4a918045eacd0349b445 *R/geom-point.r
+4f8fca315a6bae9c1856e7f36f3b4c13 *R/geom-pointrange.r
+c70f5781c5a783a3f688370de92eb31b *R/geom-polygon.r
+256da5b4c9516af4885be6a1a2532a3b *R/geom-quantile.r
+4318136c00615ababd58b3ad9dd8e3a3 *R/geom-raster.r
+f5acd7b513a158d5a7115a82a69330ed *R/geom-rect.r
+96547a86a31fa51e6ef700fc2037c513 *R/geom-ribbon.r
+4f193539fd6749b699ce7dbbae6ac6a9 *R/geom-rug.r
+e2253a84b9cdcf7f4adff3089587f253 *R/geom-segment.r
+aedf4458c989202a6a4e8fde9d35ece0 *R/geom-smooth.r
+b4bc0d601f337458a08b2dc255bfcd60 *R/geom-spoke.r
+840a2068c875c932a1e20adbc4b75e6e *R/geom-text.r
+838fdf45748355c8a074512d6f936120 *R/geom-tile.r
+6c76d3fbd3008fe71db78ba0e4f872f4 *R/geom-violin.r
+a0ce9da0fa8dac5d5b3311513e15406c *R/geom-vline.r
7fbb4a1b3a36deea08d5990dc9b82bb6 *R/ggplot2.r
-070781ab73a3e2cf5ea10abe2dd044fd *R/ggproto.r
+f147370b7f531891339d35260af1f633 *R/ggproto.r
abe3e869859c7f73fa4a9721df2ef29e *R/grob-absolute.r
57c5dee7337f17082fde9a43d071cc2c *R/grob-dotstack.r
95d44bd0d180dca5892db5674bec6362 *R/grob-null.r
a432566834bd4321476e8c8e1a5993f6 *R/grouping.r
a81c889fb0d614d49262f7f627c6d314 *R/guide-colorbar.r
-791c3a32f35493bf109ecd6264d39acb *R/guide-legend.r
+1fad1b1dbe111530a190525ffaffe5ca *R/guide-legend.r
4ffffa04a45a0fdc98d0b4a86b3964fd *R/guides-.r
a6a7662bace821f91da3ababf1f42c11 *R/guides-axis.r
91319825178764869b02d5ed527637e8 *R/guides-grid.r
-09651c30b88b748c5b7da7a41efbcd49 *R/labels.r
-ba4a38bde128d1edf27891aba63596a9 *R/layer.r
+4516ab6dab4a8799e669a5c64b917a92 *R/hexbin.R
+d3c091b2ddf6c29197d5dd13f9f83d21 *R/labels.r
+e9012d6b78f7a735a48cd04389025580 *R/layer.r
cb041a872c511f7508ccf9e0b7a2b68e *R/legend-draw.r
22ac4e1d41ee5809fd19a21347000af6 *R/limits.r
-7a443f2662cd5ad7545d6fed891e2dd6 *R/margins.R
-3e7952b15074bc30956d1e77c286d724 *R/panel.r
-0b477c5a9747234a69c00ba335675e05 *R/plot-build.r
-929aa868d774ed75060e6d45fc5c1ea3 *R/plot-construction.r
+a12685c9806c50b576b3fa6edea4c95d *R/margins.R
+103f267c62ad9ce85913913147077918 *R/panel.r
+33234cd1d8699b1a1020e6162e64a761 *R/plot-build.r
+21d0eb8d4b914162038f04585ad70b09 *R/plot-construction.r
e7d2e29ecfc09bffcf8518894eec414b *R/plot-last.r
-c8d0ebe260e3701226750c0e8d8707a6 *R/plot.r
+3ddfd4215c08fbf122599b2c34a888b2 *R/plot.r
636580e38110490dd2f38b09bba0152c *R/position-.r
9bb9cfaa59dd9d64dfcf2388f4ba0cdf *R/position-collide.r
29baf4dc9462147822635b22109fb527 *R/position-dodge.r
d30ffc9364ffa8b08256f601b7d67fcd *R/position-fill.r
8d8c6f5432e9f61de2fe222922b93142 *R/position-identity.r
fe1e1022e11f937a360352a26255e8ac *R/position-jitter.r
-47c7143f55eb5b16ceaaa97b12c583f5 *R/position-jitterdodge.R
-21b4b44525017a08e41efa0888724c01 *R/position-nudge.R
+e4e46d5e81375b783697b672ce55ae2c *R/position-jitterdodge.R
+95c9046e151200799b13f4eb53b9a8e0 *R/position-nudge.R
3bf43bb214de063904c603ce4f4909d2 *R/position-stack.r
d88b979e879b28ea83929c9d410fb1bf *R/quick-plot.r
42d7a80d2fdd0e3b2a53b58a0cbf9be9 *R/range.r
-cd3cc7621245ed40b84344a36f554435 *R/save.r
-f73c05f4e123121f6d83ee20bca85176 *R/scale-.r
+c4fa493797bfd91074ac48614b09ec63 *R/save.r
+514ce47a8a2a62077636b7682b2a8d2b *R/scale-.r
1b99c2f65e2b210e26f686a379629341 *R/scale-alpha.r
a9d9dad9fd80dd209ebe50d8ea1d5558 *R/scale-brewer.r
04a1eb6b2c8144a6528882dc64f95934 *R/scale-continuous.r
61e114a0c99a03328d6dabcacc0ec9ad *R/scale-date.r
-a1aa9f1df3072a478c84df63f5aa3478 *R/scale-discrete-.r
+0ca691dbd7734540ca50eabfdc4781d4 *R/scale-discrete-.r
d577e4befed18b3306ff53f9c2a917e7 *R/scale-gradient.r
bf1d0a9a8698b092799af1c0f966034a *R/scale-grey.r
d0248ff685ce6bda7eba6fb9272e13dd *R/scale-hue.r
e96f1acf5f333a0e2d3fb94ba0ac1682 *R/scale-identity.r
7501deaed0c692d084705890995952df *R/scale-linetype.r
6bf98c26a2f17a42134941151ef25af9 *R/scale-manual.r
-8b1c96c7b6214e45adbb96b805d2789b *R/scale-shape.r
-a10109b9f412ee7beb43bb7f607e00cb *R/scale-size.r
-ad8afa0ba9fb2fcfe7ec5f4852611d21 *R/scales-.r
+bf779de05e42c3302d62bab0c58658ef *R/scale-shape.r
+200ff19fd355ca908deade85210e4276 *R/scale-size.r
+ff4dea73d4aaa6641d22380863a6c947 *R/scale-type.R
+9033369440f516d0cd7c1c2a80b8c2bf *R/scales-.r
002772e3a128c3074f4d3100c9f63d9d *R/stat-.r
-97d6ba417371a436a14709de57c24d99 *R/stat-bin.r
-aff0b85ad8b4b5d75005e3d67dbe97f3 *R/stat-bin2d.r
-ee8c8631bed750cf47fe15b282174d4b *R/stat-bindot.r
-dac71107f1eda06b162b49e0f74294b4 *R/stat-binhex.r
-5b8996c2cb08ff36d428fcdeeabee8ea *R/stat-boxplot.r
-e2c5d5c372c6604ce7ed781e1b56dc69 *R/stat-contour.r
-5d0a381bf3c61f5cad1adf30c75aaa72 *R/stat-count.r
-341a44248958c77541327a07b383dd4b *R/stat-density-2d.r
-29a474e17d850a9cd5021e2ad4cbd783 *R/stat-density.r
-cfcc728918f7cdcd01959d85da3b2fba *R/stat-ecdf.r
-5c659828ce50d18248b77519e86ad8ee *R/stat-ellipse.R
-b4d52166558a1233a8e81f6df67b4dd7 *R/stat-function.r
-e2d0ceaf1188627706972441d8b1ec60 *R/stat-identity.r
-0b302a713eaa4b767f8fc8efc4e0d2c8 *R/stat-qq.r
-8a7f4804dc21330353cb541ba994ed94 *R/stat-quantile.r
-72ebe9d0bb085a8be73b6eb41c7a2752 *R/stat-smooth-methods.r
-efc5b7b102d6682b620765f0aa21eb4b *R/stat-smooth.r
-52c51464a86d459f00cd3c077f9ee627 *R/stat-sum.r
-f0f02eab3acaa7c1f3d4ca9a3ce9178b *R/stat-summary-2d.r
-4ac747a8b5be7b8bc44b166363ee8567 *R/stat-summary-bin.R
-d8b6fe46eb82f9bd01ace95823e03ec0 *R/stat-summary-hex.r
-423506c429776259467a670e78d21e56 *R/stat-summary.r
-9f3e890e1164da8732d13283e43389bc *R/stat-unique.r
-5714d97e361067084f41c4620545d714 *R/stat-ydensity.r
+17e1006a3af82af8d0d8ef106022c933 *R/stat-bin.r
+1635bcde69b4e9d6d87129bdf637262a *R/stat-bin2d.r
+1df733e7ef7c92dc3830dc8575ee03b0 *R/stat-bindot.r
+50fb7e01c7f17addc242332d7a5d9974 *R/stat-binhex.r
+7cd8ec280a69afc9b965de0a1f8c1746 *R/stat-boxplot.r
+c50f8f9a9a7a94da06143bd39b19534d *R/stat-contour.r
+37fab9d9152ce0bb0262fffef3376f6d *R/stat-count.r
+00a2bc6012bf166b8847fac2db06acd6 *R/stat-density-2d.r
+530636e52afa89032e39aaa0523cf9b2 *R/stat-density.r
+5369f50577747f1c1e89415e5c462a87 *R/stat-ecdf.r
+bf0e515f6799c217df737d25445bfc13 *R/stat-ellipse.R
+e6e47cbcac2f096948480ba01e92f28f *R/stat-function.r
+eb36628791a1918308e2a458a3e77aea *R/stat-identity.r
+cb854afda9c9cdc4578b0bac2c949d5d *R/stat-qq.r
+b9542dc7c675d1992487d0c49334b557 *R/stat-quantile.r
+12924f87b366aa163300ee99f39c8dbf *R/stat-smooth-methods.r
+c10a2141b526b6ee7a74e1459526b6a2 *R/stat-smooth.r
+3fd5fcea86e72471b6b05e1f06d8fe1e *R/stat-sum.r
+f50adf8c33ca45f41d2cc69a7450efbe *R/stat-summary-2d.r
+f5b6045a5814dd15cc858d6ac792686c *R/stat-summary-bin.R
+a7e0fd3364dd4842108043b76c7bc096 *R/stat-summary-hex.r
+9dd83fee5edeeb8315179fc82ad93dc2 *R/stat-summary.r
+407275f26e16aee2fd8547f61d1b2fd9 *R/stat-unique.r
+eeecedcc273617abb811c886f161b4fb *R/stat-ydensity.r
c92420a879310b86c1bcbb1e6fb45425 *R/summary.r
-ab69c1ba381733ebf620dcf10b227445 *R/theme-defaults.r
+9b50db9df88063e9fd1d56e2fc69de86 *R/theme-defaults.r
7beceb23e6e35270cdf25d7df940fedd *R/theme-elements.r
-df5cd14fbf8b04c0ff12bda88c247317 *R/theme.r
-1239cf068ccaa1a1c58d38793e91caf3 *R/translate-qplot-base.r
+f6297c7f47ca260c98948aefa8e33254 *R/theme.r
b97bd5e0d2c69643142fb2b4529a0cad *R/translate-qplot-ggplot.r
-ad2f08f76dac34814872123de6a2654a *R/translate-qplot-lattice.r
+ba2fc9a3d891a2991792efc0bdd25649 *R/translate-qplot-lattice.r
31fad80a907f5ec247287296b5ffa4a4 *R/utilities-break.r
-462f0313976c787cd44700fe5346439b *R/utilities-grid.r
+c27187f963d056888cde8428c0ca9530 *R/utilities-grid.r
6f55c444360fe627ccd3669b74f122da *R/utilities-help.r
3bef847b27dc1a7182eff846527f6fc6 *R/utilities-matrix.r
a2f6c224351ced0c10b6f55dcd941fd3 *R/utilities-resolution.r
e72a2689dc0d2076b7492a6ebd165b62 *R/utilities-table.r
ae40757394892074687c9d11a7744f20 *R/utilities.r
-b2fdc194c563ec6312f20e74382951c6 *R/zxx.r
+eeec75de61894ddc1238ba5c894879b2 *R/zxx.r
9ba24b6237d2e367c3f4c30d8cd968d1 *R/zzz.r
0eb9195324e6152acd04d0e853a8b455 *README.md
-45b569636a7954e0fe2bf7f8c9fcad99 *build/partial.rdb
-854144184597775f66eeacd20d7b0552 *build/vignette.rds
+9918255ea02dd0585fec4061d6f70950 *build/partial.rdb
+0d9454fbd1cab8dc1e4d63a8ddf1ac2c *build/vignette.rds
7fd28ad1feab3e3c773313672cd1b3be *data/diamonds.rda
1c883c4bb873c21cd428435264c456d7 *data/economics.rda
3cc1cdb7f53ac95b7346683e44e225d1 *data/economics_long.rda
@@ -180,30 +183,30 @@ c6d2b711873dc702d39de601f683ebdd *data/msleep.rda
e1ef68be302f256fe79e1e2833f5f50f *data/presidential.rda
d419c85de9cb971b7ebec959a836f72c *data/seals.rda
2012af9687f6f5813b8aa6aa86773c67 *data/txhousing.rda
-8c412b9bcc5ff77ba07b0488ea29a79d *inst/CITATION
+478b5d9f6c7d31a55ff4a26eab66578f *inst/CITATION
3cd9eb0fa04c028287aecdac2bf95cdd *inst/doc/extending-ggplot2.R
-3ea1eef97dfdacc7cd6703ae5e1bb2ed *inst/doc/extending-ggplot2.Rmd
-cc4415dc48f5a5b6ab6701d431b5aa6e *inst/doc/extending-ggplot2.html
+a0a183c6edece97cf73fbf564fbfa5b5 *inst/doc/extending-ggplot2.Rmd
+760149398ece2e28f72ece41bb53e32e *inst/doc/extending-ggplot2.html
fd4fffee04dfb833e03497c4701be1b4 *inst/doc/ggplot2-specs.R
-580964d5ac3b6030ddbfeb79f5123db3 *inst/doc/ggplot2-specs.Rmd
-50e57550b42bbc72e7d8be3f67dbe851 *inst/doc/ggplot2-specs.html
+7d2ce3bdee71e694250a1c764cfa5f8c *inst/doc/ggplot2-specs.Rmd
+0f97122414df042259e702415a821322 *inst/doc/ggplot2-specs.html
d41d8cd98f00b204e9800998ecf8427e *inst/staticdocs/README.md
7a09459ca2898424c3714a03f20665fd *inst/staticdocs/footer.html
923198a65466326dfb62fec20e793e3c *inst/staticdocs/head.html
8a0e4eb3cf19379924a78bc3f6fd3d7d *inst/staticdocs/icons.R
-4add1191e76ffb056578dbe4272159e7 *inst/staticdocs/index.r
+a45c45d397ec9594b1abad195094f45a *inst/staticdocs/index.r
56c75450069dc75bc81998ee2ec1e689 *man/absoluteGrob.Rd
ff67ba09d9d3541a10c519c3ed0d055c *man/add_theme.Rd
20f0528eb3688034fab93fc721b65409 *man/aes.Rd
-f77426680c2a929cb9ad19f8aa7613d4 *man/aes_.Rd
+efeed95b7b79a95a6186466d46869cec *man/aes_.Rd
7712e3e5b0ab03a32404a8f034aa10f0 *man/aes_all.Rd
ef8ce354cb3b609f4c33f53cd26821cc *man/aes_auto.Rd
03b05c2b533b5a88d81a6ac37cd5de77 *man/aes_colour_fill_alpha.Rd
48368f5dea136a4ec910b3c2e77cbf11 *man/aes_group_order.Rd
d7a853f2e395f95617f5b6da138cec65 *man/aes_linetype_size_shape.Rd
a99dcba86e888d8d6641653c7a5b972d *man/aes_position.Rd
-da7b4f468468cab96bb8573443141fb3 *man/annotate.Rd
-c6f56de489e678ee0c1e9ffa8603a618 *man/annotation_custom.Rd
+b012b63a37cd9c98384f13129d533360 *man/annotate.Rd
+5652e80103710fabd05920fcc372a8a2 *man/annotation_custom.Rd
e3f138140bdadb64a8aa2038218f4e25 *man/annotation_logticks.Rd
8c8c2ba1b4e343fb916b354a6560fcb5 *man/annotation_map.Rd
9a00f65c63148ff18f9fd46067bbdb4e *man/annotation_raster.Rd
@@ -223,7 +226,7 @@ ede8ed39297e89fe4dc8d9bb0eeb422a *man/coord_flip.Rd
1025087210f72dabf5ef6308790b2c6e *man/coord_trans.Rd
b3087f2c77e447cd21e6898615bfbf81 *man/cut_interval.Rd
b3ce84b7cf66c2930d2a6ee63873f72d *man/diamonds.Rd
-a2b6fbd168d4e755310000b7cc1fb60d *man/discrete_scale.Rd
+7f99b154408e3c3de0ba90c584dcbb90 *man/discrete_scale.Rd
6be3e22abc22f2b478bbf7bf6f79e10c *man/draw_key.Rd
4e7e5a544d058f424a52f3c2dba4cd91 *man/economics.Rd
c4df9291f631ea3cd24f69c97f02f1e2 *man/element_blank.Rd
@@ -233,7 +236,7 @@ c4df9291f631ea3cd24f69c97f02f1e2 *man/element_blank.Rd
f5778a7dbfad57f255816ee8c590abfb *man/element_text.Rd
5d9d25976953ec27acfc6428556eb3aa *man/expand_limits.Rd
df0176ef30dbfdde4cce9cea8381d99d *man/facet.Rd
-70e412fc004ef63b4dd13987fa69e2f5 *man/facet_grid.Rd
+b8d3b3cdac4a62f7fbd1882b767bc94e *man/facet_grid.Rd
b79ffe497fda049f9f7718a4efa86867 *man/facet_null.Rd
772a5f2d18d65842decf6d7fce27df91 *man/facet_wrap.Rd
49314a7e941068d810878ceee132c904 *man/faithfuld.Rd
@@ -243,35 +246,35 @@ b79ffe497fda049f9f7718a4efa86867 *man/facet_null.Rd
72f9d74ebc7f9b4354a702a02ac8acd4 *man/fortify.lm.Rd
720abd47d0d039c70334c93b327f3141 *man/fortify.map.Rd
7602d9d65104b9bc4e204bcb7894f445 *man/fortify.sp.Rd
-dcb5d4f5abb536b72f9350c8ff5c1a44 *man/geom_abline.Rd
-d5ffd3b3b476392c0de7e59fcc0d4cae *man/geom_bar.Rd
-86fd822c0dab391d0b021c8a04c39759 *man/geom_bin2d.Rd
-e07433ef36f68faf0a09d6cbc0093a35 *man/geom_blank.Rd
-0ad31ca2d92be8b02a38e825fa8e1d87 *man/geom_boxplot.Rd
-ebeac9abd59706401c4c0f8e07b3dc66 *man/geom_contour.Rd
-a431a225e971088a4ebcee99b346f904 *man/geom_count.Rd
-9debbf163e919ac9c0a4f4fad2162e7d *man/geom_density.Rd
-051c3ceff3b1f29d4605d6eae4960034 *man/geom_density_2d.Rd
-ff5676a104f025f5e14b0c14ad3ffe45 *man/geom_dotplot.Rd
-f617666ccea672d3ac7f7383b5030ae6 *man/geom_errorbarh.Rd
-c564a6814ccd3fe39d2d909ef5e79035 *man/geom_hex.Rd
-0ee3581c134ee72ee0b1645c47938685 *man/geom_histogram.Rd
-43e59c75d324f75f2d3602d1a8c0b088 *man/geom_jitter.Rd
-4206d8f6928e9c26277795dfd0a8b59b *man/geom_linerange.Rd
-900fc042ac2ccd6e686603b9b3de0b2f *man/geom_map.Rd
-e68a78e087c71b276e3645c2ded6cead *man/geom_path.Rd
-b2a28c9173a63654d78522dc0862ede8 *man/geom_point.Rd
-9b54eb991ed2bf0ce3cf8167a4cf466b *man/geom_polygon.Rd
-f57ff34cf79711d370e6a48e6ce30801 *man/geom_quantile.Rd
-4d3be4002eeaa64bc9103713e17bda4b *man/geom_ribbon.Rd
-a3e976f4161a198988ad8fb95365c3e8 *man/geom_rug.Rd
-17121dc9468c91ae1b2566446cb8a591 *man/geom_segment.Rd
-6ff1ac4aefc1cd657955b72d2c535005 *man/geom_smooth.Rd
-b6cdad5c6952b9dff9c2bd67ba30d295 *man/geom_spoke.Rd
-36a08621b671333882290a948773c57c *man/geom_text.Rd
-6fc616f1a1e28f726f7a895cbeb73031 *man/geom_tile.Rd
-a6bbbf06590523bff5f0389b15496cc2 *man/geom_violin.Rd
-dab0412cf340913187b9383bd173b4aa *man/gg-add.Rd
+750ced57460204f1252f23f49b8387aa *man/geom_abline.Rd
+d01f490cacf87215fac4fb4c7724ee04 *man/geom_bar.Rd
+648d1c3cc181137034baa755dd3754d2 *man/geom_bin2d.Rd
+76fe6f24e9bec643e2a924803060fb8d *man/geom_blank.Rd
+e349223241134c76ab500f617bf0f0e5 *man/geom_boxplot.Rd
+d870e7d46d5131fd6e4335b6c872753e *man/geom_contour.Rd
+639a2a0990bf02bc0c183a302577136d *man/geom_count.Rd
+741c9f98418db946e303b90d5887743b *man/geom_density.Rd
+3ba68b899f9b46f08bb6aefe28f2d450 *man/geom_density_2d.Rd
+fc2e473b6c0e5d3448902902241863f3 *man/geom_dotplot.Rd
+2736238f9142b5e96fef4d88fd093258 *man/geom_errorbarh.Rd
+e3555ec1eab4e060e0d0bc8d5852c480 *man/geom_hex.Rd
+f93cd5e514d918af0a984f4918f14633 *man/geom_histogram.Rd
+cc3f124a7051f2069416dd768d7bb803 *man/geom_jitter.Rd
+29484d3543d6681f84b66683a088328c *man/geom_linerange.Rd
+992fd4b38d2a988b24dfec8fb9704052 *man/geom_map.Rd
+ab8fb39b0eb8d4aad16bc763e36502c3 *man/geom_path.Rd
+7bc71b4ce3b94cffbdc03b9da6543aa3 *man/geom_point.Rd
+0f77fb216b5f5a40fe0ac7ec4aa29b25 *man/geom_polygon.Rd
+10945610bcc44a55521d2b2590084cc5 *man/geom_quantile.Rd
+9de21040d79f19d12fed435c6d4ba94c *man/geom_ribbon.Rd
+26ed0bb5db5051598ce661b2a4dcf939 *man/geom_rug.Rd
+de5656f17d3bac3bf5cfef7e84d09281 *man/geom_segment.Rd
+295a6d67caf1c97c1ac1c62dd50049d8 *man/geom_smooth.Rd
+7c27a32863bf85f83d11f8bfd339668e *man/geom_spoke.Rd
+2dc58e50a0313a8d9809ac0acd38f468 *man/geom_text.Rd
+dbce3474b37580aeb473afd430e684e5 *man/geom_tile.Rd
+7025ef5ca55fcca57d003c494cf13b49 *man/geom_violin.Rd
+d22c6fff5fffed1dc41e1130a2ca56a5 *man/gg-add.Rd
f1075176114c6b91fdbf223719cd981a *man/gg_dep.Rd
c63db10ccb04b87aedfdda2119ef9b5c *man/ggplot.Rd
238ef3805c533dc74575a0853d06c636 *man/ggplot2-ggproto.Rd
@@ -280,10 +283,10 @@ a4bef608dde830e27ac03f259c102cef *man/ggplotGrob.Rd
7aedf2453e47d8d2bebd38923501c60b *man/ggplot_gtable.Rd
db86dd2f3896ef6a5950d64b0a4d2766 *man/ggproto.Rd
7fadc3359fc39669f9e3b3bd59dea9a0 *man/ggsave.Rd
-f30de9d8e16cc683c280267dc54db4e0 *man/ggtheme.Rd
+33dc8fe57712ee1ca53e7373cff3690c *man/ggtheme.Rd
7a6498b8983bc96328ce0846ce0e877c *man/graphical-units.Rd
6759e461416f3ce513ad249dd15fa106 *man/guide_colourbar.Rd
-2bd2c77d6ef8806705a2b378cf4bad0a *man/guide_legend.Rd
+92cb04f0845d6d89bad331c61b44de84 *man/guide_legend.Rd
81243640ba87fee316373900d47bd170 *man/guides.Rd
7e0bd3d61fe1df07da190c3ced288fdf *man/hmisc.Rd
630598fb99d0a7a34bbb146074dfacc0 *man/is.Coord.Rd
@@ -297,12 +300,12 @@ b6171db99a23771ff09509040977439c *man/is.ggproto.Rd
86f29d63e2e2434a227e2de707b8f54e *man/labellers.Rd
b5821e641bcc949b92d3b27871ff5ff3 *man/labs.Rd
ec27029cac6b31ea9157ef0feb154b07 *man/last_plot.Rd
-d70cf02322cd705691c803fbcd1f9695 *man/layer.Rd
+e551b1f98d545489785941488546a0f1 *man/layer.Rd
115cedc87e2e5383505475fe2cf63054 *man/limits.Rd
377da418fcc446ccf31c060c52bc0d7a *man/lims.Rd
3ed091075707aa13724a9043b3ed2aa1 *man/luv_colours.Rd
21a16a89724a7fb35b1e4a83497bef74 *man/map_data.Rd
-653ed592603548727d9ba6210fb4f448 *man/margin.Rd
+449492299ada55b08955ca2efcb2c73a *man/margin.Rd
95ceb14a8b8d499aa1e3a13318fc2b98 *man/mean_se.Rd
230020b63a1ed18e271efbb407269e64 *man/midwest.Rd
ed26f5ff992715b558e465f84f9a5ee6 *man/mpg.Rd
@@ -313,7 +316,7 @@ a6e474584d501fccbc8f44c7b5cfc477 *man/position_jitter.Rd
17959133179918180ec83f11c4cbc621 *man/position_jitterdodge.Rd
605df25d4d57fa0117b5247aa1c15205 *man/position_nudge.Rd
bec4dbb370a26eb76d196c9208f95e94 *man/position_stack.Rd
-c41b9d71182dd3680692b2de56254408 *man/presidential.Rd
+7e72c18b1ffb5adfb4f691f8074bbd35 *man/presidential.Rd
3214de68f499011f976c396ae519e6de *man/print.ggplot.Rd
f130ffe874ab878cfba9e43a145df148 *man/print.ggproto.Rd
2618d742cecc1748f77cd870aade6839 *man/qplot.Rd
@@ -325,79 +328,86 @@ d7f87c2dfc2d156fb61cba090a620299 *man/remove_missing.Rd
89d50c11d76e3222056ca9bef1eee95c *man/scale_brewer.Rd
1d97e27509e6d0ac39fc87e598d337a9 *man/scale_continuous.Rd
445d9ce9a48c7656f7e0e196a76edc29 *man/scale_date.Rd
-1ce0563c5f4297d788925a7298e1a83d *man/scale_discrete.Rd
-82457894e9d32c0b19792dde26efdec4 *man/scale_gradient.Rd
+c210a92df4262fb598bd058f0fee5c52 *man/scale_discrete.Rd
+7b31f2ec29b6f02264d9be81a841d7a0 *man/scale_gradient.Rd
cf572e09e6ec62dc446f6ee845713751 *man/scale_grey.Rd
2315b109bc3814b19fe1eca32d71fc45 *man/scale_hue.Rd
f6a2295e5df163391b3759359def22cb *man/scale_identity.Rd
cdf000a350d3bc9df114f5d73889becb *man/scale_linetype.Rd
7b1d99d5983f282fd910e9b53378f0c6 *man/scale_manual.Rd
-e421384c765694757e3a2676f6d44fa0 *man/scale_shape.Rd
-6443a0c5dfb9614e648721ae343609a1 *man/scale_size.Rd
+baefd2a18b730ad3b123ae8973e3accc *man/scale_shape.Rd
+73d9bf4e9ca971c2e09809f9ff989342 *man/scale_size.Rd
b59ea5ba748f6cff46c84679997afc9b *man/seals.Rd
1056d55d33485453dd04e35394dddbac *man/should_stop.Rd
-ce238a515ba75aaa73ab63f3f7de53cd *man/stat_ecdf.Rd
-a2e10d53569214aa5a85a1ce54acddd2 *man/stat_ellipse.Rd
-bc1b38dfbfd9f629ec5d575a27e2d6a9 *man/stat_function.Rd
-c488178bbf7011597fadf82333a53262 *man/stat_identity.Rd
-c8327ec1ecf7807bc836c554c6259e99 *man/stat_qq.Rd
-29e597040e07a445416d688995bf48a2 *man/stat_summary.Rd
-a3362e1e10d662c578157a0a05d90326 *man/stat_summary_2d.Rd
-6e346ef82bfa85da9c0179c309ce7711 *man/stat_unique.Rd
+deffe971dc96a2ad0af9bc540dd24120 *man/stat_ecdf.Rd
+a44557727af8ce2613f543ed208754c5 *man/stat_ellipse.Rd
+b14f79b80724a6aa3bea34a00113482b *man/stat_function.Rd
+2eea6067b69ce41c0c6060ff8dec13e8 *man/stat_identity.Rd
+237ac5e2002e510db181269c677c3278 *man/stat_qq.Rd
+951594691eb93b454f362a284cea4603 *man/stat_summary.Rd
+20ae95e1741a7e4c828ef715e047ed04 *man/stat_summary_2d.Rd
+f221aeef4b1a78a6b408097385d36fe8 *man/stat_unique.Rd
ab1fa2e5b12d61345c6df1c55d057290 *man/summary.ggplot.Rd
-ddb990cb82eceb1692278ab09a7771ec *man/theme.Rd
-0b1a77dc069162e990936c72515fcbf8 *man/theme_update.Rd
+9850ada2b758839395edf07c936cdd0e *man/theme.Rd
+414ae32e79a1cd06063d9b524503346e *man/theme_update.Rd
ec58a310165674abab536ca72c129ac5 *man/transform_position.Rd
-ca96d351fe279c59980265de693fe286 *man/translate_qplot_base.Rd
8feeb91c8e5d9077dc5a37ed1808af46 *man/translate_qplot_ggplot.Rd
-8eba2685b5b409df90036b2251587bcd *man/translate_qplot_lattice.Rd
+8b3e7fb1c8204cabc0eae18979880e4b *man/translate_qplot_lattice.Rd
d8ce22b7718402206269b27a8f954b22 *man/txhousing.Rd
efdbab8bf593c178c64d6e1fc22205cb *man/update_defaults.Rd
df4c14b5a8d448e6bab888cab8831378 *man/update_labels.Rd
00df4f81231118534f870304920f88db *man/waiver.Rd
9ef186947b49d31af9fec818c266e4ce *man/zeroGrob.Rd
d61ade7569d3176888310444bed0e4ef *tests/testthat.R
+30b231302ed86d4a6a45c339d7780561 *tests/testthat/Rplots.pdf
d3a921ea3008eada9d101257f4f15594 *tests/testthat/helper-plot-data.r
1076ad0ef6acd3a78dd8db456f9bba04 *tests/testthat/test-aes-grouping.r
-3495ad6baee576d4dba787926e739f01 *tests/testthat/test-aes-setting.r
+ae2c17740d61430bc7c28953b49e61d2 *tests/testthat/test-aes-setting.r
56417865028605cba1c09e3a5f39663a *tests/testthat/test-aes.r
1093aca9aab9868183b5357b945ed379 *tests/testthat/test-annotate.r
-9245ba261a33250b76c72466bcbb1ebe *tests/testthat/test-boxplot.r
+ebd4f529f2d6e6c75fd386bf4dd32c18 *tests/testthat/test-boxplot.r
dfb45a5e2f1c12d8ac1c5021a7d642af *tests/testthat/test-build.r
a61803e15d2625dc599faa8f3f6b1fb2 *tests/testthat/test-coord-polar.r
6e70a3a306f7272bb7391af0af9cb84e *tests/testthat/test-coord-train.r
9ec3f36295915b84878da970f38610cc *tests/testthat/test-data.r
d0b20527ddaca6ab1f99c1cfc449e15d *tests/testthat/test-dotplot.r
-2a70f0d37abe08e7f7b4e2746ff5f846 *tests/testthat/test-empty-data.r
+2b3c216d68ac31f27e027669bb17dbf6 *tests/testthat/test-empty-data.r
6728e5c8edd8d12a05308e12b82197b6 *tests/testthat/test-facet-.r
fafcc66255d651a5d3c8819fb0d069fd *tests/testthat/test-facet-labels.r
32772170a1a135a200a9748c63ddfbcc *tests/testthat/test-facet-layout.r
14ad2ef393e2b8c42ed26caae00faf1a *tests/testthat/test-facet-locate.r
+da4133fc542d63cc560632c272a8fead *tests/testthat/test-facet-strips.r
24307e570b5c3a261fbac843622f6dfb *tests/testthat/test-fortify.r
77262eb0c26b03cdcb6a7a610d584ccf *tests/testthat/test-function-args.r
+a313873083761be05009614b1af7f85b *tests/testthat/test-geom-boxplot.R
+30a99868232c5278af513e0d220f30bf *tests/testthat/test-geom-freqpoly.R
+7d5ddcaf54c7b4cf75a4448edc954ccf *tests/testthat/test-geom-ribbon.R
3a8b464d19174e4eece703c99839174c *tests/testthat/test-geom-rule.R
b7060e5ccf4c447b38e855310bfd140c *tests/testthat/test-geom-text.R
+ab3e947e4450a3a42d10b25d2fbffc98 *tests/testthat/test-geom-tile.R
11b564057fd03011bca4861fbf2c4798 *tests/testthat/test-geom-violin.R
f7de4f656b033dab01630f1ed918c7b5 *tests/testthat/test-ggsave.R
+493eb5e788ec25e42e2b67c03ef074df *tests/testthat/test-grid-utils.R
cb855e4c0ec9892813c5f86f838b3f52 *tests/testthat/test-guides.R
6318ef949123e4e13c938ffc0e3d4010 *tests/testthat/test-labels.r
-83d926bc18cbc8a2a138f73009cb169c *tests/testthat/test-layer.r
+98f8d9fc455c3c781d5f9f3bbb6e3ff7 *tests/testthat/test-layer.r
c2b1f4b1d448df295563ae1ed9dc1886 *tests/testthat/test-munch.r
972abcb47b4a68ac9f086af1c8198da9 *tests/testthat/test-qplot.r
99ee168c3f25007fca5e93c76453038c *tests/testthat/test-range.r
d2f2d93cd9cfda4de1268614593e15f9 *tests/testthat/test-sanitise-dim.r
+e8d8d6c6cf4d7cc4df05a43eecdd1fe7 *tests/testthat/test-scale-discrete.R
926a7d6e1dd028761c51e1926c605c82 *tests/testthat/test-scale-manual.r
11af33c3989010aec22c5c5ebb34108f *tests/testthat/test-scales-breaks-labels.r
cc078e4e9973263342f51212c2ecb71f *tests/testthat/test-scales.r
-e2e2f29a35ad159d12dae8517ab28794 *tests/testthat/test-stat-bin.R
-7a2de7d35f8f4e2a9a38596b8caedffd *tests/testthat/test-stat-bin2d.R
+21b7159e833753f4ea9389f7c9a17807 *tests/testthat/test-stat-bin.R
+6d202b2200dd789edfc46aa1751f34d6 *tests/testthat/test-stat-bin2d.R
264a54ed95553c9d2bef6fa83a8245c9 *tests/testthat/test-stat-density.R
10744c4e51dd7cd19728e845f4171880 *tests/testthat/test-stat-density2d.R
547fbe507cc42321b6257125ba33f1c3 *tests/testthat/test-stat-sum.R
-99fdfeb1c824e9ab041f78075a0b1f50 *tests/testthat/test-stats-function.r
+078bb7203f95d2e0b961f494ab73a0d2 *tests/testthat/test-stats-function.r
4b6d4c25b74a97b1e27a0e169126e37f *tests/testthat/test-stats.r
03ac3fdccc2a146db16f700f1b657cb6 *tests/testthat/test-theme.r
ce26fb5635464c1ddc29cd992f03108f *tests/testthat/test-utilities.r
ac880a6aa04fc8644fed280c88b5d674 *vignettes/car.png
-3ea1eef97dfdacc7cd6703ae5e1bb2ed *vignettes/extending-ggplot2.Rmd
-580964d5ac3b6030ddbfeb79f5123db3 *vignettes/ggplot2-specs.Rmd
+a0a183c6edece97cf73fbf564fbfa5b5 *vignettes/extending-ggplot2.Rmd
+7d2ce3bdee71e694250a1c764cfa5f8c *vignettes/ggplot2-specs.Rmd
diff --git a/NAMESPACE b/NAMESPACE
index 1c6da18..5297ffb 100644
--- a/NAMESPACE
+++ b/NAMESPACE
@@ -36,6 +36,7 @@ S3method(format,facet)
S3method(format,ggproto)
S3method(format,ggproto_method)
S3method(fortify,"NULL")
+S3method(fortify,"function")
S3method(fortify,Line)
S3method(fortify,Lines)
S3method(fortify,Polygon)
@@ -90,11 +91,13 @@ S3method(predictdf,loess)
S3method(print,element)
S3method(print,facet)
S3method(print,ggplot)
+S3method(print,ggplot2_bins)
S3method(print,ggproto)
S3method(print,ggproto_method)
S3method(print,rel)
S3method(print,theme)
S3method(print,uneval)
+S3method(scale_type,AsIs)
S3method(scale_type,Date)
S3method(scale_type,POSIXt)
S3method(scale_type,character)
@@ -102,6 +105,7 @@ S3method(scale_type,default)
S3method(scale_type,factor)
S3method(scale_type,logical)
S3method(scale_type,numeric)
+S3method(scale_type,ordered)
S3method(str,uneval)
S3method(summary,ggplot)
S3method(widthDetails,stripGrob)
@@ -371,6 +375,8 @@ export(scale_color_identity)
export(scale_color_manual)
export(scale_colour_brewer)
export(scale_colour_continuous)
+export(scale_colour_date)
+export(scale_colour_datetime)
export(scale_colour_discrete)
export(scale_colour_distiller)
export(scale_colour_gradient)
@@ -382,6 +388,8 @@ export(scale_colour_identity)
export(scale_colour_manual)
export(scale_fill_brewer)
export(scale_fill_continuous)
+export(scale_fill_date)
+export(scale_fill_datetime)
export(scale_fill_discrete)
export(scale_fill_distiller)
export(scale_fill_gradient)
@@ -405,6 +413,8 @@ export(scale_shape_manual)
export(scale_size)
export(scale_size_area)
export(scale_size_continuous)
+export(scale_size_date)
+export(scale_size_datetime)
export(scale_size_discrete)
export(scale_size_identity)
export(scale_size_manual)
@@ -460,6 +470,7 @@ export(theme_grey)
export(theme_light)
export(theme_linedraw)
export(theme_minimal)
+export(theme_replace)
export(theme_set)
export(theme_update)
export(theme_void)
diff --git a/NEWS.md b/NEWS.md
new file mode 100644
index 0000000..9e622fd
--- /dev/null
+++ b/NEWS.md
@@ -0,0 +1,635 @@
+# ggplot2 2.1.0
+
+## New features
+
+* When mapping an aesthetic to a constant (e.g.
+ `geom_smooth(aes(colour = "loess")))`), the default guide title is the name
+ of the aesthetic (i.e. "colour"), not the value (i.e. "loess") (#1431).
+
+* `layer()` now accepts a function as the data argument. The function will be
+ applied to the data passed to the `ggplot()` function and must return a
+ data.frame (#1527, @thomasp85). This is a more general version of the
+ deprecated `subset` argument.
+
+* `theme_update()` now uses the `+` operator instead of `%+replace%`, so that
+ unspecified values will no longer be `NULL`ed out. `theme_replace()`
+ preserves the old behaviour if desired (@oneillkza, #1519).
+
+* `stat_bin()` has been overhauled to use the same algorithm as ggvis, which
+ has been considerably improved thanks to the advice of Randy Prium (@rpruim).
+ This includes:
+
+ * Better arguments and a better algorithm for determining the origin.
+ You can now specify either `boundary` or the `center` of a bin.
+ `origin` has been deprecated in favour of these arguments.
+
+ * `drop` is deprecated in favour of `pad`, which adds extra 0-count bins
+ at either end (needed for frequency polygons). `geom_histogram()` defaults
+ to `pad = FALSE` which considerably improves the default limits for
+ the histogram, especially when the bins are big (#1477).
+
+ * The default algorithm does a (somewhat) better job at picking nice widths
+ and origins across a wider range of input data.
+
+ * `bins = n` now gives a histogram with `n` bins, not `n + 1` (#1487).
+
+## Bug fixes
+
+* All `\donttest{}` examples run.
+
+* All `geom_()` and `stat_()` functions now have consistent argument order:
+ data + mapping, then geom/stat/position, then `...`, then specific arguments,
+ then arguments common to all layers (#1305). This may break code if you were
+ previously relying on partial name matching, but in the long-term should make
+ ggplot2 easier to use. In particular, you can now set the `n` parameter
+ in `geom_density2d()` without it partially matching `na.rm` (#1485).
+
+* For geoms with both `colour` and `fill`, `alpha` once again only affects
+ fill (Reverts #1371, #1523). This was causing problems for people.
+
+* `facet_wrap()`/`facet_grid()` works with multiple empty panels of data
+ (#1445).
+
+* `facet_wrap()` correctly swaps `nrow` and `ncol` when facetting vertically
+ (#1417).
+
+* `ggsave("x.svg")` now uses svglite to produce the svg (#1432).
+
+* `geom_boxplot()` now understands `outlier.color` (#1455).
+
+* `geom_path()` knows that "solid" (not just 1) represents a solid line (#1534).
+
+* `geom_ribbon()` preserves missing values so they correctly generate a
+ gap in the ribbon (#1549).
+
+* `geom_tile()` once again accepts `width` and `height` parameters (#1513).
+ It uses `draw_key_polygon()` for better a legend, including a coloured
+ outline (#1484).
+
+* `layer()` now automatically adds a `na.rm` parameter if none is explicitly
+ supplied.
+
+* `position_jitterdodge()` now works on all possible dodge aesthetics,
+ e.g. `color`, `linetype` etc. instead of only based on `fill` (@bleutner)
+
+* `position = "nudge"` now works (although it doesn't do anything useful)
+ (#1428).
+
+* The default scale for columns of class "AsIs" is now "identity" (#1518).
+
+* `scale_*_discrete()` has better defaults when used with purely continuous
+ data (#1542).
+
+* `scale_size()` warns when used with categorical data.
+
+* `scale_size()`, `scale_colour()`, and `scale_fill()` gain date and date-time
+ variants (#1526).
+
+* `stat_bin_hex()` and `stat_bin_summary()` now use the same underlying
+ algorithm so results are consistent (#1383). `stat_bin_hex()` now accepts
+ a `weight` aesthetic. To be consistent with related stats, the output variable
+ from `stat_bin_hex()` is now value instead of count.
+
+* `stat_density()` gains a `bw` parameter which makes it easy to get consistent
+ smoothing between facets (@jiho)
+
+* `stat-density-2d()` no longer ignores the `h` parameter, and now accepts
+ `bins` and `binwidth` parameters to control the number of contours
+ (#1448, @has2k1).
+
+* `stat_ecdf()` does a better job of adding padding to -Inf/Inf, and gains
+ an argument `pad` to suppress the padding if not needed (#1467).
+
+* `stat_function()` gains an `xlim` parameter (#1528). It once again works
+ with discrete x values (#1509).
+
+* `stat_summary()` preserves sorted x order which avoids artefacts when
+ display results with `geom_smooth()` (#1520).
+
+* All elements should now inherit correctly for all themes except `theme_void()`.
+ (@Katiedaisey, #1555)
+
+* `theme_void()` was completely void of text but facets and legends still
+ need labels. They are now visible (@jiho).
+
+* You can once again set legend key and height width to unit arithmetic
+ objects (like `2 * unit(1, "cm")`) (#1437).
+
+* Eliminate spurious warning if you have a layer with no data and no aesthetics
+ (#1451).
+
+* Removed a superfluous comma in `theme-defaults.r` code (@jschoeley)
+
+* Fixed a compatibility issue with `ggproto` and R versions prior to 3.1.2.
+ (#1444)
+
+# ggplot2 2.0.0
+
+## Major changes
+
+* ggplot no longer throws an error if you your plot has no layers. Instead it
+ automatically adds `geom_blank()` (#1246).
+
+* New `cut_width()` is a convenient replacement for the verbose
+ `plyr::round_any()`, with the additional benefit of offering finer
+ control.
+
+* New `geom_count()` is a convenient alias to `stat_sum()`. Use it when you
+ have overlapping points on a scatterplot. `stat_sum()` now defaults to
+ using counts instead of proportions.
+
+* New `geom_curve()` adds curved lines, with a similar specification to
+ `geom_segment()` (@veraanadi, #1088).
+
+* Date and datetime scales now have `date_breaks`, `date_minor_breaks` and
+ `date_labels` arguments so that you never need to use the long
+ `scales::date_breaks()` or `scales::date_format()`.
+
+* `geom_bar()` now has it's own stat, distinct from `stat_bin()` which was
+ also used by `geom_histogram()`. `geom_bar()` now uses `stat_count()`
+ which counts values at each distinct value of x (i.e. it does not bin
+ the data first). This can be useful when you want to show exactly which
+ values are used in a continuous variable.
+
+* `geom_point()` gains a `stroke` aesthetic which controls the border width of
+ shapes 21-25 (#1133, @SeySayux). `size` and `stroke` are additive so a point
+ with `size = 5` and `stroke = 5` will have a diameter of 10mm. (#1142)
+
+* New `position_nudge()` allows you to slightly offset labels (or other
+ geoms) from their corresponding points (#1109).
+
+* `scale_size()` now maps values to _area_, not radius. Use `scale_radius()`
+ if you want the old behaviour (not recommended, except perhaps for lines).
+
+* New `stat_summary_bin()` works like `stat_summary()` but on binned data.
+ It's a generalisation of `stat_bin()` that can compute any aggregate,
+ not just counts (#1274). Both default to `mean_se()` if no aggregation
+ functions are supplied (#1386).
+
+* Layers are now much stricter about their arguments - you will get an error
+ if you've supplied an argument that isn't an aesthetic or a parameter.
+ This is likely to cause some short-term pain but in the long-term it will make
+ it much easier to spot spelling mistakes and other errors (#1293).
+
+ This change does break a handful of geoms/stats that used `...` to pass
+ additional arguments on to the underlying computation. Now
+ `geom_smooth()`/`stat_smooth()` and `geom_quantile()`/`stat_quantile()`
+ use `method.args` instead (#1245, #1289); and `stat_summary()` (#1242),
+ `stat_summary_hex()`, and `stat_summary2d()` use `fun.args`.
+
+### Extensibility
+
+There is now an official mechanism for defining Stats, Geoms, and Positions in other packages. See `vignette("extending-ggplot2")` for details.
+
+* All Geoms, Stats and Positions are now exported, so you can inherit from them
+ when making your own objects (#989).
+
+* ggplot2 no longer uses proto or reference classes. Instead, we now use
+ ggproto, a new OO system designed specifically for ggplot2. Unlike proto
+ and RC, ggproto supports clean cross-package inheritance. Creating a new OO
+ system isn't usually the right way to solve a problem, but I'm pretty sure
+ it was necessary here. Read more about it in the vignette.
+
+* `aes_()` replaces `aes_q()`. It also supports formulas, so the most concise
+ SE version of `aes(carat, price)` is now `aes_(~carat, ~price)`. You may
+ want to use this form in packages, as it will avoid spurious `R CMD check`
+ warnings about undefined global variables.
+
+### Text
+
+* `geom_text()` has been overhauled to make labelling your data a little
+ easier. It:
+
+ * `nudge_x` and `nudge_y` arguments let you offset labels from their
+ corresponding points (#1120).
+
+ * `check_overlap = TRUE` provides a simple way to avoid overplotting
+ of labels: labels that would otherwise overlap are omitted (#1039).
+
+ * `hjust` and `vjust` can now be character vectors: "left", "center",
+ "right", "bottom", "middle", "top". New options include "inward" and
+ "outward" which align text towards and away from the center of the plot
+ respectively.
+
+* `geom_label()` works like `geom_text()` but draws a rounded rectangle
+ underneath each label (#1039). This is useful when you want to label plots
+ that are dense with data.
+
+### Deprecated features
+
+* The little used `aes_auto()` has been deprecated.
+
+* `aes_q()` has been replaced with `aes_()` to be consistent with SE versions
+ of NSE functions in other packages.
+
+* The `order` aesthetic is officially deprecated. It never really worked, and
+ was poorly documented.
+
+* The `stat` and `position` arguments to `qplot()` have been deprecated.
+ `qplot()` is designed for quick plots - if you need to specify position
+ or stat, use `ggplot()` instead.
+
+* The theme setting `axis.ticks.margin` has been deprecated: now use the margin
+ property of `axis.ticks`.
+
+* `stat_abline()`, `stat_hline()` and `stat_vline()` have been removed:
+ these were never suitable for use other than with `geom_abline()` etc
+ and were not documented.
+
+* `show_guide` has been renamed to `show.legend`: this more accurately
+ reflects what it does (controls appearance of layer in legend), and uses the
+ same convention as other ggplot2 arguments (i.e. a `.` between names).
+ (Yes, I know that's inconsistent with function names with use `_`, but it's
+ too late to change now.)
+
+A number of geoms have been renamed to be internally consistent:
+
+* `stat_binhex()` and `stat_bin2d()` have been renamed to `stat_bin_hex()`
+ and `stat_bin_2d()` (#1274). `stat_summary2d()` has been renamed to
+ `stat_summary_2d()`, `geom_density2d()`/`stat_density2d()` has been renamed
+ to `geom_density_2d()`/`stat_density_2d()`.
+
+* `stat_spoke()` is now `geom_spoke()` since I realised it's a
+ reparameterisation of `geom_segment().
+
+* `stat_bindot()` has been removed because it's so tightly coupled to
+ `geom_dotplot()`. If you happened to use `stat_bindot()`, just change to
+ `geom_dotplot()` (#1194).
+
+All defunct functions have been removed.
+
+### Default appearance
+
+* The default `theme_grey()` background colour has been changed from "grey90"
+ to "grey92": this makes the background a little less visually prominent.
+
+* Labels and titles have been tweaked for readability:
+
+ * Axes labels are darker.
+
+ * Legend and axis titles are given the same visual treatment.
+
+ * The default font size dropped from 12 to 11. You might be surprised that
+ I've made the default text size smaller as it was already hard for
+ many people to read. It turns out there was a bug in RStudio (fixed in
+ 0.99.724), that shrunk the text of all grid based graphics. Once that
+ was resolved the defaults seemed too big to my eyes.
+
+ * More spacing between titles and borders.
+
+ * Default margins scale with the theme font size, so the appearance at
+ larger font sizes should be considerably improved (#1228).
+
+* `alpha` now affects both fill and colour aesthetics (#1371).
+
+* `element_text()` gains a margins argument which allows you to add additional
+ padding around text elements. To help see what's going on use `debug = TRUE`
+ to display the text region and anchors.
+
+* The default font size in `geom_text()` has been decreased from 5mm (14 pts)
+ to 3.8 mm (11 pts) to match the new default theme sizes.
+
+* A diagonal line is no longer drawn on bar and rectangle legends. Instead, the
+ border has been tweaked to be more visible, and more closely match the size of
+ line drawn on the plot.
+
+* `geom_pointrange()` and `geom_linerange()` get vertical (not horizontal)
+ lines in the legend (#1389).
+
+* The default line `size` for `geom_smooth()` has been increased from 0.5 to 1
+ to make it easier to see when overlaid on data.
+
+* `geom_bar()` and `geom_rect()` use a slightly paler shade of grey so they
+ aren't so visually heavy.
+
+* `geom_boxplot()` now colours outliers the same way as the boxes.
+
+* `geom_point()` now uses shape 19 instead of 16. This looks much better on
+ the default Linux graphics device. (It's very slightly smaller than the old
+ point, but it shouldn't affect any graphics significantly)
+
+* Sizes in ggplot2 are measured in mm. Previously they were converted to pts
+ (for use in grid) by multiplying by 72 / 25.4. However, grid uses printer's
+ points, not Adobe (big pts), so sizes are now correctly multiplied by
+ 72.27 / 25.4. This is unlikely to noticeably affect display, but it's
+ technically correct (<https://youtu.be/hou0lU8WMgo>).
+
+* The default legend will now allocate multiple rows (if vertical) or
+ columns (if horizontal) in order to make a legend that is more likely to
+ fit on the screen. You can override with the `nrow`/`ncol` arguments
+ to `guide_legend()`
+
+ ```R
+ p <- ggplot(mpg, aes(displ,hwy, colour = model)) + geom_point()
+ p
+ p + theme(legend.position = "bottom")
+ # Previous behaviour
+ p + guides(colour = guide_legend(ncol = 1))
+ ```
+
+### New and updated themes
+
+* New `theme_void()` is completely empty. It's useful for plots with non-
+ standard coordinates or for drawings (@jiho, #976).
+
+* New `theme_dark()` has a dark background designed to make colours pop out
+ (@jiho, #1018)
+
+* `theme_minimal()` became slightly more minimal by removing the axis ticks:
+ labels now line up directly beneath grid lines (@tomschloss, #1084)
+
+* New theme setting `panel.ontop` (logical) make it possible to place
+ background elements (i.e., gridlines) on top of data. Best used with
+ transparent `panel.background` (@noamross. #551).
+
+### Labelling
+
+The facet labelling system was updated with many new features and a
+more flexible interface (@lionel-). It now works consistently across
+grid and wrap facets. The most important user visible changes are:
+
+* `facet_wrap()` gains a `labeller` option (#25).
+
+* `facet_grid()` and `facet_wrap()` gain a `switch` argument to
+ display the facet titles near the axes. When switched, the labels
+ become axes subtitles. `switch` can be set to "x", "y" or "both"
+ (the latter only for grids) to control which margin is switched.
+
+The labellers (such as `label_value()` or `label_both()`) also get
+some new features:
+
+* They now offer the `multi_line` argument to control whether to
+ display composite facets (those specified as `~var1 + var2`) on one
+ or multiple lines.
+
+* In `label_bquote()` you now refer directly to the names of
+ variables. With this change, you can create math expressions that
+ depend on more than one variable. This math expression can be
+ specified either for the rows or the columns and you can also
+ provide different expressions to each margin.
+
+ As a consequence of these changes, referring to `x` in backquoted
+ expressions is deprecated.
+
+* Similarly to `label_bquote()`, `labeller()` now take `.rows` and
+ `.cols` arguments. In addition, it also takes `.default`.
+ `labeller()` is useful to customise how particular variables are
+ labelled. The three additional arguments specify how to label the
+ variables are not specifically mentioned, respectively for rows,
+ columns or both. This makes it especially easy to set up a
+ project-wide labeller dispatcher that can be reused across all your
+ plots. See the documentation for an example.
+
+* The new labeller `label_context()` adapts to the number of factors
+ facetted over. With a single factor, it displays only the values,
+ just as before. But with multiple factors in a composite margin
+ (e.g. with `~cyl + am`), the labels are passed over to
+ `label_both()`. This way the variables names are displayed with the
+ values to help identifying them.
+
+On the programming side, the labeller API has been rewritten in order
+to offer more control when facetting over multiple factors (e.g. with
+formulae such as `~cyl + am`). This also means that if you have
+written custom labellers, you will need to update them for this
+version of ggplot.
+
+* Previously, a labeller function would take `variable` and `value`
+ arguments and return a character vector. Now, they take a data frame
+ of character vectors and return a list. The input data frame has one
+ column per factor facetted over and each column in the returned list
+ becomes one line in the strip label. See documentation for more
+ details.
+
+* The labels received by a labeller now contain metadata: their margin
+ (in the "type" attribute) and whether they come from a wrap or a
+ grid facet (in the "facet" attribute).
+
+* Note that the new `as_labeller()` function operator provides an easy
+ way to transform an existing function to a labeller function. The
+ existing function just needs to take and return a character vector.
+
+## Documentation
+
+* Improved documentation for `aes()`, `layer()` and much much more.
+
+* I've tried to reduce the use of `...` so that you can see all the
+ documentation in one place rather than having to integrate multiple pages.
+ In some cases this has involved adding additional arguments to geoms
+ to make it more clear what you can do:
+
+ * `geom_smooth()` gains explicit `method`, `se` and `formula` arguments.
+
+ * `geom_histogram()` gains `binwidth`, `bins`, origin` and `right`
+ arguments.
+
+ * `geom_jitter()` gains `width` and `height` arguments to make it easier
+ to control the amount of jittering without using the lengthy
+ `position_jitter()` function (#1116)
+
+* Use of `qplot()` in examples has been minimised (#1123, @hrbrmstr). This is
+ inline with the 2nd edition of the ggplot2 box, which minimises the use of
+ `qplot()` in favour of `ggplot()`.
+
+* Tighly linked geoms and stats (e.g. `geom_boxplot()` and `stat_boxplot()`)
+ are now documented in the same file so you can see all the arguments in one
+ place. Variations of the same idea (e.g. `geom_path()`, `geom_line()`, and
+ `geom_step()`) are also documented together.
+
+* It's now obvious that you can set the `binwidth` parameter for
+ `stat_bin_hex()`, `stat_summary_hex()`, `stat_bin_2d()`, and
+ `stat_summary_2d()`.
+
+* The internals of positions have been cleaned up considerably. You're unlikely
+ to notice any external changes, although the documentation should be a little
+ less confusing since positions now don't list parameters they never use.
+
+## Data
+
+* All datasets have class `tbl_df` so if you also use dplyr, you get a better
+ print method.
+
+* `economics` has been brought up to date to 2015-04-01.
+
+* New `economics_long` is the economics data in long form.
+
+* New `txhousing` dataset containing information about the Texas housing
+ market. Useful for examples that need multiple time series, and for
+ demonstrating model+vis methods.
+
+* New `luv_colours` dataset which contains the locations of all
+ built-in `colors()` in Luv space.
+
+* `movies` has been moved into its own package, ggplot2movies, because it was
+ large and not terribly useful. If you've used the movies dataset, you'll now
+ need to explicitly load the package with `library(ggplot2movies)`.
+
+## Bug fixes and minor improvements
+
+* All partially matched arguments and `$` have been been replaced with
+ full matches (@jimhester, #1134).
+
+* ggplot2 now exports `alpha()` from the scales package (#1107), and `arrow()`
+ and `unit()` from grid (#1225). This means you don't need attach scales/grid
+ or do `scales::`/`grid::` for these commonly used functions.
+
+* `aes_string()` now only parses character inputs. This fixes bugs when
+ using it with numbers and non default `OutDec` settings (#1045).
+
+* `annotation_custom()` automatically adds a unique id to each grob name,
+ making it easier to plot multiple grobs with the same name (e.g. grobs of
+ ggplot2 graphics) in the same plot (#1256).
+
+* `borders()` now accepts xlim and ylim arguments for specifying the geographical
+ region of interest (@markpayneatwork, #1392).
+
+* `coord_cartesian()` applies the same expansion factor to limits as for scales.
+ You can suppress with `expand = FALSE` (#1207).
+
+* `coord_trans()` now works when breaks are suppressed (#1422).
+
+* `cut_number()` gives error message if the number of requested bins can
+ be created because there are two few unique values (#1046).
+
+* Character labels in `facet_grid()` are no longer (incorrectly) coerced into
+ factors. This caused problems with custom label functions (#1070).
+
+* `facet_wrap()` and `facet_grid()` now allow you to use non-standard
+ variable names by surrounding them with backticks (#1067).
+
+* `facet_wrap()` more carefully checks its `nrow` and `ncol` arguments
+ to ensure that they're specified correctly (@richierocks, #962)
+
+* `facet_wrap()` gains a `dir` argument to control the direction the
+ panels are wrapped in. The default is "h" for horizontal. Use "v" for
+ vertical layout (#1260).
+
+* `geom_abline()`, `geom_hline()` and `geom_vline()` have been rewritten to
+ have simpler behaviour and be more consistent:
+
+ * `stat_abline()`, `stat_hline()` and `stat_vline()` have been removed:
+ these were never suitable for use other than with `geom_abline()` etc
+ and were not documented.
+
+ * `geom_abline()`, `geom_vline()` and `geom_hline()` are bound to
+ `stat_identity()` and `position_identity()`
+
+ * Intercept parameters can no longer be set to a function.
+
+ * They are all documented in one file, since they are so closely related.
+
+* `geom_bin2d()` will now let you specify one dimension's breaks exactly,
+ without touching the other dimension's default breaks at all (#1126).
+
+* `geom_crossbar()` sets grouping correctly so you can display multiple
+ crossbars on one plot. It also makes the default `fatten` argument a little
+ bigger to make the middle line more obvious (#1125).
+
+* `geom_histogram()` and `geom_smooth()` now only inform you about the
+ default values once per layer, rather than once per panel (#1220).
+
+* `geom_pointrange()` gains `fatten` argument so you can control the
+ size of the point relative to the size of the line.
+
+* `geom_segment()` annotations were not transforming with scales
+ (@BrianDiggs, #859).
+
+* `geom_smooth()` is no longer so chatty. If you want to know what the deafult
+ smoothing method is, look it up in the documentation! (#1247)
+
+* `geom_violin()` now has the ability to draw quantile lines (@DanRuderman).
+
+* `ggplot()` now captures the parent frame to use for evaluation,
+ rather than always defaulting to the global environment. This should
+ make ggplot more suitable to use in more situations (e.g. with knitr)
+
+* `ggsave()` has been simplified a little to make it easier to maintain.
+ It no longer checks that you're printing a ggplot2 object (so now also
+ works with any grid grob) (#970), and always requires a filename.
+ Parameter `device` now supports character argument to specify which supported
+ device to use ('pdf', 'png', 'jpeg', etc.), for when it cannot be correctly
+ inferred from the file extension (for example when a temporary filename is
+ supplied server side in shiny apps) (@sebkopf, #939). It no longer opens
+ a graphics device if one isn't already open - this is annoying when you're
+ running from a script (#1326).
+
+* `guide_colorbar()` creates correct legend if only one color (@krlmlr, #943).
+
+* `guide_colorbar()` no longer fails when the legend is empty - previously
+ this often masked misspecifications elsewhere in the plot (#967).
+
+* New `layer_data()` function extracts the data used for plotting for a given
+ layer. It's mostly useful for testing.
+
+* User supplied `minor_breaks` can now be supplied on the same scale as
+ the data, and will be automatically transformed with by scale (#1385).
+
+* You can now suppress the appearance of an axis/legend title (and the space
+ that would allocated for it) with `NULL` in the `scale_` function. To
+ use the default lable, use `waiver()` (#1145).
+
+* Position adjustments no longer warn about potentially varying ranges
+ because the problem rarely occurs in practice and there are currently a
+ lot of false positives since I don't understand exactly what FP criteria
+ I should be testing.
+
+* `scale_fill_grey()` now uses red for missing values. This matches
+ `scale_colour_grey()` and makes it obvious where missing values lie.
+ Override with `na.value`.
+
+* `scale_*_gradient2()` defaults to using Lab colour space.
+
+* `scale_*_gradientn()` now allows `colours` or `colors` (#1290)
+
+* `scale_y_continuous()` now also transforms the `lower`, `middle` and `upper`
+ aesthetics used by `geom_boxplot()`: this only affects
+ `geom_boxplot(stat = "identity")` (#1020).
+
+* Legends no longer inherit aesthetics if `inherit.aes` is FALSE (#1267).
+
+* `lims()` makes it easy to set the limits of any axis (#1138).
+
+* `labels = NULL` now works with `guide_legend()` and `guide_colorbar()`.
+ (#1175, #1183).
+
+* `override.aes` now works with American aesthetic spelling, e.g. color
+
+* Scales no longer round data points to improve performance of colour
+ palettes. Instead the scales package now uses a much faster colour
+ interpolation algorithm (#1022).
+
+* `scale_*_brewer()` and `scale_*_distiller()` add new `direction` argument of
+ `scales::brewer_pal`, making it easier to change the order of colours
+ (@jiho, #1139).
+
+* `scale_x_date()` now clips dates outside the limits in the same way as
+ `scale_x_continuous()` (#1090).
+
+* `stat_bin()` gains `bins` arguments, which denotes the number of bins. Now
+ you can set `bins=100` instead of `binwidth=0.5`. Note that `breaks` or
+ `binwidth` will override it (@tmshn, #1158, #102).
+
+* `stat_boxplot()` warns if a continuous variable is used for the `x` aesthetic
+ without also supplying a `group` aesthetic (#992, @krlmlr).
+
+* `stat_summary_2d()` and `stat_bin_2d()` now share exactly the same code for
+ determining breaks from `bins`, `binwidth`, and `origin`.
+
+* `stat_summary_2d()` and `stat_bin_2d()` now output in tile/raster compatible
+ form instead of rect compatible form.
+
+* Automatically computed breaks do not lead to an error for transformations like
+ "probit" where the inverse can map to infinity (#871, @krlmlr)
+
+* `stat_function()` now always evaluates the function on the original scale.
+ Previously it computed the function on transformed scales, giving incorrect
+ values (@BrianDiggs, #1011).
+
+* `strip_dots` works with anonymous functions within calculated aesthetics
+ (e.g. `aes(sapply(..density.., function(x) mean(x))))` (#1154, @NikNakk)
+
+* `theme()` gains `validate = FALSE` parameter to turn off validation, and
+ hence store arbitrary additional data in the themes. (@tdhock, #1121)
+
+* Improved the calculation of segments needed to draw the curve representing
+ a line when plotted in polar coordinates. In some cases, the last segment
+ of a multi-segment line was not drawn (@BrianDiggs, #952)
diff --git a/R/aes.r b/R/aes.r
index fe72c2c..410317c 100644
--- a/R/aes.r
+++ b/R/aes.r
@@ -112,7 +112,7 @@ is_position_aes <- function(vars) {
#' evaluation to capture the variable names. \code{aes_} and \code{aes_string}
#' require you to explicitly quote the inputs either with \code{""} for
#' \code{aes_string()}, or with \code{quote} or \code{~} for \code{aes_()}.
-#' (\code{aes_q} is an alias to \code{aeq_})
+#' (\code{aes_q} is an alias to \code{aes_})
#'
#' It's better to use \code{aes_q()}, because there's no easy way to create the
#' equivalent to \code{aes(colour = "my colour")} or \code{aes{x = `X$1`}}
diff --git a/R/annotation-custom.r b/R/annotation-custom.r
index 1659b26..77404b5 100644
--- a/R/annotation-custom.r
+++ b/R/annotation-custom.r
@@ -26,16 +26,13 @@ NULL
#' base <- ggplot(df, aes(x, y)) +
#' geom_blank() +
#' theme_bw()
-#' # Adding a table
-#' \dontrun{
-#' if (require(gridExtra)) {
-#' base + annotation_custom(grob = tableGrob(head(iris[ ,1:3])),
-#' xmin = 3, xmax = 6, ymin = 2, ymax = 8)
-#' # full panel
-#' base + annotation_custom(grob = roundrectGrob(),
-#' xmin = -Inf, xmax = Inf, ymin = -Inf, ymax = Inf)
-#' }
-#' }
+#'
+#' # 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)) +
diff --git a/R/annotation.r b/R/annotation.r
index 70d3f3f..d810024 100644
--- a/R/annotation.r
+++ b/R/annotation.r
@@ -14,8 +14,7 @@
#' @param geom name of geom to use for annotation
#' @param x,y,xmin,ymin,xmax,ymax,xend,yend positioning aesthetics -
#' you must specify at least one of these.
-#' @param ... other aesthetics. These are not scaled so you can do (e.g.)
-#' \code{colour = "red"} to get a red point.
+#' @inheritParams layer
#' @inheritParams geom_point
#' @export
#' @examples
diff --git a/R/bin.R b/R/bin.R
new file mode 100644
index 0000000..1d58d3e
--- /dev/null
+++ b/R/bin.R
@@ -0,0 +1,171 @@
+bins <- function(breaks, closed = c("right", "left"),
+ fuzz = 1e-08 * stats::median(diff(breaks))) {
+ stopifnot(is.numeric(breaks))
+ closed <- match.arg(closed)
+
+ breaks <- sort(breaks)
+ # Adapted base::hist - this protects from floating point rounding errors
+ if (closed == "right") {
+ fuzzes <- c(-fuzz, rep.int(fuzz, length(breaks) - 1))
+ } else {
+ fuzzes <- c(rep.int(-fuzz, length(breaks) - 1), fuzz)
+ }
+
+ structure(
+ list(
+ breaks = breaks,
+ fuzzy = breaks + fuzzes,
+ right_closed = closed == "right"
+ ),
+ class = "ggplot2_bins"
+ )
+}
+
+is_bins <- function(x) inherits(x, "ggplot2_bins")
+
+#' @export
+print.ggplot2_bins <- function(x, ...) {
+ n <- length(x$breaks)
+ cat("<Bins>\n")
+
+ if (x$right_closed) {
+ left <- c("[", rep("(", n - 2))
+ right <- rep("]", n - 1)
+ } else {
+ left <- rep("[", n - 1)
+ right <- c(rep(")", n - 2), "]")
+ }
+
+ breaks <- format(x$breaks)
+ bins <- paste0("* ", left, breaks[-n], ",", breaks[-1], right)
+ cat(bins, sep = "\n")
+ cat("\n")
+}
+
+# Compute parameters -----------------------------------------------------------
+
+bin_breaks <- function(breaks, closed = c("right", "left")) {
+ bins(breaks, closed)
+}
+
+bin_breaks_width <- function(x_range, width = NULL, center = NULL,
+ boundary = NULL, closed = c("right", "left")) {
+ stopifnot(length(x_range) == 2)
+
+ # if (length(x_range) == 0) {
+ # return(bin_params(numeric()))
+ # }
+ stopifnot(is.numeric(width), length(width) == 1)
+ if (width <= 0) {
+ stop("`binwidth` must be positive", call. = FALSE)
+ }
+
+ if (!is.null(boundary) && !is.null(center)) {
+ stop("Only one of 'boundary' and 'center' may be specified.")
+ } else if (is.null(boundary)) {
+ if (is.null(center)) {
+ # If neither edge nor center given, compute both using tile layer's
+ # algorithm. This puts min and max of data in outer half of their bins.
+ boundary <- width / 2
+
+ } else {
+ # If center given but not boundary, compute boundary.
+ boundary <- center - width / 2
+ }
+ }
+
+ # Find the left side of left-most bin: inputs could be Dates or POSIXct, so
+ # coerce to numeric first.
+ x_range <- as.numeric(x_range)
+ width <- as.numeric(width)
+ boundary <- as.numeric(boundary)
+ shift <- floor((x_range[1] - boundary) / width)
+ origin <- boundary + shift * width
+
+ # Small correction factor so that we don't get an extra bin when, for
+ # example, origin = 0, max(x) = 20, width = 10.
+ max_x <- x_range[2] + (1 - 1e-08) * width
+ breaks <- seq(origin, max_x, width)
+
+ bin_breaks(breaks, closed = closed)
+}
+
+bin_breaks_bins <- function(x_range, bins = 30, center = NULL,
+ boundary = NULL, closed = c("right", "left")) {
+ stopifnot(length(x_range) == 2)
+
+ bins <- as.integer(bins)
+ if (bins < 1) {
+ stop("Need at least one bin.", call. = FALSE)
+ } else if (bins == 1) {
+ width <- diff(x_range)
+ boundary <- x_range[1]
+ } else {
+ width <- (x_range[2] - x_range[1]) / (bins - 1)
+ }
+
+ bin_breaks_width(x_range, width, boundary = boundary, center = center,
+ closed = closed)
+}
+
+
+# Compute bins ------------------------------------------------------------
+
+bin_vector <- function(x, bins, weight = NULL, pad = FALSE) {
+ stopifnot(is_bins(bins))
+
+ if (all(is.na(x))) {
+ return(bin_out(length(x), NA, NA, xmin = NA, xmax = NA))
+ }
+
+ if (is.null(weight)) {
+ weight <- rep(1, length(x))
+ } else {
+ weight[is.na(weight)] <- 0
+ }
+
+ bin_idx <- cut(x, bins$breaks, right = bins$right_closed,
+ include.lowest = TRUE)
+ bin_count <- as.numeric(tapply(weight, bin_idx, sum, na.rm = TRUE))
+ bin_count[is.na(bin_count)] <- 0
+
+ bin_x <- (bins$breaks[-length(bins$breaks)] + bins$breaks[-1]) / 2
+ bin_widths <- diff(bins$breaks)
+
+ # Pad row of 0s at start and end
+ if (pad) {
+ bin_count <- c(0, bin_count, 0)
+
+ width1 <- bin_widths[1]
+ widthn <- bin_widths[length(bin_widths)]
+
+ bin_widths <- c(width1, bin_widths, widthn)
+ bin_x <- c(bin_x[1] - width1, bin_x, bin_x[length(bin_x)] + widthn)
+ }
+
+ # Add row for missings
+ if (any(is.na(bins))) {
+ bin_count <- c(bin_count, sum(is.na(bins)))
+ bin_widths <- c(bin_widths, NA)
+ bin_x <- c(bin_x, NA)
+ }
+
+ bin_out(bin_count, bin_x, bin_widths)
+}
+
+bin_out <- function(count = integer(0), x = numeric(0), width = numeric(0),
+ xmin = x - width / 2, xmax = x + width / 2) {
+ density <- count / width / sum(abs(count))
+
+ data.frame(
+ count = count,
+ x = x,
+ xmin = xmin,
+ xmax = xmax,
+ width = width,
+ density = density,
+ ncount = count / max(abs(count)),
+ ndensity = count / max(abs(density)),
+ stringsAsFactors = FALSE
+ )
+}
diff --git a/R/data.R b/R/data.R
index adc052d..211d113 100644
--- a/R/data.R
+++ b/R/data.R
@@ -135,12 +135,12 @@
#' }
"msleep"
-#' Terms of 10 presidents from Eisenhower to Bush W.
+#' Terms of 11 presidents from Eisenhower to Obama.
#'
#' The names of each president, the start and end date of their term, and
-#' their party of 10 US presidents from Eisenhower to Bush W.
+#' their party of 11 US presidents from Eisenhower to Obama.
#'
-#' @format A data frame with 10 rows and 4 variables
+#' @format A data frame with 11 rows and 4 variables
"presidential"
#' Vector field of seal movements.
diff --git a/R/facet-grid-.r b/R/facet-grid-.r
index acd2449..4d8f941 100644
--- a/R/facet-grid-.r
+++ b/R/facet-grid-.r
@@ -45,66 +45,24 @@
#' will be shown, regardless of whether or not they appear in the data.
#' @export
#' @examples
-#' \donttest{
-#' p <- ggplot(mtcars, aes(mpg, wt)) + geom_point()
-#' # With one variable
-#' p + facet_grid(. ~ cyl)
-#' p + facet_grid(cyl ~ .)
+#' p <- ggplot(mpg, aes(displ, cty)) + geom_point()
#'
-#' # With two variables
-#' p + facet_grid(vs ~ am)
-#' p + facet_grid(am ~ vs)
-#' p + facet_grid(vs ~ am, margins=TRUE)
+#' p + facet_grid(. ~ cyl)
+#' p + facet_grid(drv ~ .)
+#' p + facet_grid(drv ~ cyl)
#'
#' # To change plot order of facet grid,
#' # change the order of variable levels with factor()
#'
-#' set.seed(6809)
-#' diamonds <- diamonds[sample(nrow(diamonds), 1000), ]
-#' diamonds$cut <- factor(diamonds$cut,
-#' levels = c("Ideal", "Very Good", "Fair", "Good", "Premium"))
-#'
-#' # Repeat first example with new order
-#' p <- ggplot(diamonds, aes(carat, ..density..)) +
-#' geom_histogram(binwidth = 1)
-#' p + facet_grid(. ~ cut)
-#'
-#' g <- ggplot(mtcars, aes(mpg, wt)) +
-#' geom_point()
-#' g + facet_grid(. ~ vs + am)
-#' g + facet_grid(vs + am ~ .)
-#'
-#' # You can also use strings, which makes it a little easier
-#' # when writing functions that generate faceting specifications
-#'
-#' p + facet_grid("cut ~ .")
-#'
-#' # see also ?plotmatrix for the scatterplot matrix
-#'
-#' # If there isn't any data for a given combination, that panel
-#' # will be empty
-#'
-#' g + facet_grid(cyl ~ vs)
-#'
#' # If you combine a facetted dataset with a dataset that lacks those
#' # facetting variables, the data will be repeated across the missing
#' # combinations:
-#'
-#' g + facet_grid(vs ~ cyl)
-#'
-#' df <- data.frame(mpg = 22, wt = 3)
-#' g + facet_grid(vs ~ cyl) +
+#' df <- data.frame(displ = mean(mpg$displ), cty = mean(mpg$cty))
+#' p +
+#' facet_grid(. ~ cyl) +
#' geom_point(data = df, colour = "red", size = 2)
#'
-#' df2 <- data.frame(mpg = c(19, 22), wt = c(2,4), vs = c(0, 1))
-#' g + facet_grid(vs ~ cyl) +
-#' geom_point(data = df2, colour = "red", size = 2)
-#'
-#' df3 <- data.frame(mpg = c(19, 22), wt = c(2,4), vs = c(1, 1))
-#' g + facet_grid(vs ~ cyl) +
-#' geom_point(data = df3, colour = "red", size = 2)
-#'
-#'
+#' # 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
@@ -112,52 +70,44 @@
#' geom_point()
#'
#' mt + facet_grid(. ~ 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
-#' mt + facet_grid(. ~ cyl, scales = "free", space = "free")
+#' # 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))
#'
-#' mt + facet_grid(vs ~ am, scales = "free")
-#' mt + facet_grid(vs ~ am, scales = "free_x")
-#' mt + facet_grid(vs ~ am, scales = "free_y")
-#' mt + facet_grid(vs ~ am, scales = "free", space = "free")
-#' mt + facet_grid(vs ~ am, scales = "free", space = "free_x")
-#' mt + facet_grid(vs ~ am, scales = "free", space = "free_y")
+#' # Facet labels ------------------------------------------------------
+#' p <- ggplot(mtcars, aes(wt, mpg)) + geom_point()
+#' p
#'
-#' # You may need to set your own breaks for consistent display:
-#' mt + facet_grid(. ~ cyl, scales = "free_x", space = "free") +
-#' scale_x_continuous(breaks = seq(10, 36, by = 2))
-#' # Adding scale limits override free scales:
-#' last_plot() + xlim(10, 15)
+#' # label_both() displays both variable name and value
+#' p + facet_grid(vs ~ cyl, labeller = label_both)
#'
-#' # Free scales are particularly useful for categorical variables
-#' ggplot(mpg, aes(cty, model)) +
+#' # label_parsed() parses text into mathematical expressions, see ?plotmath
+#' mtcars$cyl2 <- factor(mtcars$cyl, labels = c("alpha", "beta", "sqrt(x, y)"))
+#' ggplot(mtcars, aes(wt, mpg)) +
#' geom_point() +
-#' facet_grid(manufacturer ~ ., scales = "free", space = "free")
-#' # particularly when you reorder factor levels
-#' mpg$model <- reorder(mpg$model, mpg$cty)
-#' manufacturer <- reorder(mpg$manufacturer, mpg$cty)
-#' last_plot() %+% mpg + theme(strip.text.y = element_text())
+#' facet_grid(. ~ cyl2, labeller = label_parsed)
#'
-#' # Use as.table to to control direction of horizontal facets, TRUE by default
-#' h <- ggplot(mtcars, aes(x = mpg, y = wt)) +
-#' geom_point()
-#' h + facet_grid(cyl ~ vs)
-#' h + facet_grid(cyl ~ vs, as.table = FALSE)
+#' # label_bquote() makes it easy to construct math expressions
+#' p + facet_grid(. ~ vs, labeller = label_bquote(cols = alpha ^ .(vs)))
#'
-#' # Use labeller to control facet labels, label_value is default
-#' h + facet_grid(cyl ~ vs, labeller = label_both)
-#' # Using label_parsed, see ?plotmath for more options
-#' mtcars$cyl2 <- factor(mtcars$cyl, labels = c("alpha", "beta", "sqrt(x, y)"))
-#' k <- ggplot(mtcars, aes(wt, mpg)) +
-#' geom_point()
-#' k + facet_grid(. ~ cyl2)
-#' k + facet_grid(. ~ cyl2, labeller = label_parsed)
-#' # For label_bquote the label value is x.
-#' p <- ggplot(mtcars, aes(wt, mpg)) +
-#' geom_point()
-#' p + facet_grid(. ~ vs, labeller = label_bquote(alpha ^ .(x)))
-#' p + facet_grid(. ~ vs, labeller = label_bquote(.(x) ^ .(x)))
+#' # The facet strips can be displayed near the axes with switch
+#' data <- transform(mtcars,
+#' am = factor(am, levels = 0:1, c("Automatic", "Manual")),
+#' gear = factor(gear, levels = 3:5, labels = c("Three", "Four", "Five"))
+#' )
+#' p <- ggplot(data, aes(mpg, disp)) + geom_point()
+#' p + facet_grid(am ~ gear, switch = "both")
+#' # It looks better without boxes around the strips
+#' p + facet_grid(am ~ gear, switch = "both") +
+#' theme(strip.background = element_blank())
#'
+#' # Margins ----------------------------------------------------------
+#' \donttest{
#' # Margins can be specified by logically (all yes or all no) or by specific
#' # variables as (character) variable names
#' mg <- ggplot(mtcars, aes(x = mpg, y = wt)) + geom_point()
@@ -170,20 +120,6 @@
#' mg + facet_grid(vs + am ~ gear, margins = "vs")
#' mg + facet_grid(vs + am ~ gear, margins = "gear")
#' mg + facet_grid(vs + am ~ gear, margins = c("gear", "am"))
-#'
-#' # The facet strips can be displayed near the axes with switch
-#' data <- transform(mtcars,
-#' am = factor(am, levels = 0:1, c("Automatic", "Manual")),
-#' gear = factor(gear, levels = 3:5, labels = c("Three", "Four", "Five"))
-#' )
-#' p <- ggplot(data, aes(mpg, disp)) + geom_point()
-#' p + facet_grid(am ~ gear, switch = "both") + theme_light()
-#'
-#' # It may be more aesthetic to use a theme without boxes around
-#' # around the strips.
-#' p + facet_grid(am ~ gear + vs, switch = "y") + theme_minimal()
-#' p + facet_grid(am ~ ., switch = "y") +
-#' theme_gray() %+replace% theme(strip.background = element_blank())
#' }
#' @importFrom plyr as.quoted
facet_grid <- function(facets, margins = FALSE, scales = "fixed", space = "fixed", shrink = TRUE, labeller = "label_value", as.table = TRUE, switch = NULL, drop = TRUE) {
diff --git a/R/facet-wrap.r b/R/facet-wrap.r
index ea65a14..66004b1 100644
--- a/R/facet-wrap.r
+++ b/R/facet-wrap.r
@@ -86,8 +86,10 @@ facet_wrap <- function(facets, nrow = NULL, ncol = NULL, scales = "fixed",
if (identical(dir, "v")) {
# swap
- nrow <- sanitise_dim(ncol)
- ncol <- sanitise_dim(nrow)
+ nrow_swap <- ncol
+ ncol_swap <- nrow
+ nrow <- sanitise_dim(nrow_swap)
+ ncol <- sanitise_dim(ncol_swap)
} else {
nrow <- sanitise_dim(nrow)
ncol <- sanitise_dim(ncol)
@@ -343,11 +345,11 @@ facet_strips.wrap <- function(facet, panel, theme) {
# Adding labels metadata, useful for labellers
attr(labels_df, "facet") <- "wrap"
- if (!is.null(facet$switch) && facet$switch == "x") {
+ if (is.null(facet$switch) || facet$switch == "x") {
dir <- "b"
attr(labels_df, "type") <- "rows"
} else {
- dir <- "t"
+ dir <- "l"
attr(labels_df, "type") <- "cols"
}
@@ -355,10 +357,20 @@ facet_strips.wrap <- function(facet, panel, theme) {
theme, dir, switch = facet$switch)
# While grid facetting works with a whole gtable, wrap processes the
- # columns separately. So we turn the gtable into a list of columns
- strips <- list(t = vector("list", ncol(strips_table)))
+ # strips separately. So we turn the gtable into a list
+ if (dir == "b") {
+ n_strips <- ncol(strips_table)
+ } else {
+ n_strips <- nrow(strips_table)
+ }
+
+ strips <- list(t = vector("list", n_strips))
for (i in seq_along(strips$t)) {
- strips$t[[i]] <- strips_table[, i]
+ if (dir == "b") {
+ strips$t[[i]] <- strips_table[, i]
+ } else {
+ strips$t[[i]] <- strips_table[i, ]
+ }
}
strips
}
@@ -413,7 +425,7 @@ facet_vars.wrap <- function(facet) {
#' # Valid input just gets returns unchanged
#' sanitise_dim(1)
#' sanitise_dim(NULL)
-#' \dontrun{
+#'
#' # Only the first element of vectors get returned
#' sanitise_dim(10:1)
#' # Non-integer values are coerced to integer
@@ -423,7 +435,6 @@ facet_vars.wrap <- function(facet) {
#' sanitise_dim(NA_integer_)
#' sanitise_dim(0)
#' sanitise_dim("foo")
-#' }
#' @noRd
sanitise_dim <- function(n) {
xname <- paste0("`", deparse(substitute(n)), "`")
diff --git a/R/fortify.r b/R/fortify.r
index fa4356b..a35be2a 100644
--- a/R/fortify.r
+++ b/R/fortify.r
@@ -16,7 +16,12 @@ fortify.data.frame <- function(model, data, ...) model
#' @export
fortify.NULL <- function(model, data, ...) waiver()
#' @export
+fortify.function <- function(model, data, ...) model
+#' @export
fortify.default <- function(model, data, ...) {
-
- stop("ggplot2 doesn't know how to deal with data of class ", class(model), call. = FALSE)
+ stop(
+ "ggplot2 doesn't know how to deal with data of class ",
+ paste(class(model), collapse = "/"),
+ call. = FALSE
+ )
}
diff --git a/R/geom-.r b/R/geom-.r
index 03fa679..610824e 100644
--- a/R/geom-.r
+++ b/R/geom-.r
@@ -67,7 +67,10 @@ Geom <- ggproto("Geom",
},
draw_layer = function(self, data, params, panel, coord) {
- if (empty(data)) return(list(zeroGrob()))
+ if (empty(data)) {
+ n <- if (is.factor(data$PANEL)) nlevels(data$PANEL) else 1L
+ return(rep(list(zeroGrob()), n))
+ }
# Trim off extra parameters
params <- params[intersect(names(params), self$parameters())]
diff --git a/R/geom-abline.r b/R/geom-abline.r
index 818745e..518c648 100644
--- a/R/geom-abline.r
+++ b/R/geom-abline.r
@@ -32,10 +32,11 @@ NULL
#'
#' @seealso See \code{\link{geom_segment}} for a more general approach to
#' adding straight line segments to a plot.
+#' @inheritParams layer
+#' @inheritParams geom_point
#' @param xintercept,yintercept,slope,intercept Parameters that control the
#' position of the line. If these are set, \code{data}, \code{mapping} and
#' \code{show.legend} are overridden
-#' @inheritParams geom_point
#' @export
#' @examples
#' p <- ggplot(mtcars, aes(wt, mpg)) + geom_point()
@@ -69,8 +70,10 @@ NULL
#' facet_wrap(~ cyl)
geom_abline <- function(mapping = NULL, data = NULL,
...,
- slope, intercept,
- na.rm = FALSE, show.legend = NA) {
+ slope,
+ intercept,
+ na.rm = FALSE,
+ show.legend = NA) {
# If nothing set, default to y = x
if (missing(mapping) && missing(slope) && missing(intercept)) {
diff --git a/R/geom-bar.r b/R/geom-bar.r
index 52ae972..ca264d4 100644
--- a/R/geom-bar.r
+++ b/R/geom-bar.r
@@ -26,6 +26,7 @@
#' @seealso \code{\link{geom_histogram}} for continuous data,
#' \code{\link{position_dodge}} for creating side-by-side barcharts.
#' @export
+#' @inheritParams layer
#' @inheritParams geom_point
#' @param width Bar width. By default, set to 90\% of the resolution of the data.
#' @param binwidth \code{geom_bar} no longer has a binwidth argument - if
@@ -73,9 +74,14 @@
#' }
#' ggplot(mpg, aes(reorder_size(class))) + geom_bar()
#' }
-geom_bar <- function(mapping = NULL, data = NULL, stat = "count",
- position = "stack", width = NULL, binwidth = NULL, ...,
- na.rm = FALSE, show.legend = NA, inherit.aes = TRUE) {
+geom_bar <- function(mapping = NULL, data = NULL,
+ stat = "count", position = "stack",
+ ...,
+ width = NULL,
+ binwidth = NULL,
+ na.rm = FALSE,
+ show.legend = NA,
+ inherit.aes = TRUE) {
if (!is.null(binwidth)) {
warning("`geom_bar()` no longer has a `binwidth` parameter. ",
diff --git a/R/geom-bin2d.r b/R/geom-bin2d.r
index 97bbdff..c372eed 100644
--- a/R/geom-bin2d.r
+++ b/R/geom-bin2d.r
@@ -4,6 +4,7 @@
#' \Sexpr[results=rd,stage=build]{ggplot2:::rd_aesthetics("stat", "bin2d")}
#'
#' @export
+#' @inheritParams layer
#' @inheritParams geom_point
#' @param geom,stat Use to override the default connection between
#' \code{geom_bin2d} and \code{stat_bin2d}.
@@ -19,9 +20,12 @@
#'
#' # Or by specifying the width of the bins
#' d + geom_bin2d(binwidth = c(0.1, 0.1))
-geom_bin2d <- function(mapping = NULL, data = NULL, stat = "bin2d",
- position = "identity", na.rm = FALSE,
- show.legend = NA, inherit.aes = TRUE, ...) {
+geom_bin2d <- function(mapping = NULL, data = NULL,
+ stat = "bin2d", position = "identity",
+ ...,
+ na.rm = FALSE,
+ show.legend = NA,
+ inherit.aes = TRUE) {
layer(
data = data,
diff --git a/R/geom-blank.r b/R/geom-blank.r
index fc9cc74..133a2fa 100644
--- a/R/geom-blank.r
+++ b/R/geom-blank.r
@@ -4,26 +4,16 @@
#' scales between different plots.
#'
#' @export
+#' @inheritParams layer
#' @inheritParams geom_point
#' @examples
-#' ggplot(mtcars, aes(wt, mpg)) + geom_blank()
+#' ggplot(mtcars, aes(wt, mpg))
#' # Nothing to see here!
-#'
-#' # Take the following scatter plot
-#' a <- ggplot(mtcars, aes(x = wt, y = mpg), . ~ cyl) + geom_point()
-#' # Add to that some lines with geom_abline()
-#' df <- data.frame(a = rnorm(10, 25), b = rnorm(10, 0))
-#' a + geom_abline(aes(intercept = a, slope = b), data = df)
-#' # Suppose you then wanted to remove the geom_point layer
-#' # If you just remove geom_point, you will get an error
-#' b <- ggplot(mtcars, aes(x = wt, y = mpg))
-#' \dontrun{b + geom_abline(aes(intercept = a, slope = b), data = df)}
-#' # Switching to geom_blank() gets the desired plot
-#' c <- ggplot(mtcars, aes(x = wt, y = mpg)) + geom_blank()
-#' c + geom_abline(aes(intercept = a, slope = b), data = df)
-geom_blank <- function(mapping = NULL, data = NULL, stat = "identity",
- position = "identity", show.legend = NA,
- inherit.aes = TRUE, ...) {
+geom_blank <- function(mapping = NULL, data = NULL,
+ stat = "identity", position = "identity",
+ ...,
+ show.legend = NA,
+ inherit.aes = TRUE) {
layer(
data = data,
mapping = mapping,
diff --git a/R/geom-boxplot.r b/R/geom-boxplot.r
index f17bc31..8623b3b 100644
--- a/R/geom-boxplot.r
+++ b/R/geom-boxplot.r
@@ -22,12 +22,16 @@
#' @seealso \code{\link{stat_quantile}} to view quantiles conditioned on a
#' continuous variable, \code{\link{geom_jitter}} for another way to look
#' at conditional distributions.
+#' @inheritParams layer
#' @inheritParams geom_point
#' @param geom,stat Use to override the default connection between
#' \code{geom_boxplot} and \code{stat_boxplot}.
-#' @param outlier.colour,outlier.shape,outlier.size,outlier.stroke Default
-#' aesthetics for outliers. Set to \code{NULL} to inherit from the aesthetics
-#' used for the box.
+#' @param outlier.colour,outlier.color,outlier.shape,outlier.size,outlier.stroke
+#' Default aesthetics for outliers. Set to \code{NULL} to inherit from the
+#' aesthetics used for the box.
+#'
+#' In the unlikely event you specify both US and UK spellings of colour, the
+#' US spelling will take precedence.
#' @param notch if \code{FALSE} (default) make a standard box plot. If
#' \code{TRUE}, make a notched box plot. Notches are used to compare groups;
#' if the notches of two boxes do not overlap, this suggests that the medians
@@ -82,12 +86,20 @@
#' stat = "identity"
#' )
#' }
-geom_boxplot <- function(mapping = NULL, data = NULL, stat = "boxplot",
- position = "dodge", outlier.colour = NULL,
- outlier.shape = 19, outlier.size = 1.5,
- outlier.stroke = 0.5, notch = FALSE, notchwidth = 0.5,
- varwidth = FALSE, na.rm = FALSE,
- show.legend = NA, inherit.aes = TRUE, ...) {
+geom_boxplot <- function(mapping = NULL, data = NULL,
+ stat = "boxplot", position = "dodge",
+ ...,
+ outlier.colour = NULL,
+ outlier.color = NULL,
+ outlier.shape = 19,
+ outlier.size = 1.5,
+ outlier.stroke = 0.5,
+ notch = FALSE,
+ notchwidth = 0.5,
+ varwidth = FALSE,
+ na.rm = FALSE,
+ show.legend = NA,
+ inherit.aes = TRUE) {
layer(
data = data,
mapping = mapping,
@@ -97,7 +109,7 @@ geom_boxplot <- function(mapping = NULL, data = NULL, stat = "boxplot",
show.legend = show.legend,
inherit.aes = inherit.aes,
params = list(
- outlier.colour = outlier.colour,
+ outlier.colour = outlier.color %||% outlier.colour,
outlier.shape = outlier.shape,
outlier.size = outlier.size,
outlier.stroke = outlier.stroke,
diff --git a/R/geom-contour.r b/R/geom-contour.r
index 93edb20..31c1c07 100644
--- a/R/geom-contour.r
+++ b/R/geom-contour.r
@@ -3,6 +3,7 @@
#' @section Aesthetics:
#' \Sexpr[results=rd,stage=build]{ggplot2:::rd_aesthetics("geom", "contour")}
#'
+#' @inheritParams layer
#' @inheritParams geom_point
#' @inheritParams geom_path
#' @seealso \code{\link{geom_density_2d}}: 2d density contours
@@ -33,11 +34,15 @@
#' v + geom_raster(aes(fill = density)) +
#' geom_contour(colour = "white")
#' }
-geom_contour <- function(mapping = NULL, data = NULL, stat = "contour",
- position = "identity", lineend = "butt",
- linejoin = "round", linemitre = 1,
- na.rm = FALSE, show.legend = NA,
- inherit.aes = TRUE, ...) {
+geom_contour <- function(mapping = NULL, data = NULL,
+ stat = "contour", position = "identity",
+ ...,
+ lineend = "butt",
+ linejoin = "round",
+ linemitre = 1,
+ na.rm = FALSE,
+ show.legend = NA,
+ inherit.aes = TRUE) {
layer(
data = data,
mapping = mapping,
diff --git a/R/geom-count.r b/R/geom-count.r
index 54b5e0e..a04a6f0 100644
--- a/R/geom-count.r
+++ b/R/geom-count.r
@@ -8,6 +8,7 @@
#' \Sexpr[results=rd,stage=build]{ggplot2:::rd_aesthetics("geom", "point")}
#' @param geom,stat Use to override the default connection between
#' \code{geom_count} and \code{stat_sum}.
+#' @inheritParams layer
#' @inheritParams geom_point
#' @export
#' @examples
@@ -40,9 +41,12 @@
#' scale_size_area(max_size = 10)
#' d + geom_count(aes(size = ..prop.., group = clarity)) +
#' scale_size_area(max_size = 10)
-geom_count <- function(mapping = NULL, data = NULL, stat = "sum",
- position = "identity", na.rm = FALSE,
- show.legend = NA, inherit.aes = TRUE, ...) {
+geom_count <- function(mapping = NULL, data = NULL,
+ stat = "sum", position = "identity",
+ ...,
+ na.rm = FALSE,
+ show.legend = NA,
+ inherit.aes = TRUE) {
layer(
data = data,
mapping = mapping,
diff --git a/R/geom-crossbar.r b/R/geom-crossbar.r
index 381bb94..ba71d6b 100644
--- a/R/geom-crossbar.r
+++ b/R/geom-crossbar.r
@@ -1,8 +1,12 @@
#' @export
#' @rdname geom_linerange
-geom_crossbar <- function(mapping = NULL, data = NULL, stat = "identity",
- position = "identity", fatten = 2.5, na.rm = FALSE,
- show.legend = NA, inherit.aes = TRUE, ...) {
+geom_crossbar <- function(mapping = NULL, data = NULL,
+ stat = "identity", position = "identity",
+ ...,
+ fatten = 2.5,
+ na.rm = FALSE,
+ show.legend = NA,
+ inherit.aes = TRUE) {
layer(
data = data,
mapping = mapping,
diff --git a/R/geom-curve.r b/R/geom-curve.r
index cf3df3d..20124d5 100644
--- a/R/geom-curve.r
+++ b/R/geom-curve.r
@@ -1,10 +1,17 @@
#' @inheritParams grid::curveGrob
#' @export
#' @rdname geom_segment
-geom_curve <- function(mapping = NULL, data = NULL, stat = "identity",
- position = "identity", curvature = 0.5, angle = 90,
- ncp = 5, arrow = NULL, lineend = "butt",
- na.rm = FALSE, show.legend = NA, inherit.aes = TRUE, ...) {
+geom_curve <- function(mapping = NULL, data = NULL,
+ stat = "identity", position = "identity",
+ ...,
+ curvature = 0.5,
+ angle = 90,
+ ncp = 5,
+ arrow = NULL,
+ lineend = "butt",
+ na.rm = FALSE,
+ show.legend = NA,
+ inherit.aes = TRUE) {
layer(
data = data,
mapping = mapping,
diff --git a/R/geom-density.r b/R/geom-density.r
index 01f521c..101dce6 100644
--- a/R/geom-density.r
+++ b/R/geom-density.r
@@ -9,6 +9,7 @@
#' @seealso See \code{\link{geom_histogram}}, \code{\link{geom_freqpoly}} for
#' other methods of displaying continuous distribution.
#' See \code{\link{geom_violin}} for a compact density display.
+#' @inheritParams layer
#' @inheritParams geom_point
#' @param geom,stat Use to override the default connection between
#' \code{geom_density} and \code{stat_density}.
@@ -45,9 +46,12 @@
#' ggplot(diamonds, aes(carat, ..count.., fill = cut)) +
#' geom_density(position = "fill")
#' }
-geom_density <- function(mapping = NULL, data = NULL, stat = "density",
- position = "identity", na.rm = FALSE,
- show.legend = NA, inherit.aes = TRUE, ...) {
+geom_density <- function(mapping = NULL, data = NULL,
+ stat = "density", position = "identity",
+ ...,
+ na.rm = FALSE,
+ show.legend = NA,
+ inherit.aes = TRUE) {
layer(
data = data,
diff --git a/R/geom-density2d.r b/R/geom-density2d.r
index 29dd2ce..66418dd 100644
--- a/R/geom-density2d.r
+++ b/R/geom-density2d.r
@@ -10,6 +10,7 @@
#' \code{\link{stat_sum}} for another way of dealing with overplotting
#' @param geom,stat Use to override the default connection between
#' \code{geom_density_2d} and \code{stat_density_2d}.
+#' @inheritParams layer
#' @inheritParams geom_point
#' @inheritParams geom_path
#' @export
@@ -34,11 +35,15 @@
#' # Or points:
#' d + stat_density_2d(geom = "point", aes(size = ..density..), n = 20, contour = FALSE)
#' }
-geom_density_2d <- function(mapping = NULL, data = NULL, stat = "density2d",
- position = "identity", lineend = "butt",
- linejoin = "round", linemitre = 1,
- na.rm = FALSE, show.legend = NA, inherit.aes = TRUE,
- ...) {
+geom_density_2d <- function(mapping = NULL, data = NULL,
+ stat = "density2d", position = "identity",
+ ...,
+ lineend = "butt",
+ linejoin = "round",
+ linemitre = 1,
+ na.rm = FALSE,
+ show.legend = NA,
+ inherit.aes = TRUE) {
layer(
data = data,
mapping = mapping,
diff --git a/R/geom-dotplot.r b/R/geom-dotplot.r
index eefeef2..9cb0c1c 100644
--- a/R/geom-dotplot.r
+++ b/R/geom-dotplot.r
@@ -19,6 +19,7 @@
#' @section Aesthetics:
#' \Sexpr[results=rd,stage=build]{ggplot2:::rd_aesthetics("geom", "dotplot")}
#'
+#' @inheritParams layer
#' @inheritParams geom_point
#' @param stackdir which direction to stack the dots. "up" (default),
#' "down", "center", "centerwhole" (centered, but with dots aligned)
@@ -112,12 +113,23 @@
#' geom_dotplot(binaxis = "y", stackgroups = TRUE, binwidth = 1, method = "histodot")
#' }
geom_dotplot <- function(mapping = NULL, data = NULL,
- position = "identity", binwidth = NULL, binaxis = "x",
- method = "dotdensity", binpositions = "bygroup",
- stackdir = "up", stackratio = 1, dotsize = 1,
- stackgroups = FALSE, origin = NULL, right = TRUE,
- width = 0.9, drop = FALSE, na.rm = FALSE,
- show.legend = NA, inherit.aes = TRUE, ...) {
+ position = "identity",
+ ...,
+ binwidth = NULL,
+ binaxis = "x",
+ method = "dotdensity",
+ binpositions = "bygroup",
+ stackdir = "up",
+ stackratio = 1,
+ dotsize = 1,
+ stackgroups = FALSE,
+ origin = NULL,
+ right = TRUE,
+ width = 0.9,
+ drop = FALSE,
+ na.rm = FALSE,
+ show.legend = NA,
+ inherit.aes = TRUE) {
# If identical(position, "stack") or position is position_stack(), tell them
# to use stackgroups=TRUE instead. Need to use identical() instead of ==,
# because == will fail if object is position_stack() or position_dodge()
diff --git a/R/geom-errorbar.r b/R/geom-errorbar.r
index f42ec52..0df3ad5 100644
--- a/R/geom-errorbar.r
+++ b/R/geom-errorbar.r
@@ -1,8 +1,11 @@
#' @export
#' @rdname geom_linerange
-geom_errorbar <- function(mapping = NULL, data = NULL, stat = "identity",
- position = "identity", na.rm = FALSE,
- show.legend = NA, inherit.aes = TRUE, ...) {
+geom_errorbar <- function(mapping = NULL, data = NULL,
+ stat = "identity", position = "identity",
+ ...,
+ na.rm = FALSE,
+ show.legend = NA,
+ inherit.aes = TRUE) {
layer(
data = data,
mapping = mapping,
diff --git a/R/geom-errorbarh.r b/R/geom-errorbarh.r
index 2682fcd..06d84eb 100644
--- a/R/geom-errorbarh.r
+++ b/R/geom-errorbarh.r
@@ -4,6 +4,7 @@
#' \Sexpr[results=rd,stage=build]{ggplot2:::rd_aesthetics("geom", "errorbarh")}
#'
#' @seealso \code{\link{geom_errorbar}}: vertical error bars
+#' @inheritParams layer
#' @inheritParams geom_point
#' @export
#' @examples
@@ -21,9 +22,12 @@
#' geom_errorbarh(aes(xmax = resp + se, xmin = resp - se))
#' p + geom_point() +
#' geom_errorbarh(aes(xmax = resp + se, xmin = resp - se, height = .2))
-geom_errorbarh <- function(mapping = NULL, data = NULL, stat = "identity",
- position = "identity", na.rm = FALSE,
- show.legend = NA, inherit.aes = TRUE, ...) {
+geom_errorbarh <- function(mapping = NULL, data = NULL,
+ stat = "identity", position = "identity",
+ ...,
+ na.rm = FALSE,
+ show.legend = NA,
+ inherit.aes = TRUE) {
layer(
data = data,
mapping = mapping,
diff --git a/R/geom-freqpoly.r b/R/geom-freqpoly.r
index 02fd656..bf6f9f3 100644
--- a/R/geom-freqpoly.r
+++ b/R/geom-freqpoly.r
@@ -1,8 +1,17 @@
#' @export
#' @rdname geom_histogram
-geom_freqpoly <- function(mapping = NULL, data = NULL, stat = "bin",
- position = "identity", na.rm = FALSE,
- show.legend = NA, inherit.aes = TRUE, ...) {
+geom_freqpoly <- function(mapping = NULL, data = NULL,
+ stat = "bin", position = "identity",
+ ...,
+ na.rm = FALSE,
+ show.legend = NA,
+ inherit.aes = TRUE) {
+
+ params <- list(na.rm = na.rm, ...)
+ if (identical(stat, "bin")) {
+ params$pad <- TRUE
+ }
+
layer(
data = data,
mapping = mapping,
@@ -11,9 +20,6 @@ geom_freqpoly <- function(mapping = NULL, data = NULL, stat = "bin",
position = position,
show.legend = show.legend,
inherit.aes = inherit.aes,
- params = list(
- na.rm = na.rm,
- ...
- )
+ params = params
)
}
diff --git a/R/geom-hex.r b/R/geom-hex.r
index b3f128b..e8c904f 100644
--- a/R/geom-hex.r
+++ b/R/geom-hex.r
@@ -7,6 +7,7 @@
#' @param geom,stat Override the default connection between \code{geom_hex} and
#' \code{stat_binhex.}
#' @export
+#' @inheritParams layer
#' @inheritParams geom_point
#' @export
#' @examples
@@ -23,9 +24,12 @@
#' d + geom_hex(binwidth = c(1, 1000))
#' d + geom_hex(binwidth = c(.1, 500))
#' }
-geom_hex <- function(mapping = NULL, data = NULL, stat = "binhex",
- position = "identity", na.rm = FALSE,
- show.legend = NA, inherit.aes = TRUE, ...) {
+geom_hex <- function(mapping = NULL, data = NULL,
+ stat = "binhex", position = "identity",
+ ...,
+ na.rm = FALSE,
+ show.legend = NA,
+ inherit.aes = TRUE) {
layer(
data = data,
mapping = mapping,
diff --git a/R/geom-histogram.r b/R/geom-histogram.r
index 90e2028..a6eeaf2 100644
--- a/R/geom-histogram.r
+++ b/R/geom-histogram.r
@@ -13,6 +13,7 @@
#' \code{geom_freqpoly} uses the same aesthetics as \code{geom_line}.
#'
#' @export
+#' @inheritParams layer
#' @inheritParams geom_point
#' @param geom,stat Use to override the default connection between
#' \code{geom_histogram}/\code{geom_freqpoly} and \code{stat_bin}.
@@ -70,10 +71,14 @@
#' m + geom_histogram(binwidth = 0.5) + scale_y_sqrt()
#' }
#' rm(movies)
-geom_histogram <- function(mapping = NULL, data = NULL, stat = "bin",
- binwidth = NULL, bins = NULL, origin = NULL,
- right = FALSE, position = "stack", na.rm = FALSE,
- show.legend = NA, inherit.aes = TRUE, ...) {
+geom_histogram <- function(mapping = NULL, data = NULL,
+ stat = "bin", position = "stack",
+ ...,
+ binwidth = NULL,
+ bins = NULL,
+ na.rm = FALSE,
+ show.legend = NA,
+ inherit.aes = TRUE) {
layer(
data = data,
@@ -86,9 +91,8 @@ geom_histogram <- function(mapping = NULL, data = NULL, stat = "bin",
params = list(
binwidth = binwidth,
bins = bins,
- origin = origin,
- right = right,
na.rm = na.rm,
+ pad = FALSE,
...
)
)
diff --git a/R/geom-hline.r b/R/geom-hline.r
index ba8cec6..2dc7496 100644
--- a/R/geom-hline.r
+++ b/R/geom-hline.r
@@ -6,7 +6,8 @@ NULL
geom_hline <- function(mapping = NULL, data = NULL,
...,
yintercept,
- na.rm = FALSE, show.legend = NA) {
+ na.rm = FALSE,
+ show.legend = NA) {
# Act like an annotation
if (!missing(yintercept)) {
diff --git a/R/geom-jitter.r b/R/geom-jitter.r
index 4dab784..6254b40 100644
--- a/R/geom-jitter.r
+++ b/R/geom-jitter.r
@@ -7,6 +7,7 @@
#' @section Aesthetics:
#' \Sexpr[results=rd,stage=build]{ggplot2:::rd_aesthetics("geom", "point")}
#'
+#' @inheritParams layer
#' @inheritParams geom_point
#' @inheritParams position_jitter
#' @seealso
@@ -30,9 +31,13 @@
#' ggplot(mpg, aes(cty, hwy)) + geom_jitter()
#' ggplot(mpg, aes(cty, hwy)) + geom_jitter(width = 0.5, height = 0.5)
geom_jitter <- function(mapping = NULL, data = NULL,
- width = NULL, height = NULL, stat = "identity",
- position = "jitter", na.rm = FALSE,
- show.legend = NA, inherit.aes = TRUE, ...) {
+ stat = "identity", position = "jitter",
+ ...,
+ width = NULL,
+ height = NULL,
+ na.rm = FALSE,
+ show.legend = NA,
+ inherit.aes = TRUE) {
if (!missing(width) || !missing(height)) {
if (!missing(position)) {
stop("Specify either `position` or `width`/`height`", call. = FALSE)
diff --git a/R/geom-label.R b/R/geom-label.R
index 34260b4..285c827 100644
--- a/R/geom-label.R
+++ b/R/geom-label.R
@@ -3,12 +3,18 @@
#' @param label.padding Amount of padding around label. Defaults to 0.25 lines.
#' @param label.r Radius of rounded corners. Defaults to 0.15 lines.
#' @param label.size Size of label border, in mm.
-geom_label <- function(mapping = NULL, data = NULL, stat = "identity",
- position = "identity", parse = FALSE, ...,
- nudge_x = 0, nudge_y = 0,
+geom_label <- function(mapping = NULL, data = NULL,
+ stat = "identity", position = "identity",
+ ...,
+ parse = FALSE,
+ nudge_x = 0,
+ nudge_y = 0,
label.padding = unit(0.25, "lines"),
- label.r = unit(0.15, "lines"), label.size = 0.25,
- na.rm = FALSE, show.legend = NA, inherit.aes = TRUE) {
+ label.r = unit(0.15, "lines"),
+ label.size = 0.25,
+ na.rm = FALSE,
+ show.legend = NA,
+ inherit.aes = TRUE) {
if (!missing(nudge_x) || !missing(nudge_y)) {
if (!missing(position)) {
stop("Specify either `position` or `nudge_x`/`nudge_y`", call. = FALSE)
diff --git a/R/geom-linerange.r b/R/geom-linerange.r
index f177599..c1a96cf 100644
--- a/R/geom-linerange.r
+++ b/R/geom-linerange.r
@@ -13,6 +13,7 @@
#' \code{\link{stat_summary}} for examples of these guys in use,
#' \code{\link{geom_smooth}} for continuous analog
#' @export
+#' @inheritParams layer
#' @inheritParams geom_point
#' @examples
#' #' # Create a simple example dataset
@@ -48,9 +49,12 @@
#' p +
#' geom_bar(position = dodge, stat = "identity") +
#' geom_errorbar(aes(ymin = lower, ymax = upper), position = dodge, width = 0.25)
-geom_linerange <- function(mapping = NULL, data = NULL, stat = "identity",
- position = "identity", na.rm = FALSE,
- show.legend = NA, inherit.aes = TRUE, ...) {
+geom_linerange <- function(mapping = NULL, data = NULL,
+ stat = "identity", position = "identity",
+ ...,
+ na.rm = FALSE,
+ show.legend = NA,
+ inherit.aes = TRUE) {
layer(
data = data,
mapping = mapping,
diff --git a/R/geom-map.r b/R/geom-map.r
index ce7b394..5256e64 100644
--- a/R/geom-map.r
+++ b/R/geom-map.r
@@ -13,6 +13,7 @@ NULL
#' typically be created using \code{\link{fortify}} on a spatial object.
#' It must contain columns \code{x} or \code{long}, \code{y} or
#' \code{lat}, and \code{region} or \code{id}.
+#' @inheritParams layer
#' @inheritParams geom_point
#' @examples
#' # When using geom_polygon, you will typically need two data frames:
@@ -59,8 +60,13 @@ NULL
#' expand_limits(x = states_map$long, y = states_map$lat) +
#' facet_wrap( ~ variable)
#' }
-geom_map <- function(mapping = NULL, data = NULL, map, stat = "identity",
- na.rm = FALSE, show.legend = NA, inherit.aes = TRUE, ...) {
+geom_map <- function(mapping = NULL, data = NULL,
+ stat = "identity",
+ ...,
+ map,
+ na.rm = FALSE,
+ show.legend = NA,
+ inherit.aes = TRUE) {
# Get map input into correct form
stopifnot(is.data.frame(map))
if (!is.null(map$lat)) map$y <- map$lat
diff --git a/R/geom-path.r b/R/geom-path.r
index 97e91cb..79b4282 100644
--- a/R/geom-path.r
+++ b/R/geom-path.r
@@ -8,6 +8,7 @@
#' @section Aesthetics:
#' \Sexpr[results=rd,stage=build]{ggplot2:::rd_aesthetics("geom", "path")}
#'
+#' @inheritParams layer
#' @inheritParams geom_point
#' @param lineend Line end style (round, butt, square)
#' @param linejoin Line join style (round, mitre, bevel)
@@ -84,10 +85,16 @@
#' # But this doesn't
#' should_stop(p + geom_line(aes(colour = x), linetype=2))
#' }
-geom_path <- function(mapping = NULL, data = NULL, stat = "identity",
- position = "identity", lineend = "butt",
- linejoin = "round", linemitre = 1, na.rm = FALSE,
- arrow = NULL, show.legend = NA, inherit.aes = TRUE, ...) {
+geom_path <- function(mapping = NULL, data = NULL,
+ stat = "identity", position = "identity",
+ ...,
+ lineend = "butt",
+ linejoin = "round",
+ linemitre = 1,
+ arrow = NULL,
+ na.rm = FALSE,
+ show.legend = NA,
+ inherit.aes = TRUE) {
layer(
data = data,
mapping = mapping,
@@ -161,8 +168,9 @@ GeomPath <- ggproto("GeomPath", Geom,
# Work out whether we should use lines or segments
attr <- plyr::ddply(munched, "group", function(df) {
+ linetype <- unique(df$linetype)
data.frame(
- solid = identical(unique(df$linetype), 1),
+ solid = identical(linetype, 1) || identical(linetype, "solid"),
constant = nrow(unique(df[, c("alpha", "colour","size", "linetype")])) == 1
)
})
diff --git a/R/geom-point.r b/R/geom-point.r
index b67fc35..e1eacf6 100644
--- a/R/geom-point.r
+++ b/R/geom-point.r
@@ -29,36 +29,13 @@
#' @seealso \code{\link{scale_size}} to see scale area of points, instead of
#' radius, \code{\link{geom_jitter}} to jitter points to reduce (mild)
#' overplotting
-#' @param mapping Set of aesthetic mappings created by \code{\link{aes}} or
-#' \code{\link{aes_}}. If specified and \code{inherit.aes = TRUE} (the
-#' default), is combined with the default mapping at the top level of the
-#' plot. You only need to supply \code{mapping} if there isn't a mapping
-#' defined for the plot.
-#' @param data A data frame. If specified, overrides the default data frame
-#' defined at the top level of the plot.
-#' @param position Position adjustment, either as a string, or the result of
-#' a call to a position adjustment function.
-#' @param stat The statistical transformation to use on the data for this
-#' layer, as a string.
+#' @inheritParams layer
#' @param na.rm If \code{FALSE} (the default), removes missing values with
#' a warning. If \code{TRUE} silently removes missing values.
-#' @param show.legend logical. Should this layer be included in the legends?
-#' \code{NA}, the default, includes if any aesthetics are mapped.
-#' \code{FALSE} never includes, and \code{TRUE} always includes.
-#' @param inherit.aes If \code{FALSE}, overrides the default aesthetics,
-#' rather than combining with them. This is most useful for helper functions
-#' that define both data and aesthetics and shouldn't inherit behaviour from
-#' the default plot specification, e.g. \code{\link{borders}}.
-#' @param ... other arguments passed on to \code{\link{layer}}. There are
-#' three types of arguments you can use here:
-#'
-#' \itemize{
-#' \item Aesthetics: to set an aesthetic to a fixed value, like
-#' \code{color = "red"} or \code{size = 3}.
-#' \item Other arguments to the layer, for example you override the
-#' default \code{stat} associated with the layer.
-#' \item Other arguments passed on to the stat.
-#' }
+#' @param ... other arguments passed on to \code{\link{layer}}. These are
+#' often aesthetics, used to set an aesthetic to a fixed value, like
+#' \code{color = "red"} or \code{size = 3}. They may also be parameters
+#' to the paired geom/stat.
#' @inheritParams layer
#' @export
#' @examples
@@ -113,9 +90,12 @@
#' ggplot(mtcars2, aes(wt, mpg)) + geom_point()
#' ggplot(mtcars2, aes(wt, mpg)) + geom_point(na.rm = TRUE)
#' }
-geom_point <- function(mapping = NULL, data = NULL, stat = "identity",
- position = "identity", na.rm = FALSE,
- show.legend = NA, inherit.aes = TRUE, ...) {
+geom_point <- function(mapping = NULL, data = NULL,
+ stat = "identity", position = "identity",
+ ...,
+ na.rm = FALSE,
+ show.legend = NA,
+ inherit.aes = TRUE) {
layer(
data = data,
mapping = mapping,
diff --git a/R/geom-pointrange.r b/R/geom-pointrange.r
index c1b9156..32c706a 100644
--- a/R/geom-pointrange.r
+++ b/R/geom-pointrange.r
@@ -1,8 +1,12 @@
#' @export
#' @rdname geom_linerange
-geom_pointrange <- function(mapping = NULL, data = NULL, stat = "identity",
- position = "identity", ..., fatten = 4,
- na.rm = FALSE, show.legend = NA, inherit.aes = TRUE) {
+geom_pointrange <- function(mapping = NULL, data = NULL,
+ stat = "identity", position = "identity",
+ ...,
+ fatten = 4,
+ na.rm = FALSE,
+ show.legend = NA,
+ inherit.aes = TRUE) {
layer(
data = data,
mapping = mapping,
diff --git a/R/geom-polygon.r b/R/geom-polygon.r
index be41e0e..794e3dc 100644
--- a/R/geom-polygon.r
+++ b/R/geom-polygon.r
@@ -7,6 +7,7 @@
#' \code{\link{geom_path}} for an unfilled polygon,
#' \code{\link{geom_ribbon}} for a polygon anchored on the x-axis
#' @export
+#' @inheritParams layer
#' @inheritParams geom_point
#' @examples
#' # When using geom_polygon, you will typically need two data frames:
@@ -46,9 +47,12 @@
#'
#' # And if the positions are in longitude and latitude, you can use
#' # coord_map to produce different map projections.
-geom_polygon <- function(mapping = NULL, data = NULL, stat = "identity",
- position = "identity", na.rm = FALSE, show.legend = NA,
- inherit.aes = TRUE, ...) {
+geom_polygon <- function(mapping = NULL, data = NULL,
+ stat = "identity", position = "identity",
+ ...,
+ na.rm = FALSE,
+ show.legend = NA,
+ inherit.aes = TRUE) {
layer(
data = data,
mapping = mapping,
@@ -87,7 +91,7 @@ GeomPolygon <- ggproto("GeomPolygon", Geom,
polygonGrob(munched$x, munched$y, default.units = "native",
id = munched$group,
gp = gpar(
- col = alpha(first_rows$colour, first_rows$alpha),
+ col = first_rows$colour,
fill = alpha(first_rows$fill, first_rows$alpha),
lwd = first_rows$size * .pt,
lty = first_rows$linetype
diff --git a/R/geom-quantile.r b/R/geom-quantile.r
index c957030..cc18c69 100644
--- a/R/geom-quantile.r
+++ b/R/geom-quantile.r
@@ -6,6 +6,7 @@
#' \Sexpr[results=rd,stage=build]{ggplot2:::rd_aesthetics("geom", "quantile")}
#'
#' @export
+#' @inheritParams layer
#' @inheritParams geom_point
#' @inheritParams geom_path
#' @param method.args List of additional arguments passed on to the modelling
@@ -27,10 +28,15 @@
#'
#' # Set aesthetics to fixed value
#' m + geom_quantile(colour = "red", size = 2, alpha = 0.5)
-geom_quantile <- function(mapping = NULL, data = NULL, stat = "quantile",
- position = "identity", lineend = "butt",
- linejoin = "round", linemitre = 1,
- na.rm = FALSE, show.legend = NA, inherit.aes = TRUE, ...) {
+geom_quantile <- function(mapping = NULL, data = NULL,
+ stat = "quantile", position = "identity",
+ ...,
+ lineend = "butt",
+ linejoin = "round",
+ linemitre = 1,
+ na.rm = FALSE,
+ show.legend = NA,
+ inherit.aes = TRUE) {
layer(
data = data,
diff --git a/R/geom-raster.r b/R/geom-raster.r
index 431a41a..d13d752 100644
--- a/R/geom-raster.r
+++ b/R/geom-raster.r
@@ -8,10 +8,15 @@ NULL
#' for both, centering each pixel over its data location.
#' @param interpolate If \code{TRUE} interpolate linearly, if \code{FALSE}
#' (the default) don't interpolate.
-geom_raster <- function(mapping = NULL, data = NULL, stat = "identity",
- position = "identity", hjust = 0.5, vjust = 0.5,
- interpolate = FALSE, na.rm = FALSE,
- show.legend = NA, inherit.aes = TRUE, ...)
+geom_raster <- function(mapping = NULL, data = NULL,
+ stat = "identity", position = "identity",
+ ...,
+ hjust = 0.5,
+ vjust = 0.5,
+ interpolate = FALSE,
+ na.rm = FALSE,
+ show.legend = NA,
+ inherit.aes = TRUE)
{
stopifnot(is.numeric(hjust), length(hjust) == 1)
stopifnot(is.numeric(vjust), length(vjust) == 1)
diff --git a/R/geom-rect.r b/R/geom-rect.r
index ef41546..863d2ab 100644
--- a/R/geom-rect.r
+++ b/R/geom-rect.r
@@ -1,8 +1,11 @@
#' @export
#' @rdname geom_tile
-geom_rect <- function(mapping = NULL, data = NULL, stat = "identity",
- position = "identity", na.rm = FALSE,
- show.legend = NA, inherit.aes = TRUE, ...) {
+geom_rect <- function(mapping = NULL, data = NULL,
+ stat = "identity", position = "identity",
+ ...,
+ na.rm = FALSE,
+ show.legend = NA,
+ inherit.aes = TRUE) {
layer(
data = data,
mapping = mapping,
@@ -52,7 +55,7 @@ GeomRect <- ggproto("GeomRect", Geom,
default.units = "native",
just = c("left", "top"),
gp = gpar(
- col = alpha(coords$colour, coords$alpha),
+ col = coords$colour,
fill = alpha(coords$fill, coords$alpha),
lwd = coords$size * .pt,
lty = coords$linetype,
diff --git a/R/geom-ribbon.r b/R/geom-ribbon.r
index e7f81bc..54a946f 100644
--- a/R/geom-ribbon.r
+++ b/R/geom-ribbon.r
@@ -17,6 +17,7 @@
#' \code{\link{geom_bar}} for discrete intervals (bars),
#' \code{\link{geom_linerange}} for discrete intervals (lines),
#' \code{\link{geom_polygon}} for general polygons
+#' @inheritParams layer
#' @inheritParams geom_point
#' @export
#' @examples
@@ -31,9 +32,12 @@
#' h +
#' geom_ribbon(aes(ymin = level - 1, ymax = level + 1), fill = "grey70") +
#' geom_line(aes(y = level))
-geom_ribbon <- function(mapping = NULL, data = NULL, stat = "identity",
- position = "identity", na.rm = FALSE, show.legend = NA,
- inherit.aes = TRUE, ...) {
+geom_ribbon <- function(mapping = NULL, data = NULL,
+ stat = "identity", position = "identity",
+ ...,
+ na.rm = FALSE,
+ show.legend = NA,
+ inherit.aes = TRUE) {
layer(
data = data,
mapping = mapping,
@@ -61,6 +65,10 @@ GeomRibbon <- ggproto("GeomRibbon", Geom,
draw_key = draw_key_polygon,
+ handle_na = function(data, params) {
+ data
+ },
+
draw_group = function(data, panel_scales, coord, na.rm = FALSE) {
if (na.rm) data <- data[stats::complete.cases(data[c("x", "ymin", "ymax")]), ]
data <- data[order(data$group, data$x), ]
@@ -92,7 +100,7 @@ GeomRibbon <- ggproto("GeomRibbon", Geom,
default.units = "native",
gp = gpar(
fill = alpha(aes$fill, aes$alpha),
- col = alpha(aes$colour, aes$alpha),
+ col = aes$colour,
lwd = aes$size * .pt,
lty = aes$linetype)
))
diff --git a/R/geom-rug.r b/R/geom-rug.r
index dada4e6..eebe6c7 100644
--- a/R/geom-rug.r
+++ b/R/geom-rug.r
@@ -3,6 +3,7 @@
#' @section Aesthetics:
#' \Sexpr[results=rd,stage=build]{ggplot2:::rd_aesthetics("geom", "rug")}
#'
+#' @inheritParams layer
#' @inheritParams geom_point
#' @param sides A string that controls which sides of the plot the rugs appear on.
#' It can be set to a string containing any of \code{"trbl"}, for top, right,
@@ -15,9 +16,13 @@
#' p + geom_point() + geom_rug(sides="b") # Rug on bottom only
#' p + geom_point() + geom_rug(sides="trbl") # All four sides
#' p + geom_point() + geom_rug(position='jitter')
-geom_rug <- function(mapping = NULL, data = NULL, stat = "identity",
- position = "identity", sides = "bl",
- na.rm = FALSE, show.legend = NA, inherit.aes = TRUE, ...) {
+geom_rug <- function(mapping = NULL, data = NULL,
+ stat = "identity", position = "identity",
+ ...,
+ sides = "bl",
+ na.rm = FALSE,
+ show.legend = NA,
+ inherit.aes = TRUE) {
layer(
data = data,
mapping = mapping,
diff --git a/R/geom-segment.r b/R/geom-segment.r
index adc1247..a8e04b2 100644
--- a/R/geom-segment.r
+++ b/R/geom-segment.r
@@ -6,6 +6,7 @@
#' @section Aesthetics:
#' \Sexpr[results=rd,stage=build]{ggplot2:::rd_aesthetics("geom", "segment")}
#'
+#' @inheritParams layer
#' @inheritParams geom_point
#' @param arrow specification for arrow heads, as created by arrow()
#' @param lineend Line end style (round, butt, square)
@@ -43,10 +44,14 @@
#'
#' ggplot(counts, aes(x, Freq)) +
#' geom_segment(aes(xend = x, yend = 0), size = 10, lineend = "butt")
-geom_segment <- function(mapping = NULL, data = NULL, stat = "identity",
- position = "identity", arrow = NULL, lineend = "butt",
- na.rm = FALSE, show.legend = NA, inherit.aes = TRUE,
- ...) {
+geom_segment <- function(mapping = NULL, data = NULL,
+ stat = "identity", position = "identity",
+ ...,
+ arrow = NULL,
+ lineend = "butt",
+ na.rm = FALSE,
+ show.legend = NA,
+ inherit.aes = TRUE) {
layer(
data = data,
mapping = mapping,
diff --git a/R/geom-smooth.r b/R/geom-smooth.r
index bce8461..04a4e65 100644
--- a/R/geom-smooth.r
+++ b/R/geom-smooth.r
@@ -15,6 +15,7 @@
#' @section Aesthetics:
#' \Sexpr[results=rd,stage=build]{ggplot2:::rd_aesthetics("geom", "smooth")}
#'
+#' @inheritParams layer
#' @inheritParams geom_point
#' @param geom,stat Use to override the default connection between
#' \code{geom_smooth} and \code{stat_smooth}.
@@ -55,13 +56,12 @@
#' geom_smooth(span = 0.8) +
#' facet_wrap(~drv)
#'
-#' \dontrun{
-#' # To fit a logistic regression, you need to coerce the values to
-#' # a numeric vector lying between 0 and 1.
+#' \donttest{
#' binomial_smooth <- function(...) {
#' geom_smooth(method = "glm", method.args = list(family = "binomial"), ...)
#' }
-#'
+#' # To fit a logistic regression, you need to coerce the values to
+#' # a numeric vector lying between 0 and 1.
#' ggplot(rpart::kyphosis, aes(Age, Kyphosis)) +
#' geom_jitter(height = 0.05) +
#' binomial_smooth()
@@ -77,10 +77,15 @@
#' # But in this case, it's probably better to fit the model yourself
#' # so you can exercise more control and see whether or not it's a good model
#' }
-geom_smooth <- function(mapping = NULL, data = NULL, stat = "smooth",
- method = "auto", formula = y ~ x, se = TRUE,
- position = "identity", na.rm = FALSE,
- show.legend = NA, inherit.aes = TRUE, ...) {
+geom_smooth <- function(mapping = NULL, data = NULL,
+ stat = "smooth", position = "identity",
+ ...,
+ method = "auto",
+ formula = y ~ x,
+ se = TRUE,
+ na.rm = FALSE,
+ show.legend = NA,
+ inherit.aes = TRUE) {
params <- list(
na.rm = na.rm,
diff --git a/R/geom-spoke.r b/R/geom-spoke.r
index 3c3bdd3..6c17911 100644
--- a/R/geom-spoke.r
+++ b/R/geom-spoke.r
@@ -3,6 +3,7 @@
#' @section Aesthetics:
#' \Sexpr[results=rd,stage=build]{ggplot2:::rd_aesthetics("geom", "spoke")}
#'
+#' @inheritParams layer
#' @inheritParams geom_segment
#' @export
#' @examples
@@ -17,9 +18,12 @@
#' ggplot(df, aes(x, y)) +
#' geom_point() +
#' geom_spoke(aes(angle = angle, radius = speed))
-geom_spoke <- function(mapping = NULL, data = NULL, stat = "identity",
- position = "identity", na.rm = FALSE,
- show.legend = NA, inherit.aes = TRUE, ...) {
+geom_spoke <- function(mapping = NULL, data = NULL,
+ stat = "identity", position = "identity",
+ ...,
+ na.rm = FALSE,
+ show.legend = NA,
+ inherit.aes = TRUE) {
layer(
data = data,
mapping = mapping,
diff --git a/R/geom-text.r b/R/geom-text.r
index 679040c..84d1189 100644
--- a/R/geom-text.r
+++ b/R/geom-text.r
@@ -26,6 +26,7 @@
#' Inward always aligns text towards the center, and outward aligns
#' it away from the center
#'
+#' @inheritParams layer
#' @inheritParams geom_point
#' @param parse If TRUE, the labels will be parsed into expressions and
#' displayed as described in ?plotmath
@@ -50,6 +51,7 @@
#' p + geom_point() + geom_text(vjust = 0, nudge_y = 0.5)
#' p + geom_point() + geom_text(angle = 45)
#' \dontrun{
+#' # Doesn't work on all systems
#' p + geom_text(family = "Times New Roman")
#' }
#'
@@ -115,10 +117,16 @@
#' ggplot(df, aes(x, y)) +
#' geom_text(aes(label = text), vjust = "inward", hjust = "inward")
#' }
-geom_text <- function(mapping = NULL, data = NULL, stat = "identity",
- position = "identity", parse = FALSE, ...,
- nudge_x = 0, nudge_y = 0, check_overlap = FALSE,
- na.rm = FALSE, show.legend = NA, inherit.aes = TRUE)
+geom_text <- function(mapping = NULL, data = NULL,
+ stat = "identity", position = "identity",
+ ...,
+ parse = FALSE,
+ nudge_x = 0,
+ nudge_y = 0,
+ check_overlap = FALSE,
+ na.rm = FALSE,
+ show.legend = NA,
+ inherit.aes = TRUE)
{
if (!missing(nudge_x) || !missing(nudge_y)) {
if (!missing(position)) {
diff --git a/R/geom-tile.r b/R/geom-tile.r
index 94d5e51..dc188ff 100644
--- a/R/geom-tile.r
+++ b/R/geom-tile.r
@@ -10,6 +10,7 @@
#' @section Aesthetics:
#' \Sexpr[results=rd,stage=build]{ggplot2:::rd_aesthetics("geom", "tile")}
#'
+#' @inheritParams layer
#' @inheritParams geom_point
#' @export
#' @examples
@@ -55,9 +56,12 @@
#' cars + stat_density(aes(fill = ..density..), geom = "raster", position = "identity")
#' cars + stat_density(aes(fill = ..count..), geom = "raster", position = "identity")
#' }
-geom_tile <- function(mapping = NULL, data = NULL, stat = "identity",
- position = "identity", na.rm = FALSE,
- show.legend = NA, inherit.aes = TRUE, ...) {
+geom_tile <- function(mapping = NULL, data = NULL,
+ stat = "identity", position = "identity",
+ ...,
+ na.rm = FALSE,
+ show.legend = NA,
+ inherit.aes = TRUE) {
layer(
data = data,
mapping = mapping,
@@ -79,6 +83,8 @@ geom_tile <- function(mapping = NULL, data = NULL, stat = "identity",
#' @export
#' @include geom-rect.r
GeomTile <- ggproto("GeomTile", GeomRect,
+ extra_params = c("na.rm", "width", "height"),
+
setup_data = function(data, params) {
data$width <- data$width %||% params$width %||% resolution(data$x, FALSE)
data$height <- data$height %||% params$height %||% resolution(data$y, FALSE)
@@ -94,5 +100,5 @@ GeomTile <- ggproto("GeomTile", GeomRect,
required_aes = c("x", "y"),
- draw_key = draw_key_rect
+ draw_key = draw_key_polygon
)
diff --git a/R/geom-violin.r b/R/geom-violin.r
index 0a84d92..e1446d6 100644
--- a/R/geom-violin.r
+++ b/R/geom-violin.r
@@ -3,6 +3,7 @@
#' @section Aesthetics:
#' \Sexpr[results=rd,stage=build]{ggplot2:::rd_aesthetics("geom", "violin")}
#'
+#' @inheritParams layer
#' @inheritParams geom_point
#' @param draw_quantiles If \code{not(NULL)} (default), draw horizontal lines
#' at the given quantiles of the density estimate.
@@ -65,11 +66,15 @@
#' geom_violin(aes(group = cut_width(year, 10)), scale = "width")
#' }
#' }
-geom_violin <- function(mapping = NULL, data = NULL, stat = "ydensity",
- draw_quantiles = NULL, position = "dodge",
- trim = TRUE, scale = "area",
- na.rm = FALSE, show.legend = NA, inherit.aes = TRUE,
- ...) {
+geom_violin <- function(mapping = NULL, data = NULL,
+ stat = "ydensity", position = "dodge",
+ ...,
+ draw_quantiles = NULL,
+ trim = TRUE,
+ scale = "area",
+ na.rm = FALSE,
+ show.legend = NA,
+ inherit.aes = TRUE) {
layer(
data = data,
mapping = mapping,
diff --git a/R/geom-vline.r b/R/geom-vline.r
index 27afdc6..5d12804 100644
--- a/R/geom-vline.r
+++ b/R/geom-vline.r
@@ -6,7 +6,8 @@ NULL
geom_vline <- function(mapping = NULL, data = NULL,
...,
xintercept,
- na.rm = FALSE, show.legend = NA) {
+ na.rm = FALSE,
+ show.legend = NA) {
# Act like an annotation
if (!missing(xintercept)) {
diff --git a/R/ggproto.r b/R/ggproto.r
index 903d2d2..4168907 100644
--- a/R/ggproto.r
+++ b/R/ggproto.r
@@ -36,7 +36,12 @@ ggproto <- function(`_class` = NULL, `_inherit` = NULL, ...) {
if (length(members) != sum(nzchar(names(members)))) {
stop("All members of a ggproto object must be named.")
}
- list2env(members, envir = e)
+
+ # R <3.1.2 will error when list2env() is given an empty list, so we need to
+ # check length. https://github.com/hadley/ggplot2/issues/1444
+ if (length(members) > 0) {
+ list2env(members, envir = e)
+ }
if (!is.null(`_inherit`)) {
if (!is.ggproto(`_inherit`)) {
diff --git a/R/guide-legend.r b/R/guide-legend.r
index 7f33b08..bee2208 100644
--- a/R/guide-legend.r
+++ b/R/guide-legend.r
@@ -72,7 +72,6 @@
#' p1 + scale_fill_continuous(guide = guide_legend())
#'
#' # Guide title
-#'
#' p1 + scale_fill_continuous(guide = guide_legend(title = "V")) # title text
#' p1 + scale_fill_continuous(guide = guide_legend(title = NULL)) # no title
#'
@@ -85,24 +84,38 @@
#' p1 + guides(fill = guide_legend(title = "LEFT", title.position = "left"))
#'
#' # title text styles via element_text
-#' p1 + guides(fill = guide_legend(
-#' title.theme = element_text(size=15, face="italic", colour = "red", angle = 45)))
+#' p1 + guides(fill =
+#' guide_legend(
+#' title.theme = element_text(
+#' size = 15,
+#' face = "italic",
+#' colour = "red",
+#' angle = 0
+#' )
+#' )
+#' )
#'
#' # label position
-#' p1 + guides(fill = guide_legend(label.position = "bottom"))
+#' p1 + guides(fill = guide_legend(label.position = "left", label.hjust = 1))
#'
#' # label styles
#' p1 + scale_fill_continuous(breaks = c(5, 10, 15),
#' labels = paste("long", c(5, 10, 15)),
-#' guide = guide_legend(direction = "horizontal", title.position = "top",
-#' label.position="bottom", label.hjust = 0.5, label.vjust = 0.5,
-#' label.theme = element_text(angle = 90)))
+#' guide = guide_legend(
+#' direction = "horizontal",
+#' title.position = "top",
+#' label.position = "bottom",
+#' label.hjust = 0.5,
+#' label.vjust = 1,
+#' label.theme = element_text(angle = 90)
+#' )
+#' )
#'
#' # Set aesthetic of legend key
#'
#' # very low alpha value make it difficult to see legend key
#' p3 <- ggplot(diamonds, aes(carat, price)) +
-#' geom_point(aes(colour=color), alpha=1/100)
+#' geom_point(aes(colour = color), alpha = 1/100)
#' p3
#'
#' # override.aes overwrites the alpha
@@ -300,7 +313,9 @@ guide_gengrob.legend <- function(guide, theme) {
guide$title.theme %||% calc_element("legend.title", theme),
label = guide$title,
hjust = guide$title.hjust %||% theme$legend.title.align %||% 0,
- vjust = guide$title.vjust %||% 0.5
+ vjust = guide$title.vjust %||% 0.5,
+ expand_x = FALSE,
+ expand_y = FALSE
)
)
@@ -320,8 +335,16 @@ guide_gengrob.legend <- function(guide, theme) {
vjust <- y <- guide$label.vjust %||% 0.5
grob.labels <- lapply(guide$key$.label, function(label, ...) {
- g <- element_grob(element = label.theme, label = label,
- x = x, y = y, hjust = hjust, vjust = vjust)
+ g <- element_grob(
+ element = label.theme,
+ label = label,
+ x = x,
+ y = y,
+ hjust = hjust,
+ vjust = vjust,
+ expand_x = FALSE,
+ expand_y = FALSE
+ )
ggname("guide.label", g)
})
}
diff --git a/R/hexbin.R b/R/hexbin.R
new file mode 100644
index 0000000..804c10e
--- /dev/null
+++ b/R/hexbin.R
@@ -0,0 +1,38 @@
+hex_binwidth <- function(bins = 30, scales) {
+ c(
+ diff(scales$x$dimension()) / bins,
+ diff(scales$y$dimension()) / bins
+ )
+}
+
+hex_bounds <- function(x, binwidth) {
+ c(
+ plyr::round_any(min(x), binwidth, floor) - 1e-6,
+ plyr::round_any(max(x), binwidth, ceiling) + 1e-6
+ )
+}
+
+hexBinSummarise <- function(x, y, z, binwidth, fun = mean, fun.args = list(), drop = TRUE) {
+ # Convert binwidths into bounds + nbins
+ xbnds <- hex_bounds(x, binwidth[1])
+ xbins <- diff(xbnds) / binwidth[1]
+
+ ybnds <- hex_bounds(y, binwidth[2])
+ ybins <- diff(ybnds) / binwidth[2]
+
+ # Call hexbin
+ hb <- hexbin::hexbin(
+ x, xbnds = xbnds, xbins = xbins,
+ y, ybnds = ybnds, shape = ybins / xbins,
+ IDs = TRUE
+ )
+
+ value <- do.call(tapply, c(list(quote(z), quote(hb at cID), quote(fun)), fun.args))
+
+ # Convert to data frame
+ out <- as.data.frame(hexbin::hcell2xy(hb))
+ out$value <- as.vector(value)
+
+ if (drop) out <- stats::na.omit(out)
+ out
+}
diff --git a/R/labels.r b/R/labels.r
index 6398cd3..1808993 100644
--- a/R/labels.r
+++ b/R/labels.r
@@ -68,5 +68,13 @@ make_labels <- function(mapping) {
gsub(match_calculated_aes, "\\1", x)
}
- lapply(mapping, function(x) remove_dots(deparse(x)))
+ default_label <- function(aesthetic, mapping) {
+ # e.g., geom_smooth(aes(colour = "loess"))
+ if (is.character(mapping)) {
+ aesthetic
+ } else {
+ remove_dots(deparse(mapping))
+ }
+ }
+ Map(default_label, names(mapping), mapping)
}
diff --git a/R/layer.r b/R/layer.r
index 7e522a1..125557c 100644
--- a/R/layer.r
+++ b/R/layer.r
@@ -1,10 +1,40 @@
#' Create a new layer
#'
+#' A layer is a combination of data, stat and geom with a potential position
+#' adjustment. Usually layers are created using \code{geom_*} or \code{stat_*}
+#' calls but it can also be created directly using this function.
+#'
#' @export
#' @inheritParams geom_point
-#' @param geom,stat,position Geom, stat and position adjustment to use in
-#' this layer. Can either be the name of a ggproto object, or the object
-#' itself.
+#' @param mapping Set of aesthetic mappings created by \code{\link{aes}} or
+#' \code{\link{aes_}}. If specified and \code{inherit.aes = TRUE} (the
+#' default), it is combined with the default mapping at the top level of the
+#' plot. You must supply \code{mapping} if there is no plot mapping.
+#' @param data The data to be displayed in this layer. There are three
+#' options:
+#'
+#' If \code{NULL}, the default, the data is inherited from the plot
+#' data as specified in the call to \code{\link{ggplot}}.
+#'
+#' A \code{data.frame}, or other object, will override the plot
+#' data. All objects will be fortified to produce a data frame. See
+#' \code{\link{fortify}} for which variables will be created.
+#'
+#' A \code{function} will be called with a single argument,
+#' the plot data. The return value must be a \code{data.frame.}, and
+#' will be used as the layer data.
+#' @param geom The geometric object to use display the data
+#' @param stat The statistical transformation to use on the data for this
+#' layer, as a string.
+#' @param position Position adjustment, either as a string, or the result of
+#' a call to a position adjustment function.
+#' @param show.legend logical. Should this layer be included in the legends?
+#' \code{NA}, the default, includes if any aesthetics are mapped.
+#' \code{FALSE} never includes, and \code{TRUE} always includes.
+#' @param inherit.aes If \code{FALSE}, overrides the default aesthetics,
+#' rather than combining with them. This is most useful for helper functions
+#' that define both data and aesthetics and shouldn't inherit behaviour from
+#' the default plot specification, e.g. \code{\link{borders}}.
#' @param params Additional parameters to the \code{geom} and \code{stat}.
#' @param subset DEPRECATED. An older way of subsetting the dataset used in a
#' layer.
@@ -16,6 +46,13 @@
#' layer(geom = "point", stat = "identity", position = "identity",
#' params = list(na.rm = FALSE)
#' )
+#'
+#' # use a function as data to plot a subset of global data
+#' ggplot(mpg, aes(displ, hwy)) +
+#' layer(geom = "point", stat = "identity", position = "identity",
+#' data = head, params = list(na.rm = FALSE)
+#' )
+#'
layer <- function(geom = NULL, stat = NULL,
data = NULL, mapping = NULL,
position = NULL, params = list(),
@@ -51,9 +88,13 @@ layer <- function(geom = NULL, stat = NULL,
if (is.character(position))
position <- find_subclass("Position", position)
+ # Special case for na.rm parameter needed by all layers
+ if (is.null(params$na.rm)) {
+ params$na.rm <- FALSE
+ }
+
# Split up params between aesthetics, geom, and stat
params <- rename_aes(params)
-
aes_params <- params[intersect(names(params), geom$aesthetics())]
geom_params <- params[intersect(names(params), geom$parameters(TRUE))]
stat_params <- params[intersect(names(params), stat$parameters(TRUE))]
@@ -101,6 +142,20 @@ Layer <- ggproto("Layer", NULL,
cat(snakeize(class(self$position)[[1]]), "\n")
},
+ layer_data = function(self, plot_data) {
+ if (is.waive(self$data)) {
+ plot_data
+ } else if (is.function(self$data)) {
+ data <- self$data(plot_data)
+ if (!is.data.frame(data)) {
+ stop("Data function must return a data.frame", call. = FALSE)
+ }
+ data
+ } else {
+ self$data
+ }
+ },
+
compute_aesthetics = function(self, data, plot) {
# For annotation geoms, it is useful to be able to ignore the default aes
if (self$inherit.aes) {
@@ -134,7 +189,11 @@ Layer <- ggproto("Layer", NULL,
n <- nrow(data)
if (n == 0) {
# No data, so look at longest evaluated aesthetic
- n <- max(vapply(evaled, length, integer(1)))
+ if (length(evaled) == 0) {
+ n <- 0
+ } else {
+ n <- max(vapply(evaled, length, integer(1)))
+ }
}
check_aesthetics(evaled, n)
@@ -144,6 +203,7 @@ Layer <- ggproto("Layer", NULL,
} else {
evaled$PANEL <- data$PANEL
}
+ evaled <- lapply(evaled, unname)
evaled <- data.frame(evaled, stringsAsFactors = FALSE)
evaled <- add_group(evaled)
evaled
diff --git a/R/margins.R b/R/margins.R
index 967b272..837f964 100644
--- a/R/margins.R
+++ b/R/margins.R
@@ -1,10 +1,10 @@
#' Define margins.
#'
-#' This is a convenience function that creates a grid unit object of the
+#' This is a convenient function that creates a grid unit object of the
#' correct length to use for setting margins.
#'
#' @export
-#' @param t,b,r,l Dimensions of each margin. (To remember order, think trouble).
+#' @param t,r,b,l Dimensions of each margin. (To remember order, think trouble).
#' @param unit Default units of dimensions. Defaults to "pt" so it
#' can be most easily scaled with the text.
#' @export
diff --git a/R/panel.r b/R/panel.r
index e147464..1cbf451 100644
--- a/R/panel.r
+++ b/R/panel.r
@@ -45,10 +45,8 @@ train_layout <- function(panel, facet, data, plot_data) {
# @param panel a trained panel object
# @param the facetting specification
# @param data list of data frames (one for each layer)
-# @param plot_data default plot data frame
-map_layout <- function(panel, facet, data, plot_data) {
+map_layout <- function(panel, facet, data) {
lapply(data, function(data) {
- if (is.waive(data)) data <- plot_data
facet_map_layout(facet, data, panel$layout)
})
}
diff --git a/R/plot-build.r b/R/plot-build.r
index d4ef2a2..17185b0 100644
--- a/R/plot-build.r
+++ b/R/plot-build.r
@@ -22,7 +22,7 @@ ggplot_build <- function(plot) {
}
layers <- plot$layers
- layer_data <- lapply(layers, function(y) y$data)
+ layer_data <- lapply(layers, function(y) y$layer_data(plot$data))
scales <- plot$scales
# Apply function to layer and matching data
@@ -39,7 +39,7 @@ ggplot_build <- function(plot) {
panel <- new_panel()
panel <- train_layout(panel, plot$facet, layer_data, plot$data)
- data <- map_layout(panel, plot$facet, layer_data, plot$data)
+ data <- map_layout(panel, plot$facet, layer_data)
# Compute aesthetics to produce data with generalised variable names
data <- by_layer(function(l, d) l$compute_aesthetics(d, plot))
diff --git a/R/plot-construction.r b/R/plot-construction.r
index af1015e..dc10caf 100644
--- a/R/plot-construction.r
+++ b/R/plot-construction.r
@@ -1,4 +1,4 @@
-#' Modify a ggplot or theme object by adding on new components.
+#' Add a new component to a ggplot or theme object.
#'
#' This operator allows you to add objects to a ggplot or theme object.
#'
diff --git a/R/plot.r b/R/plot.r
index 3a066ca..e3ad241 100644
--- a/R/plot.r
+++ b/R/plot.r
@@ -90,7 +90,7 @@ ggplot.default <- function(data = NULL, mapping = aes(), ...,
ggplot.data.frame <- function(data, mapping = aes(), ...,
environment = parent.frame()) {
if (!missing(mapping) && !inherits(mapping, "uneval")) {
- stop("Mapping should be created with aes or aes_string")
+ stop("Mapping should be created with `aes() or `aes_()`.", call. = FALSE)
}
p <- structure(list(
diff --git a/R/position-jitterdodge.R b/R/position-jitterdodge.R
index b65be70..f87ce4c 100644
--- a/R/position-jitterdodge.R
+++ b/R/position-jitterdodge.R
@@ -35,17 +35,22 @@ PositionJitterdodge <- ggproto("PositionJitterdodge", Position,
jitter.height = NULL,
dodge.width = NULL,
- required_aes = c("x", "y", "fill"),
+ required_aes = c("x", "y"),
setup_params = function(self, data) {
width <- self$jitter.width %||% resolution(data$x, zero = FALSE) * 0.4
- # Adjust the x transformation based on the number of 'fill' variables
- nfill <- length(levels(data$fill))
-
+ # Adjust the x transformation based on the number of 'dodge' variables
+ dodgecols <- intersect(c("fill", "colour", "linetype", "shape", "size", "alpha"), colnames(data))
+ if (length(dodgecols) == 0) {
+ stop("`position_jitterdodge()` requires at least one aesthetic to dodge by", call. = FALSE)
+ }
+ ndodge <- lapply(data[dodgecols], levels) # returns NULL for numeric, i.e. non-dodge layers
+ ndodge <- length(unique(unlist(ndodge)))
+
list(
dodge.width = self$dodge.width,
jitter.height = self$jitter.height,
- jitter.width = width / (nfill + 2)
+ jitter.width = width / (ndodge + 2)
)
},
diff --git a/R/position-nudge.R b/R/position-nudge.R
index a77920c..1ed8e9e 100644
--- a/R/position-nudge.R
+++ b/R/position-nudge.R
@@ -31,8 +31,8 @@ position_nudge <- function(x = 0, y = 0) {
#' @usage NULL
#' @export
PositionNudge <- ggproto("PositionNudge", Position,
- x = NULL,
- y = NULL,
+ x = 0,
+ y = 0,
required_aes = c("x", "y"),
diff --git a/R/save.r b/R/save.r
index 70adca2..c7139b7 100644
--- a/R/save.r
+++ b/R/save.r
@@ -104,7 +104,7 @@ plot_dev <- function(device, filename, dpi = 300) {
ps = eps,
tex = function(...) grDevices::pictex(...),
pdf = function(..., version = "1.4") grDevices::pdf(..., version = version),
- svg = function(...) grDevices::svg(...),
+ svg = function(...) svglite::svglite(...),
emf = function(...) grDevices::win.metafile(...),
wmf = function(...) grDevices::win.metafile(...),
png = function(...) grDevices::png(..., res = dpi, units = "in"),
diff --git a/R/scale-.r b/R/scale-.r
index ef71fa8..fe0aac1 100644
--- a/R/scale-.r
+++ b/R/scale-.r
@@ -569,8 +569,9 @@ continuous_scale <- function(aesthetics, scale_name, palette, name = waiver(),
#' they should take
#' @param name the name of the scale - used as the axis label or the legend
#' title
-#' @param drop drop unused factor levels from the scale (\code{TRUE} or
-#' \code{FALSE})
+#' @param drop Should unused factor levels be omitted from the scale?
+#' The default, \code{TRUE}, uses the levels that appear in the data;
+#' \code{FALSE} uses all the levels in the factor.
#' @param breaks control the breaks in the guide. There are four possible
#' types of input:
#' \itemize{
diff --git a/R/scale-discrete-.r b/R/scale-discrete-.r
index 01dc58d..304d5c8 100644
--- a/R/scale-discrete-.r
+++ b/R/scale-discrete-.r
@@ -15,10 +15,9 @@
#' @rdname scale_discrete
#' @export
#' @examples
-#' \donttest{
-#' ggplot(diamonds, aes(cut)) + stat_bin()
#' ggplot(diamonds, aes(cut)) + geom_bar()
#'
+#' \donttest{
#' # The discrete position scale is added automatically whenever you
#' # have a discrete position.
#'
@@ -29,9 +28,6 @@
#' d + scale_x_discrete("Cut", labels = c("Fair" = "F","Good" = "G",
#' "Very Good" = "VG","Perfect" = "P","Ideal" = "I"))
#'
-#' d + scale_y_discrete("Clarity")
-#' d + scale_x_discrete("Cut") + scale_y_discrete("Clarity")
-#'
#' # Use limits to adjust the which levels (and in what order)
#' # are displayed
#' d + scale_x_discrete(limits=c("Fair","Ideal"))
@@ -96,14 +92,9 @@ ScaleDiscretePosition <- ggproto("ScaleDiscretePosition", ScaleDiscrete,
}
},
- # If range not available from discrete range, implies discrete scale been
- # used with purely continuous data, so construct limits accordingly
get_limits = function(self) {
if (self$is_empty()) return(c(0, 1))
-
- dis_limits <- function(x) seq.int(floor(min(x)), ceiling(max(x)), by = 1L)
-
- self$limits %||% self$range$range %||% dis_limits(self$range_c$range)
+ self$limits %||% self$range$range %||% integer()
},
is_empty = function(self) {
@@ -124,16 +115,21 @@ ScaleDiscretePosition <- ggproto("ScaleDiscretePosition", ScaleDiscrete,
},
dimension = function(self, expand = c(0, 0)) {
- disc_range <- c(1, length(self$get_limits()))
- disc <- expand_range(disc_range, 0, expand[2], 1)
-
- # if no data was trained (i.e. range_c is infinite) return disc range
- if (any(is.infinite(self$range_c$range))) {
- return(disc)
+ c_range <- self$range_c$range
+ d_range <- self$range$range
+
+ if (self$is_empty()) {
+ c(0, 1)
+ } else if (is.null(d_range)) { # only continuous
+ expand_range(c_range, expand[1], 0 , 1)
+ } else if (is.null(c_range)) { # only discrete
+ expand_range(c(1, length(d_range)), 0, expand[2], 1)
+ } else { # both
+ range(
+ expand_range(c_range, expand[1], 0 , 1),
+ expand_range(c(1, length(d_range)), 0, expand[2], 1)
+ )
}
-
- cont <- expand_range(self$range_c$range, expand[1], 0, expand[2])
- range(disc, cont)
},
clone = function(self) {
diff --git a/R/scale-shape.r b/R/scale-shape.r
index 8822e48..4b602a9 100644
--- a/R/scale-shape.r
+++ b/R/scale-shape.r
@@ -30,10 +30,12 @@ scale_shape <- function(..., solid = TRUE) {
#' @rdname scale_shape
#' @export
+#' @usage NULL
scale_shape_discrete <- scale_shape
#' @rdname scale_shape
#' @export
+#' @usage NULL
scale_shape_continuous <- function(...) {
stop("A continuous variable can not be mapped to shape", call. = FALSE)
}
diff --git a/R/scale-size.r b/R/scale-size.r
index 0782475..a8da394 100644
--- a/R/scale-size.r
+++ b/R/scale-size.r
@@ -60,6 +60,7 @@ scale_size <- scale_size_continuous
#' @export
#' @usage NULL
scale_size_discrete <- function(..., range = c(2, 6)) {
+ warning("Using size for a discrete variable is not advised.", call. = FALSE)
discrete_scale("size", "size_d", function(n) {
area <- seq(range[1] ^ 2, range[2] ^ 2, length.out = n)
sqrt(area)
@@ -76,3 +77,18 @@ scale_size_area <- function(..., max_size = 6) {
palette = abs_area(max_size),
rescaler = rescale_max, ...)
}
+
+#' @rdname scale_size
+#' @export
+#' @usage NULL
+scale_size_datetime <- function() {
+ scale_size_continuous(trans = "time")
+}
+
+#' @rdname scale_size
+#' @export
+#' @usage NULL
+scale_size_date <- function() {
+ scale_size_continuous(trans = "date")
+}
+
diff --git a/R/scale-type.R b/R/scale-type.R
new file mode 100644
index 0000000..b08b1f9
--- /dev/null
+++ b/R/scale-type.R
@@ -0,0 +1,66 @@
+find_scale <- function(aes, x, env = parent.frame()) {
+ type <- scale_type(x)
+ candidates <- paste("scale", aes, type, sep = "_")
+
+ for (scale in candidates) {
+ scale_f <- find_global(scale, env, mode = "function")
+ if (!is.null(scale_f))
+ return(scale_f())
+ }
+
+ # Failure to find a scale is not an error because some "aesthetics" don't
+ # need scales (e.g. group), and it allows others to extend ggplot2 with
+ # their own aesthetics
+
+ return(NULL)
+}
+
+# Look for object first in parent environment and if not found, then in
+# ggplot2 namespace environment. This makes it possible to override default
+# scales by setting them in the parent environment.
+find_global <- function(name, env, mode = "any") {
+ if (exists(name, envir = env, mode = mode)) {
+ return(get(name, envir = env, mode = mode))
+ }
+
+ nsenv <- asNamespace("ggplot2")
+ if (exists(name, envir = nsenv, mode = mode)) {
+ return(get(name, envir = nsenv, mode = mode))
+ }
+
+ NULL
+}
+
+# Determine default type of a scale
+scale_type <- function(x) UseMethod("scale_type")
+
+#' @export
+scale_type.default <- function(x) {
+ message("Don't know how to automatically pick scale for object of type ",
+ paste(class(x), collapse = "/"), ". Defaulting to continuous.")
+ "continuous"
+}
+
+#' @export
+scale_type.AsIs <- function(x) "identity"
+
+#' @export
+scale_type.logical <- function(x) "discrete"
+
+#' @export
+scale_type.character <- function(x) "discrete"
+
+#' @export
+scale_type.ordered <- function(x) c("ordinal", "discrete")
+
+#' @export
+scale_type.factor <- function(x) "discrete"
+
+#' @export
+scale_type.POSIXt <- function(x) c("datetime", "continuous")
+
+#' @export
+scale_type.Date <- function(x) c("date", "continuous")
+
+#' @export
+scale_type.numeric <- function(x) "continuous"
diff --git a/R/scales-.r b/R/scales-.r
index 3498cd1..2330d8a 100644
--- a/R/scales-.r
+++ b/R/scales-.r
@@ -18,6 +18,10 @@ ScalesList <- ggproto("ScalesList", NULL,
},
add = function(self, scale) {
+ if (is.null(scale)) {
+ return()
+ }
+
prev_aes <- self$find(scale$aesthetics)
if (any(prev_aes)) {
# Get only the first aesthetic name in the returned vector -- it can
@@ -98,14 +102,7 @@ scales_add_defaults <- function(scales, data, aesthetics, env) {
)
for (aes in names(datacols)) {
- type <- scale_type(datacols[[aes]])
- scale_name <- paste("scale", aes, type, sep = "_")
-
- # Skip aesthetics with no scales (e.g. group, order, etc)
- scale_f <- find_global(scale_name, env, mode = "function")
- if (is.null(scale_f)) next
-
- scales$add(scale_f())
+ scales$add(find_scale(aes, datacols[[aes]], env))
}
}
@@ -126,47 +123,3 @@ scales_add_missing <- function(plot, aesthetics, env) {
}
-# Look for object first in parent environment and if not found, then in
-# ggplot2 namespace environment. This makes it possible to override default
-# scales by setting them in the parent environment.
-find_global <- function(name, env, mode = "any") {
- if (exists(name, envir = env, mode = mode)) {
- return(get(name, envir = env, mode = mode))
- }
-
- nsenv <- asNamespace("ggplot2")
- if (exists(name, envir = nsenv, mode = mode)) {
- return(get(name, envir = nsenv, mode = mode))
- }
-
- NULL
-}
-
-
-# Determine default type of a scale
-scale_type <- function(x) UseMethod("scale_type")
-
-#' @export
-scale_type.default <- function(x) {
- message("Don't know how to automatically pick scale for object of type ",
- paste(class(x), collapse = "/"), ". Defaulting to continuous")
- "continuous"
-}
-
-#' @export
-scale_type.logical <- function(x) "discrete"
-
-#' @export
-scale_type.character <- function(x) "discrete"
-
-#' @export
-scale_type.factor <- function(x) "discrete"
-
-#' @export
-scale_type.POSIXt <- function(x) "datetime"
-
-#' @export
-scale_type.Date <- function(x) "date"
-
-#' @export
-scale_type.numeric <- function(x) "continuous"
diff --git a/R/stat-bin.r b/R/stat-bin.r
index 7acf609..b6a9f3d 100644
--- a/R/stat-bin.r
+++ b/R/stat-bin.r
@@ -1,17 +1,29 @@
#' \code{stat_bin} is suitable only for continuous x data. If your x data is
#' discrete, you probably want to use \code{\link{stat_count}}.
#'
-#' @param binwidth Bin width to use. Defaults to 1/\code{bins} of the range of
-#' the data
-#' @param bins Number of bins. Overridden by \code{binwidth} or \code{breaks}.
-#' Defaults to 30
-#' @param breaks Actual breaks to use. Overrides bin width, bin number and
-#' origin
-#' @param origin Origin of first bin
-#' @param width Width of bars when used with categorical data
-#' @param right If \code{TRUE}, right-closed, left-open, if \code{FALSE},
-#' the default, right-open, left-closed.
-#' @param drop If TRUE, remove all bins with zero counts
+#' @param binwidth The width of the bins. The default is to use \code{bins}
+#' bins that cover the range of the data. You should always override
+#' this value, exploring multiple widths to find the best to illustrate the
+#' stories in your data.
+#'
+#' The bin width of a date variable is the number of days in each time; the
+#' bin width of a time variable is the number of seconds.
+#' @param bins Number of bins. Overridden by \code{binwidth}. Defaults to 30
+#' @param center The center of one of the bins. Note that if center is above or
+#' below the range of the data, things will be shifted by an appropriate
+#' number of \code{width}s. To center on integers, for example, use
+#' \code{width=1} and \code{center=0}, even if \code{0} is outside the range
+#' of the data. At most one of \code{center} and \code{boundary} may be
+#' specified.
+#' @param boundary A boundary between two bins. As with \code{center}, things
+#' are shifted when \code{boundary} is outside the range of the data. For
+#' example, to center on integers, use \code{width = 1} and \code{boundary =
+#' 0.5}, even if \code{1} is outside the range of the data. At most one of
+#' \code{center} and \code{boundary} may be specified.
+#' @param closed One of \code{"right"} or \code{"left"} indicating whether right
+#' or left edges of bins are included in the bin.
+#' @param pad If \code{TRUE}, adds empty bins at either end of x. This ensures
+#' frequency polygons touch 0. Defaults to \code{FALSE}.
#' @section Computed variables:
#' \describe{
#' \item{count}{number of points in bin}
@@ -25,11 +37,19 @@
#' x data, whereas \link{stat_bin} is suitable only for continuous x data.
#' @export
#' @rdname geom_histogram
-stat_bin <- function(mapping = NULL, data = NULL, geom = "bar",
- position = "stack", width = 0.9, drop = FALSE,
- right = FALSE, binwidth = NULL, bins = NULL, origin = NULL,
- breaks = NULL, na.rm = FALSE,
- show.legend = NA, inherit.aes = TRUE, ...) {
+stat_bin <- function(mapping = NULL, data = NULL,
+ geom = "bar", position = "stack",
+ ...,
+ binwidth = NULL,
+ bins = NULL,
+ center = NULL,
+ boundary = NULL,
+ closed = c("right", "left"),
+ pad = FALSE,
+ na.rm = FALSE,
+ show.legend = NA,
+ inherit.aes = TRUE) {
+
layer(
data = data,
mapping = mapping,
@@ -39,13 +59,12 @@ stat_bin <- function(mapping = NULL, data = NULL, geom = "bar",
show.legend = show.legend,
inherit.aes = inherit.aes,
params = list(
- width = width,
- drop = drop,
- right = right,
- bins = bins,
binwidth = binwidth,
- origin = origin,
- breaks = breaks,
+ bins = bins,
+ center = center,
+ boundary = boundary,
+ closed = closed,
+ pad = pad,
na.rm = na.rm,
...
)
@@ -66,86 +85,56 @@ StatBin <- ggproto("StatBin", Stat,
call. = FALSE)
}
+ if (!is.null(params$drop)) {
+ warning("`drop` is deprecated. Please use `pad` instead.", call. = FALSE)
+ params$drop <- NULL
+ }
+ if (!is.null(params$origin)) {
+ warning("`origin` is deprecated. Please use `boundary` instead.", call. = FALSE)
+ params$boundary <- params$origin
+ params$origin <- NULL
+ }
+ if (!is.null(params$right)) {
+ warning("`right` is deprecated. Please use `closed` instead.", call. = FALSE)
+ params$closed <- if (params$right) "right" else "left"
+ params$right <- NULL
+ }
+ if (!is.null(params$width)) {
+ stop("`width` is deprecated. Do you want `geom_bar()`?", call. = FALSE)
+ }
+ if (!is.null(params$boundary) && !is.null(params$center)) {
+ stop("Only one of `boundary` and `center` may be specified.", call. = FALSE)
+ }
+
if (is.null(params$breaks) && is.null(params$binwidth) && is.null(params$bins)) {
message_wrap("`stat_bin()` using `bins = 30`. Pick better value with `binwidth`.")
+ params$bins <- 30
}
params
},
compute_group = function(data, scales, binwidth = NULL, bins = NULL,
- origin = NULL, breaks = NULL, width = 0.9, drop = FALSE,
- right = FALSE) {
- range <- scales$x$dimension()
+ center = NULL, boundary = NULL,
+ closed = c("right", "left"), pad = FALSE,
+ # The following arguments are not used, but must
+ # be listed so parameters are computed correctly
+ breaks = NULL, origin = NULL, right = NULL,
+ drop = NULL, width = NULL) {
- bin(data$x, data$weight, binwidth = binwidth, bins = bins,
- origin = origin, breaks = breaks, range = range, width = width,
- drop = drop, right = right)
+ if (!is.null(breaks)) {
+ bins <- bin_breaks(breaks, closed)
+ } else if (!is.null(binwidth)) {
+ bins <- bin_breaks_width(scales$x$dimension(), binwidth, center = center,
+ boundary = boundary, closed = closed)
+ } else {
+ bins <- bin_breaks_bins(scales$x$dimension(), bins, center = center,
+ boundary = boundary, closed = closed)
+ }
+ bin_vector(data$x, bins, weight = data$weight, pad = pad)
},
default_aes = aes(y = ..count..),
required_aes = c("x")
)
-bin <- function(x, weight=NULL, binwidth=NULL, bins=NULL, origin=NULL, breaks=NULL, range=NULL, width=0.9, drop = FALSE, right = FALSE) {
-
- if (length(stats::na.omit(x)) == 0) return(data.frame())
- if (is.null(weight)) weight <- rep(1, length(x))
- weight[is.na(weight)] <- 0
-
- if (is.null(range)) range <- range(x, na.rm = TRUE, finite = TRUE)
- if (is.null(bins)) bins <- 30
- if (is.null(binwidth)) binwidth <- diff(range) / bins
-
- if (is.integer(x)) {
- bins <- x
- x <- sort(unique(bins))
- width <- width
- } else if (diff(range) == 0) {
- width <- width
- bins <- x
- } else {# if (is.numeric(x))
- if (is.null(breaks)) {
- if (is.null(origin)) {
- breaks <- fullseq(range, binwidth, pad = TRUE)
- } else {
- breaks <- seq(origin, max(range) + binwidth, binwidth)
- }
- }
-
- # Adapt break fuzziness from base::hist - this protects from floating
- # point rounding errors
- diddle <- 1e-07 * stats::median(diff(breaks))
- if (right) {
- fuzz <- c(-diddle, rep.int(diddle, length(breaks) - 1))
- } else {
- fuzz <- c(rep.int(-diddle, length(breaks) - 1), diddle)
- }
- fuzzybreaks <- sort(breaks) + fuzz
-
- bins <- cut(x, fuzzybreaks, include.lowest = TRUE, right = right)
- left <- breaks[-length(breaks)]
- right <- breaks[-1]
- x <- (left + right)/2
- width <- diff(breaks)
- }
-
- results <- data.frame(
- count = as.numeric(tapply(weight, bins, sum, na.rm = TRUE)),
- x = x,
- width = width
- )
-
- if (sum(results$count, na.rm = TRUE) == 0) {
- return(results)
- }
-
- results$count[is.na(results$count)] <- 0
- results$density <- results$count / results$width / sum(abs(results$count), na.rm = TRUE)
- results$ncount <- results$count / max(abs(results$count), na.rm = TRUE)
- results$ndensity <- results$density / max(abs(results$density), na.rm = TRUE)
- if (drop) {
- results <- results[results$count > 0, , drop = FALSE]
- }
- results
-}
diff --git a/R/stat-bin2d.r b/R/stat-bin2d.r
index c8bf0e4..202a74b 100644
--- a/R/stat-bin2d.r
+++ b/R/stat-bin2d.r
@@ -5,10 +5,15 @@
#' @param drop if \code{TRUE} removes all cells with 0 counts.
#' @export
#' @rdname geom_bin2d
-stat_bin_2d <- function(mapping = NULL, data = NULL, geom = "tile",
- position = "identity", bins = 30, binwidth = NULL,
- drop = TRUE, na.rm = FALSE,
- show.legend = NA, inherit.aes = TRUE, ...) {
+stat_bin_2d <- function(mapping = NULL, data = NULL,
+ geom = "tile", position = "identity",
+ ...,
+ bins = 30,
+ binwidth = NULL,
+ drop = TRUE,
+ na.rm = FALSE,
+ show.legend = NA,
+ inherit.aes = TRUE) {
layer(
data = data,
mapping = mapping,
@@ -49,8 +54,8 @@ StatBin2d <- ggproto("StatBin2d", Stat,
breaks <- dual_param(breaks, list(NULL, NULL))
bins <- dual_param(bins, list(x = 30, y = 30))
- xbreaks <- bin_breaks(scales$x, breaks$x, origin$x, binwidth$x, bins$x)
- ybreaks <- bin_breaks(scales$y, breaks$y, origin$y, binwidth$y, bins$y)
+ xbreaks <- bin2d_breaks(scales$x, breaks$x, origin$x, binwidth$x, bins$x)
+ ybreaks <- bin2d_breaks(scales$y, breaks$y, origin$y, binwidth$y, bins$y)
xbin <- cut(data$x, xbreaks, include.lowest = TRUE, labels = FALSE)
ybin <- cut(data$y, ybreaks, include.lowest = TRUE, labels = FALSE)
@@ -88,7 +93,7 @@ dual_param <- function(x, default = list(x = NULL, y = NULL)) {
}
}
-bin_breaks <- function(scale, breaks = NULL, origin = NULL, binwidth = NULL,
+bin2d_breaks <- function(scale, breaks = NULL, origin = NULL, binwidth = NULL,
bins = 30, right = TRUE) {
# Bins for categorical data should take the width of one level,
# and should show up centered over their tick marks. All other parameters
diff --git a/R/stat-bindot.r b/R/stat-bindot.r
index 4cc40c4..660cf02 100644
--- a/R/stat-bindot.r
+++ b/R/stat-bindot.r
@@ -8,7 +8,7 @@ StatBindot <- ggproto("StatBindot", Stat,
default_aes = aes(y = ..count..),
setup_params = function(data, params) {
- if (is.null(params$breaks) && is.null(params$binwidth)) {
+ if (is.null(params$binwidth)) {
message("`stat_bindot()` using `bins = 30`. Pick better value with `binwidth`.")
}
params
@@ -26,7 +26,7 @@ StatBindot <- ggproto("StatBindot", Stat,
compute_panel = function(self, data, scales, na.rm = FALSE, binwidth = NULL,
binaxis = "x", method = "dotdensity",
binpositions = "bygroup", origin = NULL,
- breaks = NULL, width = 0.9, drop = FALSE,
+ width = 0.9, drop = FALSE,
right = TRUE) {
# If using dotdensity and binning over all, we need to find the bin centers
@@ -56,13 +56,13 @@ StatBindot <- ggproto("StatBindot", Stat,
ggproto_parent(Stat, self)$compute_panel(data, scales, binwidth = binwidth,
binaxis = binaxis, method = method, binpositions = binpositions,
- origin = origin, breaks = breaks, width = width, drop = drop,
+ origin = origin, width = width, drop = drop,
right = right)
},
compute_group = function(self, data, scales, binwidth = NULL, binaxis = "x",
method = "dotdensity", binpositions = "bygroup",
- origin = NULL, breaks = NULL, width = 0.9, drop = FALSE,
+ origin = NULL, width = 0.9, drop = FALSE,
right = TRUE) {
# This function taken from integer help page
@@ -87,9 +87,14 @@ StatBindot <- ggproto("StatBindot", Stat,
}
if (method == "histodot") {
- # Use the function from stat_bin
- data <- bin(x = values, weight = data$weight, binwidth = binwidth, origin = origin,
- breaks = breaks, range = range, width = width, drop = drop, right = right)
+ closed <- if (right) "right" else "left"
+ if (!is.null(binwidth)) {
+ bins <- bin_breaks_width(range, binwidth, boundary = origin, closed = closed)
+ } else {
+ bins <- bin_breaks_bins(range, 30, boundary = origin, closed = closed)
+ }
+
+ data <- bin_vector(values, bins, weight = data$weight, pad = FALSE)
# Change "width" column to "binwidth" for consistency
names(data)[names(data) == "width"] <- "binwidth"
diff --git a/R/stat-binhex.r b/R/stat-binhex.r
index 8ba031c..d64761c 100644
--- a/R/stat-binhex.r
+++ b/R/stat-binhex.r
@@ -1,10 +1,14 @@
#' @export
#' @rdname geom_hex
#' @inheritParams stat_bin_2d
-stat_bin_hex <- function(mapping = NULL, data = NULL, geom = "hex",
- position = "identity", bins = 30, binwidth = NULL,
- na.rm = FALSE, show.legend = NA, inherit.aes = TRUE,
- ...) {
+stat_bin_hex <- function(mapping = NULL, data = NULL,
+ geom = "hex", position = "identity",
+ ...,
+ bins = 30,
+ binwidth = NULL,
+ na.rm = FALSE,
+ show.legend = NA,
+ inherit.aes = TRUE) {
layer(
data = data,
mapping = mapping,
@@ -32,54 +36,17 @@ stat_binhex <- stat_bin_hex
#' @usage NULL
#' @export
StatBinhex <- ggproto("StatBinhex", Stat,
- default_aes = aes(fill = ..count..),
+ default_aes = aes(fill = ..value..),
required_aes = c("x", "y"),
compute_group = function(data, scales, binwidth = NULL, bins = 30,
na.rm = FALSE) {
- if (is.null(binwidth)) {
- binwidth <- c(
- diff(scales$x$dimension()) / bins,
- diff(scales$y$dimension()) / bins
- )
- }
+ try_require("hexbin", "stat_binhex")
- hexBin(data$x, data$y, binwidth)
+ binwidth <- binwidth %||% hex_binwidth(bins, scales)
+ wt <- data$weight %||% rep(1L, nrow(data))
+ hexBinSummarise(data$x, data$y, wt, binwidth, sum)
}
)
-# Bin 2d plane into hexagons
-# Wrapper around \code{\link[hexbin]{hcell2xy}} that returns a data frame
-#
-# @param x positions
-# @param y positions
-# @param numeric vector of length 2 giving binwidth in x and y directions
-# @keyword internal
-hexBin <- function(x, y, binwidth) {
- # Convert binwidths into bounds + nbins
- xbnds <- c(
- plyr::round_any(min(x), binwidth[1], floor) - 1e-6,
- plyr::round_any(max(x), binwidth[1], ceiling) + 1e-6
- )
- xbins <- diff(xbnds) / binwidth[1]
-
- ybnds <- c(
- plyr::round_any(min(y), binwidth[2], floor) - 1e-6,
- plyr::round_any(max(y), binwidth[2], ceiling) + 1e-6
- )
- ybins <- diff(ybnds) / binwidth[2]
-
- # Call hexbin
- hb <- hexbin::hexbin(
- x, xbnds = xbnds, xbins = xbins,
- y, ybnds = ybnds, shape = ybins / xbins
- )
-
- # Convert to data frame
- data.frame(
- hexbin::hcell2xy(hb),
- count = hb at count,
- density = hb at count / sum(hb at count, na.rm = TRUE)
- )
-}
diff --git a/R/stat-boxplot.r b/R/stat-boxplot.r
index 97c7f22..8909ae1 100644
--- a/R/stat-boxplot.r
+++ b/R/stat-boxplot.r
@@ -13,9 +13,13 @@
#' \item{ymax}{upper whisker = largest observation less than or equal to upper hinge + 1.5 * IQR}
#' }
#' @export
-stat_boxplot <- function(mapping = NULL, data = NULL, geom = "boxplot",
- position = "dodge", coef = 1.5, na.rm = FALSE,
- show.legend = NA, inherit.aes = TRUE, ...) {
+stat_boxplot <- function(mapping = NULL, data = NULL,
+ geom = "boxplot", position = "dodge",
+ ...,
+ coef = 1.5,
+ na.rm = FALSE,
+ show.legend = NA,
+ inherit.aes = TRUE) {
layer(
data = data,
mapping = mapping,
diff --git a/R/stat-contour.r b/R/stat-contour.r
index f139f71..7eb6ac9 100644
--- a/R/stat-contour.r
+++ b/R/stat-contour.r
@@ -5,9 +5,12 @@
#' \item{level}{height of contour}
#' }
#' @rdname geom_contour
-stat_contour <- function(mapping = NULL, data = NULL, geom = "contour",
- position = "identity", na.rm = FALSE, show.legend = NA,
- inherit.aes = TRUE, ...) {
+stat_contour <- function(mapping = NULL, data = NULL,
+ geom = "contour", position = "identity",
+ ...,
+ na.rm = FALSE,
+ show.legend = NA,
+ inherit.aes = TRUE) {
layer(
data = data,
mapping = mapping,
diff --git a/R/stat-count.r b/R/stat-count.r
index eacc45f..c0b7285 100644
--- a/R/stat-count.r
+++ b/R/stat-count.r
@@ -14,9 +14,13 @@
#'
#' @export
#' @rdname geom_bar
-stat_count <- function(mapping = NULL, data = NULL, geom = "bar",
- position = "stack", width = NULL, ...,
- na.rm = FALSE, show.legend = NA, inherit.aes = TRUE) {
+stat_count <- function(mapping = NULL, data = NULL,
+ geom = "bar", position = "stack",
+ ...,
+ width = NULL,
+ na.rm = FALSE,
+ show.legend = NA,
+ inherit.aes = TRUE) {
layer(
data = data,
mapping = mapping,
diff --git a/R/stat-density-2d.r b/R/stat-density-2d.r
index e509ed5..3dfa844 100644
--- a/R/stat-density-2d.r
+++ b/R/stat-density-2d.r
@@ -7,10 +7,15 @@
#' using \code{\link[MASS]{bandwidth.nrd}}.
#' @section Computed variables:
#' Same as \code{\link{stat_contour}}
-stat_density_2d <- function(mapping = NULL, data = NULL, geom = "density_2d",
- position = "identity", contour = TRUE,
- n = 100, h = NULL, na.rm = FALSE,
- show.legend = NA, inherit.aes = TRUE, ...) {
+stat_density_2d <- function(mapping = NULL, data = NULL,
+ geom = "density_2d", position = "identity",
+ ...,
+ contour = TRUE,
+ n = 100,
+ h = NULL,
+ na.rm = FALSE,
+ show.legend = NA,
+ inherit.aes = TRUE) {
layer(
data = data,
mapping = mapping,
@@ -23,6 +28,7 @@ stat_density_2d <- function(mapping = NULL, data = NULL, geom = "density_2d",
na.rm = na.rm,
contour = contour,
n = n,
+ h = h,
...
)
)
@@ -43,7 +49,8 @@ StatDensity2d <- ggproto("StatDensity2d", Stat,
required_aes = c("x", "y"),
compute_group = function(data, scales, na.rm = FALSE, h = NULL,
- contour = TRUE, n = 100) {
+ contour = TRUE, n = 100, bins = NULL,
+ binwidth = NULL) {
if (is.null(h)) {
h <- c(MASS::bandwidth.nrd(data$x), MASS::bandwidth.nrd(data$y))
}
@@ -56,7 +63,7 @@ StatDensity2d <- ggproto("StatDensity2d", Stat,
df$group <- data$group[1]
if (contour) {
- StatContour$compute_panel(df, scales)
+ StatContour$compute_panel(df, scales, bins, binwidth)
} else {
names(df) <- c("x", "y", "density", "group")
df$level <- 1
diff --git a/R/stat-density.r b/R/stat-density.r
index 5f6b285..c1707ed 100644
--- a/R/stat-density.r
+++ b/R/stat-density.r
@@ -1,4 +1,7 @@
-#' @param adjust see \code{\link{density}} for details
+#' @param bw the smoothing bandwidth to be used, see
+#' \code{\link{density}} for details
+#' @param adjust adjustment of the bandwidth, see
+#' \code{\link{density}} for details
#' @param kernel kernel used for density estimation, see
#' \code{\link{density}} for details
#' @param trim This parameter only matters if you are displaying multiple
@@ -16,10 +19,16 @@
#' }
#' @export
#' @rdname geom_density
-stat_density <- function(mapping = NULL, data = NULL, geom = "area",
- position = "stack", adjust = 1, kernel = "gaussian",
- trim = FALSE, na.rm = FALSE,
- show.legend = NA, inherit.aes = TRUE, ...) {
+stat_density <- function(mapping = NULL, data = NULL,
+ geom = "area", position = "stack",
+ ...,
+ bw = "nrd0",
+ adjust = 1,
+ kernel = "gaussian",
+ trim = FALSE,
+ na.rm = FALSE,
+ show.legend = NA,
+ inherit.aes = TRUE) {
layer(
data = data,
@@ -30,6 +39,7 @@ stat_density <- function(mapping = NULL, data = NULL, geom = "area",
show.legend = show.legend,
inherit.aes = inherit.aes,
params = list(
+ bw = bw,
adjust = adjust,
kernel = kernel,
trim = trim,
@@ -47,7 +57,7 @@ StatDensity <- ggproto("StatDensity", Stat,
required_aes = "x",
default_aes = aes(y = ..density.., fill = NA),
- compute_group = function(data, scales, adjust = 1, kernel = "gaussian",
+ compute_group = function(data, scales, bw = "nrd0", adjust = 1, kernel = "gaussian",
trim = FALSE, na.rm = FALSE) {
if (trim) {
range <- range(data$x, na.rm = TRUE)
@@ -56,7 +66,7 @@ StatDensity <- ggproto("StatDensity", Stat,
}
compute_density(data$x, data$weight, from = range[1], to = range[2],
- adjust = adjust, kernel = kernel)
+ bw = bw, adjust = adjust, kernel = kernel)
}
)
diff --git a/R/stat-ecdf.r b/R/stat-ecdf.r
index 4e0f5f3..6663da7 100644
--- a/R/stat-ecdf.r
+++ b/R/stat-ecdf.r
@@ -1,10 +1,13 @@
#' Empirical Cumulative Density Function
#'
-#' @inheritParams stat_identity
+#' @inheritParams layer
+#' @inheritParams geom_point
#' @param na.rm If \code{FALSE} (the default), removes missing values with
#' a warning. If \code{TRUE} silently removes missing values.
#' @param n if NULL, do not interpolate. If not NULL, this is the number
#' of points to interpolate with.
+#' @param pad If \code{TRUE}, pad the ecdf with additional points (-Inf, 0)
+#' and (Inf, 1)
#' @section Computed variables:
#' \describe{
#' \item{x}{x in data}
@@ -21,9 +24,14 @@
#'
#' ggplot(df, aes(x, colour = g)) + stat_ecdf()
#' }
-stat_ecdf <- function(mapping = NULL, data = NULL, geom = "step",
- position = "identity", n = NULL, na.rm = FALSE,
- show.legend = NA, inherit.aes = TRUE, ...) {
+stat_ecdf <- function(mapping = NULL, data = NULL,
+ geom = "step", position = "identity",
+ ...,
+ n = NULL,
+ pad = TRUE,
+ na.rm = FALSE,
+ show.legend = NA,
+ inherit.aes = TRUE) {
layer(
data = data,
mapping = mapping,
@@ -46,31 +54,20 @@ stat_ecdf <- function(mapping = NULL, data = NULL, geom = "step",
#' @usage NULL
#' @export
StatEcdf <- ggproto("StatEcdf", Stat,
- compute_group = function(data, scales, n = NULL) {
-
+ compute_group = function(data, scales, n = NULL, pad = TRUE) {
# If n is NULL, use raw values; otherwise interpolate
if (is.null(n)) {
- xvals <- unique(data$x)
+ x <- unique(data$x)
} else {
- xvals <- seq(min(data$x), max(data$x), length.out = n)
+ x <- seq(min(data$x), max(data$x), length.out = n)
}
- y <- ecdf(data$x)(xvals)
-
- # make point with y = 0, from plot.stepfun
- rx <- range(xvals)
- if (length(xvals) > 1L) {
- dr <- max(0.08 * diff(rx), median(diff(xvals)))
- } else {
- dr <- abs(xvals)/16
+ if (pad) {
+ x <- c(-Inf, x, Inf)
}
+ y <- ecdf(data$x)(x)
- x0 <- rx[1] - dr
- x1 <- rx[2] + dr
- y0 <- 0
- y1 <- 1
-
- data.frame(x = c(x0, xvals, x1), y = c(y0, y, y1))
+ data.frame(x = x, y = y)
},
default_aes = aes(y = ..y..),
diff --git a/R/stat-ellipse.R b/R/stat-ellipse.R
index 9eb6001..97c01e3 100644
--- a/R/stat-ellipse.R
+++ b/R/stat-ellipse.R
@@ -15,9 +15,8 @@
#' representing the euclidean distance from the center.
#' This ellipse probably won't appear circular unless \code{coord_fixed()} is applied.
#' @param segments The number of segments to be used in drawing the ellipse.
-#' @param na.rm If \code{FALSE} (the default), removes missing values with
-#' a warning. If \code{TRUE} silently removes missing values.
-#' @inheritParams stat_identity
+#' @inheritParams layer
+#' @inheritParams geom_point
#' @export
#' @examples
#' ggplot(faithful, aes(waiting, eruptions)) +
@@ -41,10 +40,15 @@
#'
#' ggplot(faithful, aes(waiting, eruptions, fill = eruptions > 3)) +
#' stat_ellipse(geom = "polygon")
-stat_ellipse <- function(mapping = NULL, data = NULL, geom = "path",
- position = "identity", type = "t", level = 0.95,
- segments = 51, na.rm = FALSE, show.legend = NA,
- inherit.aes = TRUE, ...) {
+stat_ellipse <- function(mapping = NULL, data = NULL,
+ geom = "path", position = "identity",
+ ...,
+ type = "t",
+ level = 0.95,
+ segments = 51,
+ na.rm = FALSE,
+ show.legend = NA,
+ inherit.aes = TRUE) {
layer(
data = data,
mapping = mapping,
diff --git a/R/stat-function.r b/R/stat-function.r
index 69ee89d..ed499b8 100644
--- a/R/stat-function.r
+++ b/R/stat-function.r
@@ -6,9 +6,9 @@
#' @param fun function to use
#' @param n number of points to interpolate along
#' @param args list of additional arguments to pass to \code{fun}
-#' @param na.rm If \code{FALSE} (the default), removes missing values with
-#' a warning. If \code{TRUE} silently removes missing values.
-#' @inheritParams stat_identity
+#' @param xlim Optionally, restrict the range of the function to this range.
+#' @inheritParams layer
+#' @inheritParams geom_point
#' @section Computed variables:
#' \describe{
#' \item{x}{x's along a grid}
@@ -23,7 +23,7 @@
#' x <- df$x
#' base <- ggplot(df, aes(x)) + geom_density()
#' base + stat_function(fun = dnorm, colour = "red")
-#' base + stat_function(fun = dnorm, colour = "red", arg = list(mean = 3))
+#' base + stat_function(fun = dnorm, colour = "red", args = list(mean = 3))
#'
#' # Plot functions without data
#' # Examples adapted from Kohske Takahashi
@@ -47,10 +47,16 @@
#' # Using a custom function
#' test <- function(x) {x ^ 2 + x + 20}
#' f + stat_function(fun = test)
-stat_function <- function(mapping = NULL, data = NULL, geom = "path",
- position = "identity", fun, n = 101, args = list(),
- na.rm = FALSE, show.legend = NA, inherit.aes = TRUE,
- ...) {
+stat_function <- function(mapping = NULL, data = NULL,
+ geom = "path", position = "identity",
+ ...,
+ fun,
+ xlim = NULL,
+ n = 101,
+ args = list(),
+ na.rm = FALSE,
+ show.legend = NA,
+ inherit.aes = TRUE) {
layer(
data = data,
mapping = mapping,
@@ -64,6 +70,7 @@ stat_function <- function(mapping = NULL, data = NULL, geom = "path",
n = n,
args = args,
na.rm = na.rm,
+ xlim = xlim,
...
)
)
@@ -76,13 +83,21 @@ stat_function <- function(mapping = NULL, data = NULL, geom = "path",
StatFunction <- ggproto("StatFunction", Stat,
default_aes = aes(y = ..y..),
- compute_group = function(data, scales, fun, n = 101, args = list()) {
- range <- scales$x$dimension()
+ compute_group = function(data, scales, fun, xlim = NULL, n = 101, args = list()) {
+ range <- xlim %||% scales$x$dimension()
xseq <- seq(range[1], range[2], length.out = n)
+ if (scales$x$is_discrete()) {
+ x_trans <- xseq
+ } else {
+ # For continuous scales, need to back transform from transformed range
+ # to original values
+ x_trans <- scales$x$trans$inverse(xseq)
+ }
+
data.frame(
x = xseq,
- y = do.call(fun, c(list(quote(scales$x$trans$inv(xseq))), args))
+ y = do.call(fun, c(list(quote(x_trans)), args))
)
}
)
diff --git a/R/stat-identity.r b/R/stat-identity.r
index 9b2781a..71bfb89 100644
--- a/R/stat-identity.r
+++ b/R/stat-identity.r
@@ -2,31 +2,17 @@
#'
#' The identity statistic leaves the data unchanged.
#'
-#' @param mapping The aesthetic mapping, usually constructed with
-#' \code{\link{aes}} or \code{\link{aes_string}}. Only needs to be set
-#' at the layer level if you are overriding the plot defaults.
-#' @param data A layer specific dataset - only needed if you want to override
-#' the plot defaults.
-#' @param geom The geometric object to use display the data
-#' @param position The position adjustment to use for overlapping points
-#' on this layer
-#' @param show.legend logical. Should this layer be included in the legends?
-#' \code{NA}, the default, includes if any aesthetics are mapped.
-#' \code{FALSE} never includes, and \code{TRUE} always includes.
-#' @param inherit.aes If \code{FALSE}, overrides the default aesthetics,
-#' rather than combining with them. This is most useful for helper functions
-#' that define both data and aesthetics and shouldn't inherit behaviour from
-#' the default plot specification, e.g. \code{\link{borders}}.
-#' @param ... other arguments passed on to \code{\link{layer}}. This can
-#' include aesthetics whose values you want to set, not map. See
-#' \code{\link{layer}} for more details.
+#' @inheritParams layer
+#' @inheritParams geom_point
#' @export
#' @examples
#' p <- ggplot(mtcars, aes(wt, mpg))
#' p + stat_identity()
-stat_identity <- function(mapping = NULL, data = NULL, geom = "point",
- position = "identity", show.legend = NA,
- inherit.aes = TRUE, ...) {
+stat_identity <- function(mapping = NULL, data = NULL,
+ geom = "point", position = "identity",
+ ...,
+ show.legend = NA,
+ inherit.aes = TRUE) {
layer(
data = data,
mapping = mapping,
diff --git a/R/stat-qq.r b/R/stat-qq.r
index 6647936..23e8e61 100644
--- a/R/stat-qq.r
+++ b/R/stat-qq.r
@@ -6,9 +6,8 @@
#' @param distribution Distribution function to use, if x not specified
#' @param dparams Additional parameters passed on to \code{distribution}
#' function.
-#' @param na.rm If \code{FALSE} (the default), removes missing values with
-#' a warning. If \code{TRUE} silently removes missing values.
-#' @inheritParams stat_identity
+#' @inheritParams layer
+#' @inheritParams geom_point
#' @section Computed variables:
#' \describe{
#' \item{sample}{sample quantiles}
@@ -33,10 +32,14 @@
#' ggplot(mtcars) +
#' stat_qq(aes(sample = mpg, colour = factor(cyl)))
#' }
-stat_qq <- function(mapping = NULL, data = NULL, geom = "point",
- position = "identity", distribution = stats::qnorm,
- dparams = list(), na.rm = FALSE,
- show.legend = NA, inherit.aes = TRUE, ...) {
+stat_qq <- function(mapping = NULL, data = NULL,
+ geom = "point", position = "identity",
+ ...,
+ distribution = stats::qnorm,
+ dparams = list(),
+ na.rm = FALSE,
+ show.legend = NA,
+ inherit.aes = TRUE) {
layer(
data = data,
mapping = mapping,
diff --git a/R/stat-quantile.r b/R/stat-quantile.r
index d927561..ace21c7 100644
--- a/R/stat-quantile.r
+++ b/R/stat-quantile.r
@@ -2,18 +2,24 @@
#' @param formula formula relating y variables to x variables
#' @param method Quantile regression method to use. Currently only supports
#' \code{\link[quantreg]{rq}}.
-#' @inheritParams stat_identity
+#' @inheritParams layer
+#' @inheritParams geom_point
#' @section Computed variables:
#' \describe{
#' \item{quantile}{quantile of distribution}
#' }
#' @export
#' @rdname geom_quantile
-stat_quantile <- function(mapping = NULL, data = NULL, geom = "quantile",
- position = "identity", quantiles = c(0.25, 0.5, 0.75),
- formula = NULL, method = "rq", method.args = list(),
- na.rm = FALSE, show.legend = NA, inherit.aes = TRUE,
- ...) {
+stat_quantile <- function(mapping = NULL, data = NULL,
+ geom = "quantile", position = "identity",
+ ...,
+ quantiles = c(0.25, 0.5, 0.75),
+ formula = NULL,
+ method = "rq",
+ method.args = list(),
+ na.rm = FALSE,
+ show.legend = NA,
+ inherit.aes = TRUE) {
layer(
data = data,
mapping = mapping,
diff --git a/R/stat-smooth-methods.r b/R/stat-smooth-methods.r
index a7ac2a3..43ebf62 100644
--- a/R/stat-smooth-methods.r
+++ b/R/stat-smooth-methods.r
@@ -32,9 +32,9 @@ predictdf.glm <- function(model, xseq, se, level) {
data.frame(
x = xseq,
y = model$family$linkinv(as.vector(pred$fit)),
- ymin = model$family$linkinv(as.vector(pred$fit - std * pred$se)),
- ymax = model$family$linkinv(as.vector(pred$fit + std * pred$se)),
- se = as.vector(pred$se)
+ ymin = model$family$linkinv(as.vector(pred$fit - std * pred$se.fit)),
+ ymax = model$family$linkinv(as.vector(pred$fit + std * pred$se.fit)),
+ se = as.vector(pred$se.fit)
)
} else {
data.frame(x = xseq, y = model$family$linkinv(as.vector(pred)))
diff --git a/R/stat-smooth.r b/R/stat-smooth.r
index 22f30a3..f275fb6 100644
--- a/R/stat-smooth.r
+++ b/R/stat-smooth.r
@@ -24,11 +24,20 @@
#' }
#' @export
#' @rdname geom_smooth
-stat_smooth <- function(mapping = NULL, data = NULL, geom = "smooth",
- position = "identity", method = "auto", formula = y ~ x,
- se = TRUE, n = 80, span = 0.75, fullrange = FALSE,
- level = 0.95, method.args = list(),
- na.rm = FALSE, show.legend = NA, inherit.aes = TRUE, ...) {
+stat_smooth <- function(mapping = NULL, data = NULL,
+ geom = "smooth", position = "identity",
+ ...,
+ method = "auto",
+ formula = y ~ x,
+ se = TRUE,
+ n = 80,
+ span = 0.75,
+ fullrange = FALSE,
+ level = 0.95,
+ method.args = list(),
+ na.rm = FALSE,
+ show.legend = NA,
+ inherit.aes = TRUE) {
layer(
data = data,
mapping = mapping,
diff --git a/R/stat-sum.r b/R/stat-sum.r
index 81d5c86..62cf8ec 100644
--- a/R/stat-sum.r
+++ b/R/stat-sum.r
@@ -1,4 +1,5 @@
-#' @inheritParams stat_identity
+#' @inheritParams layer
+#' @inheritParams geom_point
#' @section Computed variables:
#' \describe{
#' \item{n}{number of observations at position}
@@ -6,9 +7,12 @@
#' }
#' @export
#' @rdname geom_count
-stat_sum <- function(mapping = NULL, data = NULL, geom = "point",
- position = "identity", na.rm = FALSE,
- show.legend = NA, inherit.aes = TRUE, ...) {
+stat_sum <- function(mapping = NULL, data = NULL,
+ geom = "point", position = "identity",
+ ...,
+ na.rm = FALSE,
+ show.legend = NA,
+ inherit.aes = TRUE) {
layer(
data = data,
mapping = mapping,
diff --git a/R/stat-summary-2d.r b/R/stat-summary-2d.r
index 1020351..4869038 100644
--- a/R/stat-summary-2d.r
+++ b/R/stat-summary-2d.r
@@ -12,10 +12,15 @@
#' \item \code{y}: vertical position
#' \item \code{z}: value passed to the summary function
#' }
-#'
+#' @section Computed variables:
+#' \describe{
+#' \item{x,y}{Location}
+#' \item{value}{Value of summary statistic.}
+#' }
#' @seealso \code{\link{stat_summary_hex}} for hexagonal summarization.
#' \code{\link{stat_bin2d}} for the binning options.
-#' @inheritParams stat_identity
+#' @inheritParams layer
+#' @inheritParams geom_point
#' @inheritParams stat_bin_2d
#' @param drop drop if the output of \code{fun} is \code{NA}.
#' @param fun function for summary.
@@ -33,11 +38,17 @@
#' if (requireNamespace("hexbin")) {
#' d + stat_summary_hex()
#' }
-stat_summary_2d <- function(mapping = NULL, data = NULL, geom = "tile",
- position = "identity", bins = 30, binwidth = NULL,
- drop = TRUE, fun = "mean", fun.args = list(),
- na.rm = FALSE, show.legend = NA, inherit.aes = TRUE,
- ...) {
+stat_summary_2d <- function(mapping = NULL, data = NULL,
+ geom = "tile", position = "identity",
+ ...,
+ bins = 30,
+ binwidth = NULL,
+ drop = TRUE,
+ fun = "mean",
+ fun.args = list(),
+ na.rm = FALSE,
+ show.legend = NA,
+ inherit.aes = TRUE) {
layer(
data = data,
mapping = mapping,
@@ -83,8 +94,8 @@ StatSummary2d <- ggproto("StatSummary2d", Stat,
breaks <- dual_param(breaks, list(NULL, NULL))
bins <- dual_param(bins, list(x = 30, y = 30))
- xbreaks <- bin_breaks(scales$x, breaks$x, origin$x, binwidth$x, bins$x)
- ybreaks <- bin_breaks(scales$y, breaks$y, origin$y, binwidth$y, bins$y)
+ xbreaks <- bin2d_breaks(scales$x, breaks$x, origin$x, binwidth$x, bins$x)
+ ybreaks <- bin2d_breaks(scales$y, breaks$y, origin$y, binwidth$y, bins$y)
xbin <- cut(data$x, xbreaks, include.lowest = TRUE, labels = FALSE)
ybin <- cut(data$y, ybreaks, include.lowest = TRUE, labels = FALSE)
diff --git a/R/stat-summary-bin.R b/R/stat-summary-bin.R
index d0af6f7..2df1a28 100644
--- a/R/stat-summary-bin.R
+++ b/R/stat-summary-bin.R
@@ -1,11 +1,17 @@
#' @rdname stat_summary
#' @inheritParams stat_bin
#' @export
-stat_summary_bin <- function(mapping = NULL, data = NULL, geom = "pointrange",
- fun.data = NULL, fun.y = NULL, fun.ymax = NULL,
- fun.ymin = NULL, fun.args = list(), na.rm = FALSE,
- position = "identity", show.legend = NA,
- inherit.aes = TRUE, ...) {
+stat_summary_bin <- function(mapping = NULL, data = NULL,
+ geom = "pointrange", position = "identity",
+ ...,
+ fun.data = NULL,
+ fun.y = NULL,
+ fun.ymax = NULL,
+ fun.ymin = NULL,
+ fun.args = list(),
+ na.rm = FALSE,
+ show.legend = NA,
+ inherit.aes = TRUE) {
layer(
data = data,
mapping = mapping,
@@ -40,7 +46,7 @@ StatSummaryBin <- ggproto("StatSummaryBin", Stat,
fun <- make_summary_fun(fun.data, fun.y, fun.ymax, fun.ymin, fun.args)
- breaks <- bin_breaks(scales$x, NULL, origin, binwidth, bins, right = right)
+ breaks <- bin2d_breaks(scales$x, NULL, origin, binwidth, bins, right = right)
data$bin <- cut(data$x, breaks, include.lowest = TRUE, labels = FALSE)
out <- plyr::ddply(data, "bin", fun)
diff --git a/R/stat-summary-hex.r b/R/stat-summary-hex.r
index fe07860..844b5eb 100644
--- a/R/stat-summary-hex.r
+++ b/R/stat-summary-hex.r
@@ -1,11 +1,17 @@
#' @export
#' @rdname stat_summary_2d
#' @inheritParams stat_bin_hex
-stat_summary_hex <- function(mapping = NULL, data = NULL, geom = "hex",
- position = "identity", bins = 30, binwidth = NULL,
- drop = TRUE, fun = "mean", fun.args = list(),
- na.rm = FALSE, show.legend = NA, inherit.aes = TRUE,
- ...) {
+stat_summary_hex <- function(mapping = NULL, data = NULL,
+ geom = "hex", position = "identity",
+ ...,
+ bins = 30,
+ binwidth = NULL,
+ drop = TRUE,
+ fun = "mean",
+ fun.args = list(),
+ na.rm = FALSE,
+ show.legend = NA,
+ inherit.aes = TRUE) {
layer(
data = data,
mapping = mapping,
@@ -37,41 +43,10 @@ StatSummaryHex <- ggproto("StatSummaryHex", Stat,
compute_group = function(data, scales, binwidth = NULL, bins = 30, drop = TRUE,
fun = "mean", fun.args = list()) {
- if (is.null(binwidth)) {
- binwidth <- c(
- diff(scales$x$dimension()) / bins,
- diff(scales$y$dimension()) / bins
- )
- }
+ try_require("hexbin", "stat_summary_hex")
- # Convert binwidths into bounds + nbins
- x <- data$x
- y <- data$y
-
- xbnds <- c(
- plyr::round_any(min(x), binwidth[1], floor) - 1e-6,
- plyr::round_any(max(x), binwidth[1], ceiling) + 1e-6
- )
- xbins <- diff(xbnds) / binwidth[1]
-
- ybnds <- c(
- plyr::round_any(min(y), binwidth[1], floor) - 1e-6,
- plyr::round_any(max(y), binwidth[2], ceiling) + 1e-6
- )
- ybins <- diff(ybnds) / binwidth[2]
-
- # Call hexbin
- hb <- hexbin::hexbin(
- x, xbnds = xbnds, xbins = xbins,
- y, ybnds = ybnds, shape = ybins / xbins,
- IDs = TRUE
- )
-
- value <- do.call(tapply, c(list(quote(data$z), quote(hb at cID), quote(fun)), fun.args))
-
- # Convert to data frame
- ret <- data.frame(hexbin::hcell2xy(hb), value)
- if (drop) ret <- stats::na.omit(ret)
- ret
+ binwidth <- binwidth %||% hex_binwidth(bins, scales)
+ hexBinSummarise(data$x, data$y, data$z, binwidth,
+ fun = fun, fun.args = fun.args, drop = drop)
}
)
diff --git a/R/stat-summary.r b/R/stat-summary.r
index 9390877..a163fce 100644
--- a/R/stat-summary.r
+++ b/R/stat-summary.r
@@ -2,7 +2,7 @@
#'
#' \code{stat_summary} operates on unique \code{x}; \code{stat_summary_bin}
#' operators on binned \code{x}. They are more flexible versions of
-#' \code{\link{stat_bin}}: instead of just counting, the can compute any
+#' \code{\link{stat_bin}}: instead of just counting, they can compute any
#' aggregate.
#'
#' @section Aesthetics:
@@ -47,27 +47,18 @@
#'
#' # You can supply individual functions to summarise the value at
#' # each x:
-#' d + stat_summary(fun.y = "median", colour = "red", size = 2)
-#' d + stat_summary(fun.y = "mean", colour = "red", size = 2)
+#' d + stat_summary(fun.y = "median", colour = "red", size = 2, geom = "point")
+#' d + stat_summary(fun.y = "mean", colour = "red", size = 2, geom = "point")
#' d + aes(colour = factor(vs)) + stat_summary(fun.y = mean, geom="line")
#'
#' d + stat_summary(fun.y = mean, fun.ymin = min, fun.ymax = max,
#' colour = "red")
#'
-#' #' d <- ggplot(diamonds, aes(carat, price))
-#' d + geom_smooth()
-#' d + geom_line(stat = "summary_bin", binwidth = 0.1, fun.y = "mean")
-#'
#' d <- ggplot(diamonds, aes(cut))
#' d + geom_bar()
#' d + stat_summary_bin(aes(y = price), fun.y = "mean", geom = "bar")
-
-#' \donttest{
-#' # A set of useful summary functions is provided from the Hmisc package:
-#' stat_sum_df <- function(fun, geom="crossbar", ...) {
-#' stat_summary(fun.data=fun, colour="red", geom=geom, width=0.2, ...)
-#' }
#'
+#' \donttest{
#' # Don't use ylim to zoom into a summary plot - this throws the
#' # data away
#' p <- ggplot(mtcars, aes(cyl, mpg)) +
@@ -77,28 +68,18 @@
#' # Instead use coord_cartesian
#' p + coord_cartesian(ylim = c(15, 30))
#'
+#' # A set of useful summary functions is provided from the Hmisc package:
+#' stat_sum_df <- function(fun, geom="crossbar", ...) {
+#' stat_summary(fun.data=fun, colour="red", geom=geom, width=0.2, ...)
+#' }
+#' d <- ggplot(mtcars, aes(cyl, mpg)) + geom_point()
#' # The crossbar geom needs grouping to be specified when used with
#' # a continuous x axis.
#' d + stat_sum_df("mean_cl_boot", mapping = aes(group = cyl))
#' d + stat_sum_df("mean_sdl", mapping = aes(group = cyl))
-#' d + stat_sum_df("mean_sdl", mult = 1, mapping = aes(group = cyl))
+#' d + stat_sum_df("mean_sdl", fun.args = list(mult = 1), mapping = aes(group = cyl))
#' d + stat_sum_df("median_hilow", mapping = aes(group = cyl))
#'
-#' # There are lots of different geoms you can use to display the summaries
-#'
-#' d + stat_sum_df("mean_cl_normal", mapping = aes(group = cyl))
-#' d + stat_sum_df("mean_cl_normal", geom = "errorbar")
-#' d + stat_sum_df("mean_cl_normal", geom = "pointrange")
-#' d + stat_sum_df("mean_cl_normal", geom = "smooth")
-#'
-#' # Summaries are more useful with a bigger data set:
-#' mpg2 <- subset(mpg, cyl != 5L)
-#' m <- ggplot(mpg2, aes(x=cyl, y=hwy)) +
-#' geom_point() +
-#' stat_summary(fun.data = "mean_sdl", geom = "linerange",
-#' colour = "red", size = 2, mult = 1) +
-#' xlab("cyl")
-#' m
#' # An example with highly skewed distributions:
#' if (require("ggplot2movies")) {
#' set.seed(596)
@@ -122,11 +103,17 @@
#' m2 + coord_trans(y="log10")
#' }
#' }
-stat_summary <- function(mapping = NULL, data = NULL, geom = "pointrange",
- fun.data = NULL, fun.y = NULL, fun.ymax = NULL,
- fun.ymin = NULL, fun.args = list(), na.rm = FALSE,
- position = "identity", show.legend = NA,
- inherit.aes = TRUE, ...) {
+stat_summary <- function(mapping = NULL, data = NULL,
+ geom = "pointrange", position = "identity",
+ ...,
+ fun.data = NULL,
+ fun.y = NULL,
+ fun.ymax = NULL,
+ fun.ymin = NULL,
+ fun.args = list(),
+ na.rm = FALSE,
+ show.legend = NA,
+ inherit.aes = TRUE) {
layer(
data = data,
mapping = mapping,
@@ -180,7 +167,7 @@ summarise_by_x <- function(data, summary, ...) {
unique <- plyr::ddply(data, c("group", "x"), uniquecols)
unique$y <- NULL
- merge(summary, unique, by = c("x", "group"))
+ merge(summary, unique, by = c("x", "group"), sort = FALSE)
}
#' Wrap up a selection of summary functions from Hmisc to make it easy to use
diff --git a/R/stat-unique.r b/R/stat-unique.r
index 157a6f2..73a1a0d 100644
--- a/R/stat-unique.r
+++ b/R/stat-unique.r
@@ -4,15 +4,17 @@
#' \Sexpr[results=rd,stage=build]{ggplot2:::rd_aesthetics("stat", "unique")}
#'
#' @export
-#' @inheritParams stat_identity
-#' @param na.rm If \code{FALSE} (the default), removes missing values with
-#' a warning. If \code{TRUE} silently removes missing values.
+#' @inheritParams layer
+#' @inheritParams geom_point
#' @examples
#' ggplot(mtcars, aes(vs, am)) + geom_point(alpha = 0.1)
#' ggplot(mtcars, aes(vs, am)) + geom_point(alpha = 0.1, stat="unique")
-stat_unique <- function(mapping = NULL, data = NULL, geom = "point",
- position = "identity", na.rm = FALSE,
- show.legend = NA, inherit.aes = TRUE, ...) {
+stat_unique <- function(mapping = NULL, data = NULL,
+ geom = "point", position = "identity",
+ ...,
+ na.rm = FALSE,
+ show.legend = NA,
+ inherit.aes = TRUE) {
layer(
data = data,
mapping = mapping,
diff --git a/R/stat-ydensity.r b/R/stat-ydensity.r
index a2c34c3..bda4fe3 100644
--- a/R/stat-ydensity.r
+++ b/R/stat-ydensity.r
@@ -1,5 +1,6 @@
+#' @inheritParams layer
+#' @inheritParams geom_point
#' @inheritParams stat_density
-#' @inheritParams stat_identity
#' @param scale if "area" (default), all violins have the same area (before trimming
#' the tails). If "count", areas are scaled proportionally to the number of
#' observations. If "width", all violins have the same maximum width.
@@ -17,10 +18,17 @@
#' for examples with data along the x axis.
#' @export
#' @rdname geom_violin
-stat_ydensity <- function(mapping = NULL, data = NULL, geom = "violin",
- position = "dodge", adjust = 1, kernel = "gaussian",
- trim = TRUE, scale = "area", na.rm = FALSE,
- show.legend = NA, inherit.aes = TRUE, ...) {
+stat_ydensity <- function(mapping = NULL, data = NULL,
+ geom = "violin", position = "dodge",
+ ...,
+ bw = "nrd0",
+ adjust = 1,
+ kernel = "gaussian",
+ trim = TRUE,
+ scale = "area",
+ na.rm = FALSE,
+ show.legend = NA,
+ inherit.aes = TRUE) {
scale <- match.arg(scale, c("area", "count", "width"))
layer(
@@ -32,6 +40,7 @@ stat_ydensity <- function(mapping = NULL, data = NULL, geom = "violin",
show.legend = show.legend,
inherit.aes = inherit.aes,
params = list(
+ bw = bw,
adjust = adjust,
kernel = kernel,
trim = trim,
@@ -51,7 +60,7 @@ StatYdensity <- ggproto("StatYdensity", Stat,
required_aes = c("x", "y"),
non_missing_aes = "weight",
- compute_group = function(data, scales, width = NULL, adjust = 1,
+ compute_group = function(data, scales, width = NULL, bw = "nrd0", adjust = 1,
kernel = "gaussian", trim = TRUE, na.rm = FALSE) {
if (nrow(data) < 3) return(data.frame())
@@ -61,7 +70,7 @@ StatYdensity <- ggproto("StatYdensity", Stat,
range <- scales$y$dimension()
}
dens <- compute_density(data$y, data$w, from = range[1], to = range[2],
- adjust = adjust, kernel = kernel)
+ bw = bw, adjust = adjust, kernel = kernel)
dens$y <- dens$x
dens$x <- mean(range(data$x))
@@ -75,11 +84,11 @@ StatYdensity <- ggproto("StatYdensity", Stat,
dens
},
- compute_panel = function(self, data, scales, width = NULL, adjust = 1,
+ compute_panel = function(self, data, scales, width = NULL, bw = "nrd0", adjust = 1,
kernel = "gaussian", trim = TRUE, na.rm = FALSE,
scale = "area") {
data <- ggproto_parent(Stat, self)$compute_panel(
- data, scales, width = width, adjust = adjust, kernel = kernel,
+ data, scales, width = width, bw = bw, adjust = adjust, kernel = kernel,
trim = trim, na.rm = na.rm
)
diff --git a/R/theme-defaults.r b/R/theme-defaults.r
index 506ef1c..41e1ebc 100644
--- a/R/theme-defaults.r
+++ b/R/theme-defaults.r
@@ -49,6 +49,7 @@
#' p + theme_bw()
#' p + theme_linedraw()
#' p + theme_light()
+#' p + theme_dark()
#' p + theme_minimal()
#' p + theme_classic()
#' p + theme_void()
@@ -75,7 +76,9 @@ theme_grey <- function(base_size = 11, base_family = "") {
margin = margin(), debug = FALSE
),
- axis.line = element_blank(),
+ axis.line = element_line(),
+ axis.line.x = element_blank(),
+ axis.line.y = element_blank(),
axis.text = element_text(size = rel(0.8), colour = "grey30"),
axis.text.x = element_text(margin = margin(t = 0.8 * half_line / 2), vjust = 1),
axis.text.y = element_text(margin = margin(r = 0.8 * half_line / 2), hjust = 1),
@@ -86,7 +89,7 @@ theme_grey <- function(base_size = 11, base_family = "") {
),
axis.title.y = element_text(
angle = 90,
- margin = margin(r = 0.8 * half_line, l = 0.8 * half_line / 2),
+ margin = margin(r = 0.8 * half_line, l = 0.8 * half_line / 2)
),
legend.background = element_rect(colour = NA),
@@ -217,8 +220,10 @@ theme_minimal <- function(base_size = 12, base_family = "") {
panel.border = element_blank(),
strip.background = element_blank(),
plot.background = element_blank(),
- axis.ticks = element_blank(),
- axis.ticks.length = unit(0, "lines")
+ axis.ticks = element_line(),
+ axis.ticks.x = element_blank(),
+ axis.ticks.y = element_blank(),
+ axis.ticks.length = unit(1, "lines")
)
}
@@ -229,8 +234,12 @@ theme_classic <- function(base_size = 12, base_family = ""){
theme(
panel.border = element_blank(),
axis.line = element_line(colour = "black"),
- panel.grid.major = element_blank(),
- panel.grid.minor = element_blank(),
+ panel.grid.major = element_line(),
+ panel.grid.major.x = element_blank(),
+ panel.grid.major.y = element_blank(),
+ panel.grid.minor = element_line(),
+ panel.grid.minor.x = element_blank(),
+ panel.grid.minor.y = element_blank(),
strip.background = element_rect(colour = "black", size = 0.5),
legend.key = element_blank()
)
@@ -268,8 +277,20 @@ theme_void <- function(base_size = 12, base_family = "") {
# Use only inherited elements and make everything blank
line = element_blank(),
rect = element_blank(),
- text = element_blank(),
+ text = element_text(
+ family = base_family, face = "plain",
+ colour = "black", size = base_size,
+ lineheight = 0.9, hjust = 0.5, vjust = 0.5, angle = 0,
+ margin = margin(), debug = FALSE
+ ),
plot.margin = unit(c(0, 0, 0, 0), "lines"),
+ axis.text.x = element_blank(),
+ axis.text.y = element_blank(),
+ axis.title.x = element_blank(),
+ axis.title.y = element_blank(),
+ legend.text = element_text(size = rel(0.8)),
+ legend.title = element_blank(),
+ strip.text = element_text(size = rel(0.8)),
complete = TRUE
)
diff --git a/R/theme.r b/R/theme.r
index d8be07a..5934f89 100644
--- a/R/theme.r
+++ b/R/theme.r
@@ -1,7 +1,13 @@
#' Get, set and update themes.
#'
-#' Use \code{theme_update} to modify a small number of elements of the current
-#' theme or use \code{theme_set} to completely override it.
+#' Use \code{theme_get} to get the current theme, and \code{theme_set} to
+#' completely override it. \code{theme_update} and \code{theme_replace} are
+#' shorthands for changing individual elements in the current theme.
+#' \code{theme_update} uses the \code{+} operator, so that any unspecified
+#' values in the theme element will default to the values they are set in the
+#' theme. \code{theme_replace} will completely replace the element, so any
+#' unspecified values will overwrite the current value in the theme with \code{NULL}s.
+#'
#'
#' @param ... named list of theme settings
#' @seealso \code{\link{\%+replace\%}} and \code{\link{+.gg}}
@@ -15,19 +21,37 @@
#' theme_set(old)
#' p
#'
+#' #theme_replace NULLs out the fill attribute of panel.background,
+#' #resulting in a white background:
+#' theme_get()$panel.background
+#' old <- theme_replace(panel.background = element_rect(colour = "pink"))
+#' theme_get()$panel.background
+#' p
+#' theme_set(old)
+#'
+#' #theme_update only changes the colour attribute, leaving the others intact:
#' old <- theme_update(panel.background = element_rect(colour = "pink"))
+#' theme_get()$panel.background
#' p
#' theme_set(old)
+#'
#' theme_get()
#'
+#'
#' ggplot(mtcars, aes(mpg, wt)) +
#' geom_point(aes(color = mpg)) +
#' theme(legend.position = c(0.95, 0.95),
#' legend.justification = c(1, 1))
#' last_plot() +
#' theme(legend.background = element_rect(fill = "white", colour = "white", size = 3))
+#'
theme_update <- function(...) {
- # Make a call to theme, then add to theme
+ theme_set(theme_get() + theme(...))
+}
+
+#' @rdname theme_update
+#' @export
+theme_replace <- function(...) {
theme_set(theme_get() %+replace% theme(...))
}
@@ -316,35 +340,6 @@ print.theme <- function(x, ...) utils::str(x)
#' p + mytheme
#'
#' }
-#'
-#' \dontrun{
-#' ## Run this to generate a graph of the element inheritance tree
-#' build_element_graph <- function(tree) {
-#' require(igraph)
-#' require(plyr)
-#'
-#' inheritdf <- function(name, item) {
-#' if (length(item$inherit) == 0)
-#' data.frame()
-#' else
-#' data.frame(child = name, parent = item$inherit)
-#' }
-#'
-#' edges <- plyr::rbind.fill(mapply(inheritdf, names(tree), tree))
-#'
-#' # Explicitly add vertices (since not all are in edge list)
-#' vertices <- data.frame(name = names(tree))
-#' graph.data.frame(edges, vertices = vertices)
-#' }
-#'
-#' g <- build_element_graph(ggplot2:::.element_tree)
-#' V(g)$label <- V(g)$name
-#'
-#' set.seed(324)
-#' par(mar=c(0,0,0,0)) # Remove unnecessary margins
-#' plot(g, layout=layout.fruchterman.reingold, vertex.size=4, vertex.label.dist=.25)
-#'
-#' }
theme <- function(..., complete = FALSE, validate = TRUE) {
elements <- list(...)
diff --git a/R/translate-qplot-base.r b/R/translate-qplot-base.r
deleted file mode 100644
index 4863dbf..0000000
--- a/R/translate-qplot-base.r
+++ /dev/null
@@ -1,145 +0,0 @@
-#' Translating between qplot and base graphics
-#'
-#' There are two types of graphics functions in base graphics, those that draw
-#' complete graphics and those that add to existing graphics.
-#'
-#' qplot() has been designed to mimic plot(), and can do the job of all other
-#' high-level plotting commands. There are only two graph types from base
-#' graphics that cannot be replicated with ggplot2: filled.contour() and
-#' persp()
-#'
-#' @name translate_qplot_base
-#' @examples
-#' \donttest{
-#'
-#' # High-level plotting commands
-#'
-#' x <- runif(10)
-#' y <- 1:10
-#' plot(x, y); dotchart(x, y)
-#' qplot(x, y)
-#'
-#' plot(x, y, type = "l")
-#' qplot(x, y, geom = "line")
-#'
-#' plot(x, y, type = "s")
-#' qplot(x, y, geom = "step")
-#'
-#' plot(x, y, type = "b")
-#' qplot(x, y, geom = c("point", "line"))
-#'
-#' boxplot(x, y)
-#' qplot(x, y, geom = "boxplot")
-#'
-#' hist(x)
-#' qplot(x, geom = "histogram")
-#'
-#' # cdplot(factor(x), y)
-#' # qplot(x, fill = y, geom = "density", position = "fill")
-#'
-#' # coplot(y ~ x | a + b)
-#' # qplot(x, y, facets = a ~ b)
-#'
-#' # Many of the geoms are parameterised differently than base graphics. For
-#' # example, hist() is parameterised in terms of the number of bins, while
-#' # geom_histogram() is parameterised in terms of the width of each bin.
-#' hist(x, bins = 10)
-#' qplot(x, geom = "histogram", binwidth = .1)
-#'
-#' # qplot() often requires data in a slightly different format to the base
-#' # graphics functions. For example, the bar geom works with untabulated data,
-#' # not tabulated data like barplot(); the tile and contour geoms expect data
-#' # in a data frame, not a matrix like image() and contour().
-#' barplot(table(x))
-#' qplot(x, geom = "bar")
-#'
-#' barplot(x)
-#' qplot(seq_along(x), x, geom = "bar", stat = "identity")
-#'
-#' # image(x)
-#' # qplot(X1, X2, data = melt(x), geom = "tile", fill = value)
-#'
-#' # contour(x)
-#' # qplot(X1, X2, data = melt(x), geom = "contour", fill = value)
-#'
-#' # Generally, the base graphics functions work with individual vectors, not
-#' # data frames like ggplot2. qplot() will try to construct a data frame if one
-#' # is not specified, but it is not always possible. If you get strange errors,
-#' # you may need to create the data frame yourself.
-#' df <- data.frame(x = x, y = y)
-#' with(df, plot(x, y))
-#' qplot(x, y, data = df)
-#'
-#' # By default, qplot() maps values to aesthetics with a scale. To override
-#' # this behaviour and set aesthetics, overriding the defaults, you need to use I().
-#' plot(x, y, col = "red", cex = 1)
-#' qplot(x, y, colour = I("red"), size = I(1))
-#'
-#' # Low-level drawing
-#'
-#' # The low-level drawing functions which add to an existing plot are equivalent
-#' # to adding a new layer in ggplot2.
-#'
-#' # Base function ggplot2 layer
-#' # curve() geom_curve()
-#' # hline() geom_hline()
-#' # lines() geom_line()
-#' # points() geom_point()
-#' # polygon() geom_polygon()
-#' # rect() geom_rect()
-#' # rug() geom_rug()
-#' # segments() geom_segment()
-#' # text() geom_text()
-#' # vline() geom_vline()
-#' # abline(lm(y ~ x)) geom_smooth(method = "lm")
-#' # lines(density(x)) geom_density()
-#' # lines(loess(x, y)) geom_smooth()
-#'
-#' plot(x, y)
-#' lines(x, y)
-#'
-#' qplot(x, y) + geom_line()
-#'
-#' # Or, building up piece-meal
-#' qplot(x, y)
-#' last_plot() + geom_line()
-#'
-#' # Legends, axes and grid lines
-#'
-#' # In ggplot2, the appearance of legends and axes is controlled by the scales.
-#' # Axes are produced by the x and y scales, while all other scales produce legends.
-#' # See ?theme for help changing the appearance of axes and legends.
-#' # The appearance of grid lines is controlled by the grid.major and grid.minor
-#' # theme options, and their position by the breaks of the x and y scales.
-#'
-#' # Colour palettes
-#'
-#' # Instead of global colour palettes, ggplot2 has scales for individual plots. Much
-#' # of the time you can rely on the default colour scale (which has somewhat better
-#' # perceptual properties), but if you want to reuse an existing colour palette, you
-#' # can use scale_colour_manual(). You will need to make sure that the colour
-#' # is a factor for this to work.
-#'
-#' palette(rainbow(5))
-#' plot(1:5, 1:5, col = 1:5, pch = 19, cex = 4)
-#'
-#' qplot(1:5, 1:5, col = factor(1:5), size = I(4))
-#' last_plot() + scale_colour_manual(values = rainbow(5))
-#'
-#' # In ggplot2, you can also use palettes with continuous values,
-#' # with intermediate values being linearly interpolated.
-#'
-#' qplot(0:100, 0:100, col = 0:100, size = I(4)) +
-#' scale_colour_gradientn(colours = rainbow(7))
-#' last_plot() + scale_colour_gradientn(colours = terrain.colors(7))
-#'
-#' # Graphical parameters
-#'
-#' # The majority of par settings have some analogue within the theme system, or
-#' # in the defaults of the geoms and scales. The appearance plot border drawn
-#' # by box() can be controlled in a similar way by the panel.background and
-#' # plot.background theme elements. Instead of using title(), the plot title is
-#' # set with the title option. See ?theme for more theme elements.
-#' last_plot() + labs(title = "My Plot Title")
-#' }
-NULL
diff --git a/R/translate-qplot-lattice.r b/R/translate-qplot-lattice.r
index 67f0723..1a97b6e 100644
--- a/R/translate-qplot-lattice.r
+++ b/R/translate-qplot-lattice.r
@@ -1,12 +1,12 @@
#' Translating between qplot and lattice
#'
-#' The major difference between lattice and ggplot2 is that lattice uses a formula based
-#' interface. ggplot2 does not because the formula does not generalise well
-#' to more complicated situations.
+#' The major difference between lattice and ggplot2 is that lattice uses a
+#' formula based interface. ggplot2 does not because the formula does not
+#' generalise well to more complicated situations.
#'
#' @name translate_qplot_lattice
#' @examples
-#' \dontrun{
+#' \donttest{
#' library(lattice)
#'
#' if (require("ggplot2movies")) {
@@ -29,13 +29,10 @@
#' qplot(rating, data = movies, geom = "histogram")
#'
#' bwplot(Comedy ~ rating ,data = movies)
-#' qplot(factor(Comedy), rating, data = movies, type = "boxplot")
+#' qplot(factor(Comedy), rating, data = movies, geom = "boxplot")
#'
#' xyplot(wt ~ mpg, mtcars, type = c("p","smooth"))
#' qplot(mpg, wt, data = mtcars, geom = c("point","smooth"))
-#'
-#' xyplot(wt ~ mpg, mtcars, type = c("p","r"))
-#' qplot(mpg, wt, data = mtcars, geom = c("point","smooth"), method = "lm")
#' }
#'
#' # The capabilities for scale manipulations are similar in both ggplot2 and
diff --git a/R/utilities-grid.r b/R/utilities-grid.r
index c0089eb..dbf3950 100644
--- a/R/utilities-grid.r
+++ b/R/utilities-grid.r
@@ -16,10 +16,10 @@ ggname <- function(prefix, grob) {
width_cm <- function(x) {
if (is.grob(x)) {
convertWidth(grobWidth(x), "cm", TRUE)
- } else if (is.list(x)) {
- vapply(x, width_cm, numeric(1))
} else if (is.unit(x)) {
convertWidth(x, "cm", TRUE)
+ } else if (is.list(x)) {
+ vapply(x, width_cm, numeric(1))
} else {
stop("Unknown input")
}
@@ -27,10 +27,10 @@ width_cm <- function(x) {
height_cm <- function(x) {
if (is.grob(x)) {
convertWidth(grobHeight(x), "cm", TRUE)
- } else if (is.list(x)) {
- vapply(x, height_cm, numeric(1))
} else if (is.unit(x)) {
convertHeight(x, "cm", TRUE)
+ } else if (is.list(x)) {
+ vapply(x, height_cm, numeric(1))
} else {
stop("Unknown input")
}
diff --git a/R/zxx.r b/R/zxx.r
index 26e4a8d..e3d8e67 100644
--- a/R/zxx.r
+++ b/R/zxx.r
@@ -11,6 +11,20 @@ scale_colour_discrete <- scale_colour_hue
scale_colour_continuous <- scale_colour_gradient
#' @export
+#' @rdname scale_gradient
+#' @usage NULL
+scale_colour_datetime <- function() {
+ scale_colour_continuous(trans = "time")
+}
+
+#' @export
+#' @rdname scale_gradient
+#' @usage NULL
+scale_colour_date <- function() {
+ scale_colour_continuous(trans = "date")
+}
+
+#' @export
#' @rdname scale_hue
#' @usage NULL
scale_fill_discrete <- scale_fill_hue
@@ -20,6 +34,21 @@ scale_fill_discrete <- scale_fill_hue
#' @usage NULL
scale_fill_continuous <- scale_fill_gradient
+#' @export
+#' @rdname scale_gradient
+#' @usage NULL
+scale_fill_datetime <- function() {
+ scale_fill_continuous(trans = "time")
+}
+
+#' @export
+#' @rdname scale_gradient
+#' @usage NULL
+scale_fill_date <- function() {
+ scale_fill_continuous(trans = "date")
+}
+
+
# British to American spellings ----------------------------------------------
#' @export
diff --git a/build/partial.rdb b/build/partial.rdb
index 5121f70..4c7a641 100644
Binary files a/build/partial.rdb and b/build/partial.rdb differ
diff --git a/build/vignette.rds b/build/vignette.rds
index e14aa7d..df6db96 100644
Binary files a/build/vignette.rds and b/build/vignette.rds differ
diff --git a/inst/CITATION b/inst/CITATION
index a70c8ab..7d39367 100644
--- a/inst/CITATION
+++ b/inst/CITATION
@@ -6,6 +6,6 @@ citEntry(entry = "book",
publisher = "Springer-Verlag New York",
year = "2009",
isbn = "978-0-387-98140-6",
- url = "http://had.co.nz/ggplot2/book",
+ url = "http://ggplot2.org",
textVersion = "H. Wickham. ggplot2: Elegant Graphics for Data Analysis. Springer-Verlag New York, 2009."
-)
\ No newline at end of file
+)
diff --git a/inst/doc/extending-ggplot2.Rmd b/inst/doc/extending-ggplot2.Rmd
index 5040814..921c095 100644
--- a/inst/doc/extending-ggplot2.Rmd
+++ b/inst/doc/extending-ggplot2.Rmd
@@ -14,15 +14,15 @@ knitr::opts_chunk$set(collapse = TRUE, comment = "#>")
library(ggplot2)
```
-This vignette documents the official extension mechanism provided in ggplot2 1.1.0. This vignette is a high-level adjunct to the low-level details found in `?Stat`, `?Geom` and `?theme`. You'll learn how to extend ggplot2 by creating a new stat, geom, or theme.
+This vignette documents the official extension mechanism provided in ggplot2 2.0.0. This vignette is a high-level adjunct to the low-level details found in `?Stat`, `?Geom` and `?theme`. You'll learn how to extend ggplot2 by creating a new stat, geom, or theme.
-As you read this document, you'll see many things that will make you scratch your head and wonder why on earth is it designed this way? Mostly it's historical accident - I wasn't a terribly good R programmer when I started writing ggplot2 and I made a lot of questionable decisions. We cleaned up as many of those issues as possible in the 1.1.0 release, but some fixes simply weren't worth the effort.
+As you read this document, you'll see many things that will make you scratch your head and wonder why on earth is it designed this way? Mostly it's historical accident - I wasn't a terribly good R programmer when I started writing ggplot2 and I made a lot of questionable decisions. We cleaned up as many of those issues as possible in the 2.0.0 release, but some fixes simply weren't worth the effort.
## ggproto
All ggplot2 objects are built using the ggproto system of object oriented programming. This OO system is used only in one place: ggplot2. This is mostly historical accident: ggplot2 started off using [proto]( https://cran.r-project.org/package=proto) because I needed mutable objects. This was well before the creation of (the briefly lived) [mutatr](http://vita.had.co.nz/papers/mutatr.html), reference classes and R6: proto was the only game in town.
-But why ggproto? Well when we turned to add an official extension mechanism to ggplot2, we found a major problem that caused problems when proto objects were extended in a different package (methods were evaluated in ggplot2, not the package where the extension was added). We tried converting to R6, but it was a poor fit for the needs of ggplot2. We could've modified proto, but that would've first involved understand exactly how proto worked, and secondly making sure that the changes did [...]
+But why ggproto? Well when we turned to add an official extension mechanism to ggplot2, we found a major problem that caused problems when proto objects were extended in a different package (methods were evaluated in ggplot2, not the package where the extension was added). We tried converting to R6, but it was a poor fit for the needs of ggplot2. We could've modified proto, but that would've first involved understanding exactly how proto worked, and secondly making sure that the changes [...]
It's strange to say, but this is a case where inventing a new OO system was actually the right answer to the problem! Fortunately Winston is now very good at creating OO systems, so it only took him a day to come up with ggproto: it maintains all the features of proto that ggplot2 needs, while allowing cross package inheritance to work.
@@ -51,7 +51,7 @@ To create a new geom or stat, you will just create a new ggproto that inherits f
### The simplest stat
-We'll start by creating a very simple stat: one that gives the complex hull (the _c_ hull) of a set of points. First we create a new ggproto object that inherits from `Stat`:
+We'll start by creating a very simple stat: one that gives the convex hull (the _c_ hull) of a set of points. First we create a new ggproto object that inherits from `Stat`:
```{r chull}
StatChull <- ggproto("StatChull", Stat,
@@ -177,7 +177,7 @@ ggplot(mpg, aes(displ, hwy)) +
stat_lm(formula = y ~ poly(x, 10), geom = "point", colour = "red", n = 20)
```
-Note that don't _have_ to explicitly include the new parameters in the arguments for the layer, `...` will get passed to the right place anyway. But you'll need to document them somewhere so the user knows about them. Here's a brief example. Note `@inheritParams ggplot2::stat_identity`: that will automatically inherit documentation for all the parameters also defined for `stat_identity()`.
+Note that we don't _have_ to explicitly include the new parameters in the arguments for the layer, `...` will get passed to the right place anyway. But you'll need to document them somewhere so the user knows about them. Here's a brief example. Note `@inheritParams ggplot2::stat_identity`: that will automatically inherit documentation for all the parameters also defined for `stat_identity()`.
```{r}
#' @inheritParams ggplot2::stat_identity
@@ -199,7 +199,7 @@ stat_lm <- function(mapping = NULL, data = NULL, geom = "line",
### Picking defaults
-Sometimes you have calculations that should performed once for the complete dataset, not once for each group. This is useful for picking sensible default values. For example, if we want to do a density estimate, it's reasonable to pick one bandwidth for the whole plot. The following Stat creates a variation of the `stat_density()` that picks one bandwidth for all groups by choosing the mean of the "best" bandwidth for each group (I have no theoretical justification for this, but it doesn [...]
+Sometimes you have calculations that should be performed once for the complete dataset, not once for each group. This is useful for picking sensible default values. For example, if we want to do a density estimate, it's reasonable to pick one bandwidth for the whole plot. The following Stat creates a variation of the `stat_density()` that picks one bandwidth for all groups by choosing the mean of the "best" bandwidth for each group (I have no theoretical justification for this, but it do [...]
To do this we override the `setup_params()` method. It's passed the data and a list of params, and returns an updated list.
diff --git a/inst/doc/extending-ggplot2.html b/inst/doc/extending-ggplot2.html
index 4705f0c..baa2e91 100644
--- a/inst/doc/extending-ggplot2.html
+++ b/inst/doc/extending-ggplot2.html
@@ -7,10 +7,11 @@
<meta charset="utf-8">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="generator" content="pandoc" />
+<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="author" content="Hadley Wickham" />
-<meta name="date" content="2015-12-15" />
+<meta name="date" content="2016-02-29" />
<title>Extending ggplot2</title>
@@ -18,32 +19,45 @@
<style type="text/css">code{white-space: pre;}</style>
<style type="text/css">
+div.sourceCode { overflow-x: auto; }
table.sourceCode, tr.sourceCode, td.lineNumbers, td.sourceCode {
margin: 0; padding: 0; vertical-align: baseline; border: none; }
table.sourceCode { width: 100%; line-height: 100%; }
td.lineNumbers { text-align: right; padding-right: 4px; padding-left: 4px; color: #aaaaaa; border-right: 1px solid #aaaaaa; }
td.sourceCode { padding-left: 5px; }
-code > span.kw { color: #007020; font-weight: bold; }
-code > span.dt { color: #902000; }
-code > span.dv { color: #40a070; }
-code > span.bn { color: #40a070; }
-code > span.fl { color: #40a070; }
-code > span.ch { color: #4070a0; }
-code > span.st { color: #4070a0; }
-code > span.co { color: #60a0b0; font-style: italic; }
-code > span.ot { color: #007020; }
-code > span.al { color: #ff0000; font-weight: bold; }
-code > span.fu { color: #06287e; }
-code > span.er { color: #ff0000; font-weight: bold; }
-</style>
-<style type="text/css">
- pre:not([class]) {
- background-color: white;
- }
+code > span.kw { color: #007020; font-weight: bold; } /* Keyword */
+code > span.dt { color: #902000; } /* DataType */
+code > span.dv { color: #40a070; } /* DecVal */
+code > span.bn { color: #40a070; } /* BaseN */
+code > span.fl { color: #40a070; } /* Float */
+code > span.ch { color: #4070a0; } /* Char */
+code > span.st { color: #4070a0; } /* String */
+code > span.co { color: #60a0b0; font-style: italic; } /* Comment */
+code > span.ot { color: #007020; } /* Other */
+code > span.al { color: #ff0000; font-weight: bold; } /* Alert */
+code > span.fu { color: #06287e; } /* Function */
+code > span.er { color: #ff0000; font-weight: bold; } /* Error */
+code > span.wa { color: #60a0b0; font-weight: bold; font-style: italic; } /* Warning */
+code > span.cn { color: #880000; } /* Constant */
+code > span.sc { color: #4070a0; } /* SpecialChar */
+code > span.vs { color: #4070a0; } /* VerbatimString */
+code > span.ss { color: #bb6688; } /* SpecialString */
+code > span.im { } /* Import */
+code > span.va { color: #19177c; } /* Variable */
+code > span.cf { color: #007020; font-weight: bold; } /* ControlFlow */
+code > span.op { color: #666666; } /* Operator */
+code > span.bu { } /* BuiltIn */
+code > span.ex { } /* Extension */
+code > span.pp { color: #bc7a00; } /* Preprocessor */
+code > span.at { color: #7d9029; } /* Attribute */
+code > span.do { color: #ba2121; font-style: italic; } /* Documentation */
+code > span.an { color: #60a0b0; font-weight: bold; font-style: italic; } /* Annotation */
+code > span.cv { color: #60a0b0; font-weight: bold; font-style: italic; } /* CommentVar */
+code > span.in { color: #60a0b0; font-weight: bold; font-style: italic; } /* Information */
</style>
-<link href="data:text/css,body%20%7B%0A%20%20background%2Dcolor%3A%20%23fff%3B%0A%20%20margin%3A%201em%20auto%3B%0A%20%20max%2Dwidth%3A%20700px%3B%0A%20%20overflow%3A%20visible%3B%0A%20%20padding%2Dleft%3A%202em%3B%0A%20%20padding%2Dright%3A%202em%3B%0A%20%20font%2Dfamily%3A%20%22Open%20Sans%22%2C%20%22Helvetica%20Neue%22%2C%20Helvetica%2C%20Arial%2C%20sans%2Dserif%3B%0A%20%20font%2Dsize%3A%2014px%3B%0A%20%20line%2Dheight%3A%201%2E35%3B%0A%7D%0A%0A%23header%20%7B%0A%20%20text%2Dalign%3A% [...]
+<link href="data:text/css;charset=utf-8,body%20%7B%0Abackground%2Dcolor%3A%20%23fff%3B%0Amargin%3A%201em%20auto%3B%0Amax%2Dwidth%3A%20700px%3B%0Aoverflow%3A%20visible%3B%0Apadding%2Dleft%3A%202em%3B%0Apadding%2Dright%3A%202em%3B%0Afont%2Dfamily%3A%20%22Open%20Sans%22%2C%20%22Helvetica%20Neue%22%2C%20Helvetica%2C%20Arial%2C%20sans%2Dserif%3B%0Afont%2Dsize%3A%2014px%3B%0Aline%2Dheight%3A%201%2E35%3B%0A%7D%0A%23header%20%7B%0Atext%2Dalign%3A%20center%3B%0A%7D%0A%23TOC%20%7B%0Aclear%3A%20bot [...]
</head>
@@ -51,22 +65,25 @@ code > span.er { color: #ff0000; font-weight: bold; }
-<div id="header">
+<div class="fluid-row" id="header">
+
+
<h1 class="title">Extending ggplot2</h1>
<h4 class="author"><em>Hadley Wickham</em></h4>
-<h4 class="date"><em>2015-12-15</em></h4>
+<h4 class="date"><em>2016-02-29</em></h4>
+
</div>
-<p>This vignette documents the official extension mechanism provided in ggplot2 1.1.0. This vignette is a high-level adjunct to the low-level details found in <code>?Stat</code>, <code>?Geom</code> and <code>?theme</code>. You’ll learn how to extend ggplot2 by creating a new stat, geom, or theme.</p>
-<p>As you read this document, you’ll see many things that will make you scratch your head and wonder why on earth is it designed this way? Mostly it’s historical accident - I wasn’t a terribly good R programmer when I started writing ggplot2 and I made a lot of questionable decisions. We cleaned up as many of those issues as possible in the 1.1.0 release, but some fixes simply weren’t worth the effort.</p>
+<p>This vignette documents the official extension mechanism provided in ggplot2 2.0.0. This vignette is a high-level adjunct to the low-level details found in <code>?Stat</code>, <code>?Geom</code> and <code>?theme</code>. You’ll learn how to extend ggplot2 by creating a new stat, geom, or theme.</p>
+<p>As you read this document, you’ll see many things that will make you scratch your head and wonder why on earth is it designed this way? Mostly it’s historical accident - I wasn’t a terribly good R programmer when I started writing ggplot2 and I made a lot of questionable decisions. We cleaned up as many of those issues as possible in the 2.0.0 release, but some fixes simply weren’t worth the effort.</p>
<div id="ggproto" class="section level2">
<h2>ggproto</h2>
<p>All ggplot2 objects are built using the ggproto system of object oriented programming. This OO system is used only in one place: ggplot2. This is mostly historical accident: ggplot2 started off using <a href="https://cran.r-project.org/package=proto">proto</a> because I needed mutable objects. This was well before the creation of (the briefly lived) <a href="http://vita.had.co.nz/papers/mutatr.html">mutatr</a>, reference classes and R6: proto was the only game in town.</p>
-<p>But why ggproto? Well when we turned to add an official extension mechanism to ggplot2, we found a major problem that caused problems when proto objects were extended in a different package (methods were evaluated in ggplot2, not the package where the extension was added). We tried converting to R6, but it was a poor fit for the needs of ggplot2. We could’ve modified proto, but that would’ve first involved understand exactly how proto worked, and secondly making sure that the changes [...]
+<p>But why ggproto? Well when we turned to add an official extension mechanism to ggplot2, we found a major problem that caused problems when proto objects were extended in a different package (methods were evaluated in ggplot2, not the package where the extension was added). We tried converting to R6, but it was a poor fit for the needs of ggplot2. We could’ve modified proto, but that would’ve first involved understanding exactly how proto worked, and secondly making sure that the chang [...]
<p>It’s strange to say, but this is a case where inventing a new OO system was actually the right answer to the problem! Fortunately Winston is now very good at creating OO systems, so it only took him a day to come up with ggproto: it maintains all the features of proto that ggplot2 needs, while allowing cross package inheritance to work.</p>
<p>Here’s a quick demo of ggproto in action:</p>
-<pre class="sourceCode r"><code class="sourceCode r">A <-<span class="st"> </span><span class="kw">ggproto</span>(<span class="st">"A"</span>, <span class="ot">NULL</span>,
+<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r">A <-<span class="st"> </span><span class="kw">ggproto</span>(<span class="st">"A"</span>, <span class="ot">NULL</span>,
<span class="dt">x =</span> <span class="dv">1</span>,
<span class="dt">inc =</span> function(self) {
self$x <-<span class="st"> </span>self$x +<span class="st"> </span><span class="dv">1</span>
@@ -80,7 +97,7 @@ A$x
A$<span class="kw">inc</span>()
A$<span class="kw">inc</span>()
A$x
-<span class="co">#> [1] 4</span></code></pre>
+<span class="co">#> [1] 4</span></code></pre></div>
<p>The majority of ggplot2 classes are immutable and static: the methods neither use nor modify state in the class. They’re mostly used as a convenient way of bundling related methods together.</p>
<p>To create a new geom or stat, you will just create a new ggproto that inherits from <code>Stat</code>, <code>Geom</code> and override the methods described below.</p>
</div>
@@ -88,18 +105,18 @@ A$x
<h2>Creating a new stat</h2>
<div id="the-simplest-stat" class="section level3">
<h3>The simplest stat</h3>
-<p>We’ll start by creating a very simple stat: one that gives the complex hull (the <em>c</em> hull) of a set of points. First we create a new ggproto object that inherits from <code>Stat</code>:</p>
-<pre class="sourceCode r"><code class="sourceCode r">StatChull <-<span class="st"> </span><span class="kw">ggproto</span>(<span class="st">"StatChull"</span>, Stat,
+<p>We’ll start by creating a very simple stat: one that gives the convex hull (the <em>c</em> hull) of a set of points. First we create a new ggproto object that inherits from <code>Stat</code>:</p>
+<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r">StatChull <-<span class="st"> </span><span class="kw">ggproto</span>(<span class="st">"StatChull"</span>, Stat,
<span class="dt">compute_group =</span> function(data, scales) {
data[<span class="kw">chull</span>(data$x, data$y), , drop =<span class="st"> </span><span class="ot">FALSE</span>]
},
<span class="dt">required_aes =</span> <span class="kw">c</span>(<span class="st">"x"</span>, <span class="st">"y"</span>)
-)</code></pre>
+)</code></pre></div>
<p>The two most important components are the <code>compute_group()</code> method (which does the computation), and the <code>required_aes</code> field, which lists which aesthetics must be present in order to for the stat to work.</p>
<p>Next we write a layer function. Unfortunately, due to an early design mistake I called these either <code>stat_()</code> or <code>geom_()</code>. A better decision would have been to call them <code>layer_()</code> functions: that’s a more accurate description because every layer involves a stat <em>and</em> a geom.</p>
<p>All layer functions follow the same form - you specify defaults in the function arguments and then call the <code>layer()</code> function, sending <code>...</code> into the <code>params</code> argument. The arguments in <code>...</code> will either be arguments for the geom (if you’re making a stat wrapper), arguments for the stat (if you’re making a geom wrapper), or aesthetics to be set. <code>layer()</code> takes care of teasing the different parameters apart and making sure they’r [...]
-<pre class="sourceCode r"><code class="sourceCode r">stat_chull <-<span class="st"> </span>function(<span class="dt">mapping =</span> <span class="ot">NULL</span>, <span class="dt">data =</span> <span class="ot">NULL</span>, <span class="dt">geom =</span> <span class="st">"polygon"</span>,
+<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r">stat_chull <-<span class="st"> </span>function(<span class="dt">mapping =</span> <span class="ot">NULL</span>, <span class="dt">data =</span> <span class="ot">NULL</span>, <span class="dt">geom =</span> <span class="st">"polygon"</span>,
<span class="dt">position =</span> <span class="st">"identity"</span>, <span class="dt">na.rm =</span> <span class="ot">FALSE</span>, <span class="dt">show.legend =</span> <span class="ot">NA</span>,
<span class="dt">inherit.aes =</span> <span class="ot">TRUE</span>, ...) {
<span class="kw">layer</span>(
@@ -107,29 +124,29 @@ A$x
<span class="dt">position =</span> position, <span class="dt">show.legend =</span> show.legend, <span class="dt">inherit.aes =</span> inherit.aes,
<span class="dt">params =</span> <span class="kw">list</span>(<span class="dt">na.rm =</span> na.rm, ...)
)
-}</code></pre>
+}</code></pre></div>
<p>(Note that if you’re writing this in your own package, you’ll either need to call <code>ggplot2::layer()</code> explicitly, or import the <code>layer()</code> function into your package namespace.)</p>
<p>Once we have a layer function we can try our new stat:</p>
-<pre class="sourceCode r"><code class="sourceCode r"><span class="kw">ggplot</span>(mpg, <span class="kw">aes</span>(displ, hwy)) +<span class="st"> </span>
+<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="kw">ggplot</span>(mpg, <span class="kw">aes</span>(displ, hwy)) +<span class="st"> </span>
<span class="st"> </span><span class="kw">geom_point</span>() +<span class="st"> </span>
-<span class="st"> </span><span class="kw">stat_chull</span>(<span class="dt">fill =</span> <span class="ot">NA</span>, <span class="dt">colour =</span> <span class="st">"black"</span>)</code></pre>
-<p><img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAASAAAAEgCAYAAAAUg66AAAAEDWlDQ1BJQ0MgUHJvZmlsZQAAOI2NVV1oHFUUPrtzZyMkzlNsNIV0qD8NJQ2TVjShtLp/3d02bpZJNtoi6GT27s6Yyc44M7v9oU9FUHwx6psUxL+3gCAo9Q/bPrQvlQol2tQgKD60+INQ6Ium65k7M5lpurHeZe58853vnnvuuWfvBei5qliWkRQBFpquLRcy4nOHj4g9K5CEh6AXBqFXUR0rXalMAjZPC3e1W99Dwntf2dXd/p+tt0YdFSBxH2Kz5qgLiI8B8KdVy3YBevqRHz/qWh72Yui3MUDEL3q44WPXw3M+fo1pZuQs4tOIBVVTaoiXEI/MxfhGDPsxsNZfoE1q66ro5aJim3XdoLFw72H+n23BaIXzbcOnz5mfPoTvYVz7KzUl5+FRxEuqkp9G/Ajia [...]
+<span class="st"> </span><span class="kw">stat_chull</span>(<span class="dt">fill =</span> <span class="ot">NA</span>, <span class="dt">colour =</span> <span class="st">"black"</span>)</code></pre></div>
+<p><img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAASAAAAEgCAYAAAAUg66AAAAEDWlDQ1BJQ0MgUHJvZmlsZQAAOI2NVV1oHFUUPrtzZyMkzlNsNIV0qD8NJQ2TVjShtLp/3d02bpZJNtoi6GT27s6Yyc44M7v9oU9FUHwx6psUxL+3gCAo9Q/bPrQvlQol2tQgKD60+INQ6Ium65k7M5lpurHeZe58853vnnvuuWfvBei5qliWkRQBFpquLRcy4nOHj4g9K5CEh6AXBqFXUR0rXalMAjZPC3e1W99Dwntf2dXd/p+tt0YdFSBxH2Kz5qgLiI8B8KdVy3YBevqRHz/qWh72Yui3MUDEL3q44WPXw3M+fo1pZuQs4tOIBVVTaoiXEI/MxfhGDPsxsNZfoE1q66ro5aJim3XdoLFw72H+n23BaIXzbcOnz5mfPoTvYVz7KzUl5+FRxEuqkp9G/Ajia [...]
<p>(We’ll see later how to change the defaults of the geom so that you don’t need to specify <code>fill = NA</code> every time.)</p>
<p>Once we’ve written this basic object, ggplot2 gives a lot for free. For example, ggplot2 automatically preserves aesthetics that are constant within each group:</p>
-<pre class="sourceCode r"><code class="sourceCode r"><span class="kw">ggplot</span>(mpg, <span class="kw">aes</span>(displ, hwy, <span class="dt">colour =</span> drv)) +<span class="st"> </span>
+<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="kw">ggplot</span>(mpg, <span class="kw">aes</span>(displ, hwy, <span class="dt">colour =</span> drv)) +<span class="st"> </span>
<span class="st"> </span><span class="kw">geom_point</span>() +<span class="st"> </span>
-<span class="st"> </span><span class="kw">stat_chull</span>(<span class="dt">fill =</span> <span class="ot">NA</span>)</code></pre>
-<p><img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAASAAAAEgCAYAAAAUg66AAAAEDWlDQ1BJQ0MgUHJvZmlsZQAAOI2NVV1oHFUUPrtzZyMkzlNsNIV0qD8NJQ2TVjShtLp/3d02bpZJNtoi6GT27s6Yyc44M7v9oU9FUHwx6psUxL+3gCAo9Q/bPrQvlQol2tQgKD60+INQ6Ium65k7M5lpurHeZe58853vnnvuuWfvBei5qliWkRQBFpquLRcy4nOHj4g9K5CEh6AXBqFXUR0rXalMAjZPC3e1W99Dwntf2dXd/p+tt0YdFSBxH2Kz5qgLiI8B8KdVy3YBevqRHz/qWh72Yui3MUDEL3q44WPXw3M+fo1pZuQs4tOIBVVTaoiXEI/MxfhGDPsxsNZfoE1q66ro5aJim3XdoLFw72H+n23BaIXzbcOnz5mfPoTvYVz7KzUl5+FRxEuqkp9G/Ajia [...]
+<span class="st"> </span><span class="kw">stat_chull</span>(<span class="dt">fill =</span> <span class="ot">NA</span>)</code></pre></div>
+<p><img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAASAAAAEgCAYAAAAUg66AAAAEDWlDQ1BJQ0MgUHJvZmlsZQAAOI2NVV1oHFUUPrtzZyMkzlNsNIV0qD8NJQ2TVjShtLp/3d02bpZJNtoi6GT27s6Yyc44M7v9oU9FUHwx6psUxL+3gCAo9Q/bPrQvlQol2tQgKD60+INQ6Ium65k7M5lpurHeZe58853vnnvuuWfvBei5qliWkRQBFpquLRcy4nOHj4g9K5CEh6AXBqFXUR0rXalMAjZPC3e1W99Dwntf2dXd/p+tt0YdFSBxH2Kz5qgLiI8B8KdVy3YBevqRHz/qWh72Yui3MUDEL3q44WPXw3M+fo1pZuQs4tOIBVVTaoiXEI/MxfhGDPsxsNZfoE1q66ro5aJim3XdoLFw72H+n23BaIXzbcOnz5mfPoTvYVz7KzUl5+FRxEuqkp9G/Ajia [...]
<p>We can also override the default geom to display the convex hull in a different way:</p>
-<pre class="sourceCode r"><code class="sourceCode r"><span class="kw">ggplot</span>(mpg, <span class="kw">aes</span>(displ, hwy)) +<span class="st"> </span>
+<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="kw">ggplot</span>(mpg, <span class="kw">aes</span>(displ, hwy)) +<span class="st"> </span>
<span class="st"> </span><span class="kw">stat_chull</span>(<span class="dt">geom =</span> <span class="st">"point"</span>, <span class="dt">size =</span> <span class="dv">4</span>, <span class="dt">colour =</span> <span class="st">"red"</span>) +
-<span class="st"> </span><span class="kw">geom_point</span>()</code></pre>
-<p><img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAASAAAAEgCAYAAAAUg66AAAAEDWlDQ1BJQ0MgUHJvZmlsZQAAOI2NVV1oHFUUPrtzZyMkzlNsNIV0qD8NJQ2TVjShtLp/3d02bpZJNtoi6GT27s6Yyc44M7v9oU9FUHwx6psUxL+3gCAo9Q/bPrQvlQol2tQgKD60+INQ6Ium65k7M5lpurHeZe58853vnnvuuWfvBei5qliWkRQBFpquLRcy4nOHj4g9K5CEh6AXBqFXUR0rXalMAjZPC3e1W99Dwntf2dXd/p+tt0YdFSBxH2Kz5qgLiI8B8KdVy3YBevqRHz/qWh72Yui3MUDEL3q44WPXw3M+fo1pZuQs4tOIBVVTaoiXEI/MxfhGDPsxsNZfoE1q66ro5aJim3XdoLFw72H+n23BaIXzbcOnz5mfPoTvYVz7KzUl5+FRxEuqkp9G/Ajia [...]
+<span class="st"> </span><span class="kw">geom_point</span>()</code></pre></div>
+<p><img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAASAAAAEgCAYAAAAUg66AAAAEDWlDQ1BJQ0MgUHJvZmlsZQAAOI2NVV1oHFUUPrtzZyMkzlNsNIV0qD8NJQ2TVjShtLp/3d02bpZJNtoi6GT27s6Yyc44M7v9oU9FUHwx6psUxL+3gCAo9Q/bPrQvlQol2tQgKD60+INQ6Ium65k7M5lpurHeZe58853vnnvuuWfvBei5qliWkRQBFpquLRcy4nOHj4g9K5CEh6AXBqFXUR0rXalMAjZPC3e1W99Dwntf2dXd/p+tt0YdFSBxH2Kz5qgLiI8B8KdVy3YBevqRHz/qWh72Yui3MUDEL3q44WPXw3M+fo1pZuQs4tOIBVVTaoiXEI/MxfhGDPsxsNZfoE1q66ro5aJim3XdoLFw72H+n23BaIXzbcOnz5mfPoTvYVz7KzUl5+FRxEuqkp9G/Ajia [...]
</div>
<div id="stat-parameters" class="section level3">
<h3>Stat parameters</h3>
<p>A more complex stat will do some computation. Let’s implement a simple version of <code>geom_smooth()</code> that adds a line of best fit to a plot. We create a <code>StatLm</code> that inherits from <code>Stat</code> and a layer function, <code>stat_lm()</code>:</p>
-<pre class="sourceCode r"><code class="sourceCode r">StatLm <-<span class="st"> </span><span class="kw">ggproto</span>(<span class="st">"StatLm"</span>, Stat,
+<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r">StatLm <-<span class="st"> </span><span class="kw">ggproto</span>(<span class="st">"StatLm"</span>, Stat,
<span class="dt">required_aes =</span> <span class="kw">c</span>(<span class="st">"x"</span>, <span class="st">"y"</span>),
<span class="dt">compute_group =</span> function(data, scales) {
@@ -155,10 +172,10 @@ stat_lm <-<span class="st"> </span>function(<span class="dt">mapping =</span>
<span class="kw">ggplot</span>(mpg, <span class="kw">aes</span>(displ, hwy)) +<span class="st"> </span>
<span class="st"> </span><span class="kw">geom_point</span>() +<span class="st"> </span>
-<span class="st"> </span><span class="kw">stat_lm</span>()</code></pre>
-<p><img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAASAAAAEgCAYAAAAUg66AAAAEDWlDQ1BJQ0MgUHJvZmlsZQAAOI2NVV1oHFUUPrtzZyMkzlNsNIV0qD8NJQ2TVjShtLp/3d02bpZJNtoi6GT27s6Yyc44M7v9oU9FUHwx6psUxL+3gCAo9Q/bPrQvlQol2tQgKD60+INQ6Ium65k7M5lpurHeZe58853vnnvuuWfvBei5qliWkRQBFpquLRcy4nOHj4g9K5CEh6AXBqFXUR0rXalMAjZPC3e1W99Dwntf2dXd/p+tt0YdFSBxH2Kz5qgLiI8B8KdVy3YBevqRHz/qWh72Yui3MUDEL3q44WPXw3M+fo1pZuQs4tOIBVVTaoiXEI/MxfhGDPsxsNZfoE1q66ro5aJim3XdoLFw72H+n23BaIXzbcOnz5mfPoTvYVz7KzUl5+FRxEuqkp9G/Ajia [...]
+<span class="st"> </span><span class="kw">stat_lm</span>()</code></pre></div>
+<p><img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAASAAAAEgCAYAAAAUg66AAAAEDWlDQ1BJQ0MgUHJvZmlsZQAAOI2NVV1oHFUUPrtzZyMkzlNsNIV0qD8NJQ2TVjShtLp/3d02bpZJNtoi6GT27s6Yyc44M7v9oU9FUHwx6psUxL+3gCAo9Q/bPrQvlQol2tQgKD60+INQ6Ium65k7M5lpurHeZe58853vnnvuuWfvBei5qliWkRQBFpquLRcy4nOHj4g9K5CEh6AXBqFXUR0rXalMAjZPC3e1W99Dwntf2dXd/p+tt0YdFSBxH2Kz5qgLiI8B8KdVy3YBevqRHz/qWh72Yui3MUDEL3q44WPXw3M+fo1pZuQs4tOIBVVTaoiXEI/MxfhGDPsxsNZfoE1q66ro5aJim3XdoLFw72H+n23BaIXzbcOnz5mfPoTvYVz7KzUl5+FRxEuqkp9G/Ajia [...]
<p><code>StatLm</code> is inflexible because it has no parameters. We might want to allow the user to control the model formula and the number of points used to generate the grid. To do so, we add arguments to the <code>compute_group()</code> method and our wrapper function:</p>
-<pre class="sourceCode r"><code class="sourceCode r">StatLm <-<span class="st"> </span><span class="kw">ggproto</span>(<span class="st">"StatLm"</span>, Stat,
+<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r">StatLm <-<span class="st"> </span><span class="kw">ggproto</span>(<span class="st">"StatLm"</span>, Stat,
<span class="dt">required_aes =</span> <span class="kw">c</span>(<span class="st">"x"</span>, <span class="st">"y"</span>),
<span class="dt">compute_group =</span> function(data, scales, params, <span class="dt">n =</span> <span class="dv">100</span>, <span class="dt">formula =</span> y ~<span class="st"> </span>x) {
@@ -186,10 +203,10 @@ stat_lm <-<span class="st"> </span>function(<span class="dt">mapping =</span>
<span class="kw">ggplot</span>(mpg, <span class="kw">aes</span>(displ, hwy)) +<span class="st"> </span>
<span class="st"> </span><span class="kw">geom_point</span>() +<span class="st"> </span>
<span class="st"> </span><span class="kw">stat_lm</span>(<span class="dt">formula =</span> y ~<span class="st"> </span><span class="kw">poly</span>(x, <span class="dv">10</span>)) +<span class="st"> </span>
-<span class="st"> </span><span class="kw">stat_lm</span>(<span class="dt">formula =</span> y ~<span class="st"> </span><span class="kw">poly</span>(x, <span class="dv">10</span>), <span class="dt">geom =</span> <span class="st">"point"</span>, <span class="dt">colour =</span> <span class="st">"red"</span>, <span class="dt">n =</span> <span class="dv">20</span>)</code></pre>
-<p><img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAASAAAAEgCAYAAAAUg66AAAAEDWlDQ1BJQ0MgUHJvZmlsZQAAOI2NVV1oHFUUPrtzZyMkzlNsNIV0qD8NJQ2TVjShtLp/3d02bpZJNtoi6GT27s6Yyc44M7v9oU9FUHwx6psUxL+3gCAo9Q/bPrQvlQol2tQgKD60+INQ6Ium65k7M5lpurHeZe58853vnnvuuWfvBei5qliWkRQBFpquLRcy4nOHj4g9K5CEh6AXBqFXUR0rXalMAjZPC3e1W99Dwntf2dXd/p+tt0YdFSBxH2Kz5qgLiI8B8KdVy3YBevqRHz/qWh72Yui3MUDEL3q44WPXw3M+fo1pZuQs4tOIBVVTaoiXEI/MxfhGDPsxsNZfoE1q66ro5aJim3XdoLFw72H+n23BaIXzbcOnz5mfPoTvYVz7KzUl5+FRxEuqkp9G/Ajia [...]
-<p>Note that don’t <em>have</em> to explicitly include the new parameters in the arguments for the layer, <code>...</code> will get passed to the right place anyway. But you’ll need to document them somewhere so the user knows about them. Here’s a brief example. Note <code>@inheritParams ggplot2::stat_identity</code>: that will automatically inherit documentation for all the parameters also defined for <code>stat_identity()</code>.</p>
-<pre class="sourceCode r"><code class="sourceCode r"><span class="co">#' @inheritParams ggplot2::stat_identity</span>
+<span class="st"> </span><span class="kw">stat_lm</span>(<span class="dt">formula =</span> y ~<span class="st"> </span><span class="kw">poly</span>(x, <span class="dv">10</span>), <span class="dt">geom =</span> <span class="st">"point"</span>, <span class="dt">colour =</span> <span class="st">"red"</span>, <span class="dt">n =</span> <span class="dv">20</span>)</code></pre></div>
+<p><img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAASAAAAEgCAYAAAAUg66AAAAEDWlDQ1BJQ0MgUHJvZmlsZQAAOI2NVV1oHFUUPrtzZyMkzlNsNIV0qD8NJQ2TVjShtLp/3d02bpZJNtoi6GT27s6Yyc44M7v9oU9FUHwx6psUxL+3gCAo9Q/bPrQvlQol2tQgKD60+INQ6Ium65k7M5lpurHeZe58853vnnvuuWfvBei5qliWkRQBFpquLRcy4nOHj4g9K5CEh6AXBqFXUR0rXalMAjZPC3e1W99Dwntf2dXd/p+tt0YdFSBxH2Kz5qgLiI8B8KdVy3YBevqRHz/qWh72Yui3MUDEL3q44WPXw3M+fo1pZuQs4tOIBVVTaoiXEI/MxfhGDPsxsNZfoE1q66ro5aJim3XdoLFw72H+n23BaIXzbcOnz5mfPoTvYVz7KzUl5+FRxEuqkp9G/Ajia [...]
+<p>Note that we don’t <em>have</em> to explicitly include the new parameters in the arguments for the layer, <code>...</code> will get passed to the right place anyway. But you’ll need to document them somewhere so the user knows about them. Here’s a brief example. Note <code>@inheritParams ggplot2::stat_identity</code>: that will automatically inherit documentation for all the parameters also defined for <code>stat_identity()</code>.</p>
+<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="co">#' @inheritParams ggplot2::stat_identity</span>
<span class="co">#' @param formula The modelling formula passed to \code{lm}. Should only </span>
<span class="co">#' involve \code{y} and \code{x}</span>
<span class="co">#' @param n Number of points used for interpolation.</span>
@@ -202,13 +219,13 @@ stat_lm <-<span class="st"> </span>function(<span class="dt">mapping =</span>
<span class="dt">position =</span> position, <span class="dt">show.legend =</span> show.legend, <span class="dt">inherit.aes =</span> inherit.aes,
<span class="dt">params =</span> <span class="kw">list</span>(<span class="dt">n =</span> n, <span class="dt">formula =</span> formula, <span class="dt">na.rm =</span> na.rm, ...)
)
-}</code></pre>
+}</code></pre></div>
</div>
<div id="picking-defaults" class="section level3">
<h3>Picking defaults</h3>
-<p>Sometimes you have calculations that should performed once for the complete dataset, not once for each group. This is useful for picking sensible default values. For example, if we want to do a density estimate, it’s reasonable to pick one bandwidth for the whole plot. The following Stat creates a variation of the <code>stat_density()</code> that picks one bandwidth for all groups by choosing the mean of the “best” bandwidth for each group (I have no theoretical justification for this [...]
+<p>Sometimes you have calculations that should be performed once for the complete dataset, not once for each group. This is useful for picking sensible default values. For example, if we want to do a density estimate, it’s reasonable to pick one bandwidth for the whole plot. The following Stat creates a variation of the <code>stat_density()</code> that picks one bandwidth for all groups by choosing the mean of the “best” bandwidth for each group (I have no theoretical justification for t [...]
<p>To do this we override the <code>setup_params()</code> method. It’s passed the data and a list of params, and returns an updated list.</p>
-<pre class="sourceCode r"><code class="sourceCode r">StatDensityCommon <-<span class="st"> </span><span class="kw">ggproto</span>(<span class="st">"StatDensityCommon"</span>, Stat,
+<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r">StatDensityCommon <-<span class="st"> </span><span class="kw">ggproto</span>(<span class="st">"StatDensityCommon"</span>, Stat,
<span class="dt">required_aes =</span> <span class="st">"x"</span>,
<span class="dt">setup_params =</span> function(data, params) {
@@ -243,18 +260,18 @@ stat_density_common <-<span class="st"> </span>function(<span class="dt">mapp
<span class="kw">ggplot</span>(mpg, <span class="kw">aes</span>(displ, <span class="dt">colour =</span> drv)) +<span class="st"> </span>
<span class="st"> </span><span class="kw">stat_density_common</span>()
-<span class="co">#> Picking bandwidth of 0.345</span></code></pre>
-<p><img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAASAAAAEgCAYAAAAUg66AAAAEDWlDQ1BJQ0MgUHJvZmlsZQAAOI2NVV1oHFUUPrtzZyMkzlNsNIV0qD8NJQ2TVjShtLp/3d02bpZJNtoi6GT27s6Yyc44M7v9oU9FUHwx6psUxL+3gCAo9Q/bPrQvlQol2tQgKD60+INQ6Ium65k7M5lpurHeZe58853vnnvuuWfvBei5qliWkRQBFpquLRcy4nOHj4g9K5CEh6AXBqFXUR0rXalMAjZPC3e1W99Dwntf2dXd/p+tt0YdFSBxH2Kz5qgLiI8B8KdVy3YBevqRHz/qWh72Yui3MUDEL3q44WPXw3M+fo1pZuQs4tOIBVVTaoiXEI/MxfhGDPsxsNZfoE1q66ro5aJim3XdoLFw72H+n23BaIXzbcOnz5mfPoTvYVz7KzUl5+FRxEuqkp9G/Ajia [...]
-<pre class="sourceCode r"><code class="sourceCode r">
+<span class="co">#> Picking bandwidth of 0.345</span></code></pre></div>
+<p><img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAASAAAAEgCAYAAAAUg66AAAAEDWlDQ1BJQ0MgUHJvZmlsZQAAOI2NVV1oHFUUPrtzZyMkzlNsNIV0qD8NJQ2TVjShtLp/3d02bpZJNtoi6GT27s6Yyc44M7v9oU9FUHwx6psUxL+3gCAo9Q/bPrQvlQol2tQgKD60+INQ6Ium65k7M5lpurHeZe58853vnnvuuWfvBei5qliWkRQBFpquLRcy4nOHj4g9K5CEh6AXBqFXUR0rXalMAjZPC3e1W99Dwntf2dXd/p+tt0YdFSBxH2Kz5qgLiI8B8KdVy3YBevqRHz/qWh72Yui3MUDEL3q44WPXw3M+fo1pZuQs4tOIBVVTaoiXEI/MxfhGDPsxsNZfoE1q66ro5aJim3XdoLFw72H+n23BaIXzbcOnz5mfPoTvYVz7KzUl5+FRxEuqkp9G/Ajia [...]
+<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r">
<span class="kw">ggplot</span>(mpg, <span class="kw">aes</span>(displ, <span class="dt">colour =</span> drv)) +<span class="st"> </span>
-<span class="st"> </span><span class="kw">stat_density_common</span>(<span class="dt">bandwidth =</span> <span class="fl">0.5</span>)</code></pre>
-<p><img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAASAAAAEgCAYAAAAUg66AAAAEDWlDQ1BJQ0MgUHJvZmlsZQAAOI2NVV1oHFUUPrtzZyMkzlNsNIV0qD8NJQ2TVjShtLp/3d02bpZJNtoi6GT27s6Yyc44M7v9oU9FUHwx6psUxL+3gCAo9Q/bPrQvlQol2tQgKD60+INQ6Ium65k7M5lpurHeZe58853vnnvuuWfvBei5qliWkRQBFpquLRcy4nOHj4g9K5CEh6AXBqFXUR0rXalMAjZPC3e1W99Dwntf2dXd/p+tt0YdFSBxH2Kz5qgLiI8B8KdVy3YBevqRHz/qWh72Yui3MUDEL3q44WPXw3M+fo1pZuQs4tOIBVVTaoiXEI/MxfhGDPsxsNZfoE1q66ro5aJim3XdoLFw72H+n23BaIXzbcOnz5mfPoTvYVz7KzUl5+FRxEuqkp9G/Ajia [...]
+<span class="st"> </span><span class="kw">stat_density_common</span>(<span class="dt">bandwidth =</span> <span class="fl">0.5</span>)</code></pre></div>
+<p><img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAASAAAAEgCAYAAAAUg66AAAAEDWlDQ1BJQ0MgUHJvZmlsZQAAOI2NVV1oHFUUPrtzZyMkzlNsNIV0qD8NJQ2TVjShtLp/3d02bpZJNtoi6GT27s6Yyc44M7v9oU9FUHwx6psUxL+3gCAo9Q/bPrQvlQol2tQgKD60+INQ6Ium65k7M5lpurHeZe58853vnnvuuWfvBei5qliWkRQBFpquLRcy4nOHj4g9K5CEh6AXBqFXUR0rXalMAjZPC3e1W99Dwntf2dXd/p+tt0YdFSBxH2Kz5qgLiI8B8KdVy3YBevqRHz/qWh72Yui3MUDEL3q44WPXw3M+fo1pZuQs4tOIBVVTaoiXEI/MxfhGDPsxsNZfoE1q66ro5aJim3XdoLFw72H+n23BaIXzbcOnz5mfPoTvYVz7KzUl5+FRxEuqkp9G/Ajia [...]
<p>I recommend using <code>NULL</code> as a default value. If you pick important parameters automatically, it’s a good idea to <code>message()</code> to the user (and when printing a floating point parameter, using <code>signif()</code> to show only a few significant digits).</p>
</div>
<div id="variable-names-and-default-aesthetics" class="section level3">
<h3>Variable names and default aesthetics</h3>
<p>This stat illustrates another important point. If we want to make this stat usable with other geoms, we should return a variable called <code>density</code> instead of <code>y</code>. Then we can set up the <code>default_aes</code> to automatically map <code>density</code> to <code>y</code>, which allows the user to override it to use with different geoms:</p>
-<pre class="sourceCode r"><code class="sourceCode r">StatDensityCommon <-<span class="st"> </span><span class="kw">ggproto</span>(<span class="st">"StatDensity2"</span>, Stat,
+<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r">StatDensityCommon <-<span class="st"> </span><span class="kw">ggproto</span>(<span class="st">"StatDensity2"</span>, Stat,
<span class="dt">required_aes =</span> <span class="st">"x"</span>,
<span class="dt">default_aes =</span> <span class="kw">aes</span>(<span class="dt">y =</span> ..density..),
@@ -265,14 +282,14 @@ stat_density_common <-<span class="st"> </span>function(<span class="dt">mapp
)
<span class="kw">ggplot</span>(mpg, <span class="kw">aes</span>(displ, drv, <span class="dt">colour =</span> ..density..)) +<span class="st"> </span>
-<span class="st"> </span><span class="kw">stat_density_common</span>(<span class="dt">bandwidth =</span> <span class="dv">1</span>, <span class="dt">geom =</span> <span class="st">"point"</span>)</code></pre>
-<p><img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAASAAAAEgCAYAAAAUg66AAAAEDWlDQ1BJQ0MgUHJvZmlsZQAAOI2NVV1oHFUUPrtzZyMkzlNsNIV0qD8NJQ2TVjShtLp/3d02bpZJNtoi6GT27s6Yyc44M7v9oU9FUHwx6psUxL+3gCAo9Q/bPrQvlQol2tQgKD60+INQ6Ium65k7M5lpurHeZe58853vnnvuuWfvBei5qliWkRQBFpquLRcy4nOHj4g9K5CEh6AXBqFXUR0rXalMAjZPC3e1W99Dwntf2dXd/p+tt0YdFSBxH2Kz5qgLiI8B8KdVy3YBevqRHz/qWh72Yui3MUDEL3q44WPXw3M+fo1pZuQs4tOIBVVTaoiXEI/MxfhGDPsxsNZfoE1q66ro5aJim3XdoLFw72H+n23BaIXzbcOnz5mfPoTvYVz7KzUl5+FRxEuqkp9G/Ajia [...]
+<span class="st"> </span><span class="kw">stat_density_common</span>(<span class="dt">bandwidth =</span> <span class="dv">1</span>, <span class="dt">geom =</span> <span class="st">"point"</span>)</code></pre></div>
+<p><img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAASAAAAEgCAYAAAAUg66AAAAEDWlDQ1BJQ0MgUHJvZmlsZQAAOI2NVV1oHFUUPrtzZyMkzlNsNIV0qD8NJQ2TVjShtLp/3d02bpZJNtoi6GT27s6Yyc44M7v9oU9FUHwx6psUxL+3gCAo9Q/bPrQvlQol2tQgKD60+INQ6Ium65k7M5lpurHeZe58853vnnvuuWfvBei5qliWkRQBFpquLRcy4nOHj4g9K5CEh6AXBqFXUR0rXalMAjZPC3e1W99Dwntf2dXd/p+tt0YdFSBxH2Kz5qgLiI8B8KdVy3YBevqRHz/qWh72Yui3MUDEL3q44WPXw3M+fo1pZuQs4tOIBVVTaoiXEI/MxfhGDPsxsNZfoE1q66ro5aJim3XdoLFw72H+n23BaIXzbcOnz5mfPoTvYVz7KzUl5+FRxEuqkp9G/Ajia [...]
<p>However, using this stat with the area geom doesn’t work quite right. The areas don’t stack on top of each other:</p>
-<pre class="sourceCode r"><code class="sourceCode r"><span class="kw">ggplot</span>(mpg, <span class="kw">aes</span>(displ, <span class="dt">fill =</span> drv)) +<span class="st"> </span>
-<span class="st"> </span><span class="kw">stat_density_common</span>(<span class="dt">bandwidth =</span> <span class="dv">1</span>, <span class="dt">geom =</span> <span class="st">"area"</span>, <span class="dt">position =</span> <span class="st">"stack"</span>)</code></pre>
-<p><img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAASAAAAEgCAYAAAAUg66AAAAEDWlDQ1BJQ0MgUHJvZmlsZQAAOI2NVV1oHFUUPrtzZyMkzlNsNIV0qD8NJQ2TVjShtLp/3d02bpZJNtoi6GT27s6Yyc44M7v9oU9FUHwx6psUxL+3gCAo9Q/bPrQvlQol2tQgKD60+INQ6Ium65k7M5lpurHeZe58853vnnvuuWfvBei5qliWkRQBFpquLRcy4nOHj4g9K5CEh6AXBqFXUR0rXalMAjZPC3e1W99Dwntf2dXd/p+tt0YdFSBxH2Kz5qgLiI8B8KdVy3YBevqRHz/qWh72Yui3MUDEL3q44WPXw3M+fo1pZuQs4tOIBVVTaoiXEI/MxfhGDPsxsNZfoE1q66ro5aJim3XdoLFw72H+n23BaIXzbcOnz5mfPoTvYVz7KzUl5+FRxEuqkp9G/Ajia [...]
+<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="kw">ggplot</span>(mpg, <span class="kw">aes</span>(displ, <span class="dt">fill =</span> drv)) +<span class="st"> </span>
+<span class="st"> </span><span class="kw">stat_density_common</span>(<span class="dt">bandwidth =</span> <span class="dv">1</span>, <span class="dt">geom =</span> <span class="st">"area"</span>, <span class="dt">position =</span> <span class="st">"stack"</span>)</code></pre></div>
+<p><img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAASAAAAEgCAYAAAAUg66AAAAEDWlDQ1BJQ0MgUHJvZmlsZQAAOI2NVV1oHFUUPrtzZyMkzlNsNIV0qD8NJQ2TVjShtLp/3d02bpZJNtoi6GT27s6Yyc44M7v9oU9FUHwx6psUxL+3gCAo9Q/bPrQvlQol2tQgKD60+INQ6Ium65k7M5lpurHeZe58853vnnvuuWfvBei5qliWkRQBFpquLRcy4nOHj4g9K5CEh6AXBqFXUR0rXalMAjZPC3e1W99Dwntf2dXd/p+tt0YdFSBxH2Kz5qgLiI8B8KdVy3YBevqRHz/qWh72Yui3MUDEL3q44WPXw3M+fo1pZuQs4tOIBVVTaoiXEI/MxfhGDPsxsNZfoE1q66ro5aJim3XdoLFw72H+n23BaIXzbcOnz5mfPoTvYVz7KzUl5+FRxEuqkp9G/Ajia [...]
<p>This is because each density is computed independently, and the estimated <code>x</code>s don’t line up. We can resolve that issue by computing the range of the data once in <code>setup_params()</code>.</p>
-<pre class="sourceCode r"><code class="sourceCode r">StatDensityCommon <-<span class="st"> </span><span class="kw">ggproto</span>(<span class="st">"StatDensityCommon"</span>, Stat,
+<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r">StatDensityCommon <-<span class="st"> </span><span class="kw">ggproto</span>(<span class="st">"StatDensityCommon"</span>, Stat,
<span class="dt">required_aes =</span> <span class="st">"x"</span>,
<span class="dt">default_aes =</span> <span class="kw">aes</span>(<span class="dt">y =</span> ..density..),
@@ -295,11 +312,11 @@ stat_density_common <-<span class="st"> </span>function(<span class="dt">mapp
)
<span class="kw">ggplot</span>(mpg, <span class="kw">aes</span>(displ, <span class="dt">fill =</span> drv)) +<span class="st"> </span>
-<span class="st"> </span><span class="kw">stat_density_common</span>(<span class="dt">bandwidth =</span> <span class="dv">1</span>, <span class="dt">geom =</span> <span class="st">"area"</span>, <span class="dt">position =</span> <span class="st">"stack"</span>)</code></pre>
-<p><img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAASAAAAEgCAYAAAAUg66AAAAEDWlDQ1BJQ0MgUHJvZmlsZQAAOI2NVV1oHFUUPrtzZyMkzlNsNIV0qD8NJQ2TVjShtLp/3d02bpZJNtoi6GT27s6Yyc44M7v9oU9FUHwx6psUxL+3gCAo9Q/bPrQvlQol2tQgKD60+INQ6Ium65k7M5lpurHeZe58853vnnvuuWfvBei5qliWkRQBFpquLRcy4nOHj4g9K5CEh6AXBqFXUR0rXalMAjZPC3e1W99Dwntf2dXd/p+tt0YdFSBxH2Kz5qgLiI8B8KdVy3YBevqRHz/qWh72Yui3MUDEL3q44WPXw3M+fo1pZuQs4tOIBVVTaoiXEI/MxfhGDPsxsNZfoE1q66ro5aJim3XdoLFw72H+n23BaIXzbcOnz5mfPoTvYVz7KzUl5+FRxEuqkp9G/Ajia [...]
-<pre class="sourceCode r"><code class="sourceCode r"><span class="kw">ggplot</span>(mpg, <span class="kw">aes</span>(displ, drv, <span class="dt">fill =</span> ..density..)) +<span class="st"> </span>
-<span class="st"> </span><span class="kw">stat_density_common</span>(<span class="dt">bandwidth =</span> <span class="dv">1</span>, <span class="dt">geom =</span> <span class="st">"raster"</span>)</code></pre>
-<p><img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAASAAAAEgCAYAAAAUg66AAAAEDWlDQ1BJQ0MgUHJvZmlsZQAAOI2NVV1oHFUUPrtzZyMkzlNsNIV0qD8NJQ2TVjShtLp/3d02bpZJNtoi6GT27s6Yyc44M7v9oU9FUHwx6psUxL+3gCAo9Q/bPrQvlQol2tQgKD60+INQ6Ium65k7M5lpurHeZe58853vnnvuuWfvBei5qliWkRQBFpquLRcy4nOHj4g9K5CEh6AXBqFXUR0rXalMAjZPC3e1W99Dwntf2dXd/p+tt0YdFSBxH2Kz5qgLiI8B8KdVy3YBevqRHz/qWh72Yui3MUDEL3q44WPXw3M+fo1pZuQs4tOIBVVTaoiXEI/MxfhGDPsxsNZfoE1q66ro5aJim3XdoLFw72H+n23BaIXzbcOnz5mfPoTvYVz7KzUl5+FRxEuqkp9G/Ajia [...]
+<span class="st"> </span><span class="kw">stat_density_common</span>(<span class="dt">bandwidth =</span> <span class="dv">1</span>, <span class="dt">geom =</span> <span class="st">"area"</span>, <span class="dt">position =</span> <span class="st">"stack"</span>)</code></pre></div>
+<p><img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAASAAAAEgCAYAAAAUg66AAAAEDWlDQ1BJQ0MgUHJvZmlsZQAAOI2NVV1oHFUUPrtzZyMkzlNsNIV0qD8NJQ2TVjShtLp/3d02bpZJNtoi6GT27s6Yyc44M7v9oU9FUHwx6psUxL+3gCAo9Q/bPrQvlQol2tQgKD60+INQ6Ium65k7M5lpurHeZe58853vnnvuuWfvBei5qliWkRQBFpquLRcy4nOHj4g9K5CEh6AXBqFXUR0rXalMAjZPC3e1W99Dwntf2dXd/p+tt0YdFSBxH2Kz5qgLiI8B8KdVy3YBevqRHz/qWh72Yui3MUDEL3q44WPXw3M+fo1pZuQs4tOIBVVTaoiXEI/MxfhGDPsxsNZfoE1q66ro5aJim3XdoLFw72H+n23BaIXzbcOnz5mfPoTvYVz7KzUl5+FRxEuqkp9G/Ajia [...]
+<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="kw">ggplot</span>(mpg, <span class="kw">aes</span>(displ, drv, <span class="dt">fill =</span> ..density..)) +<span class="st"> </span>
+<span class="st"> </span><span class="kw">stat_density_common</span>(<span class="dt">bandwidth =</span> <span class="dv">1</span>, <span class="dt">geom =</span> <span class="st">"raster"</span>)</code></pre></div>
+<p><img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAASAAAAEgCAYAAAAUg66AAAAEDWlDQ1BJQ0MgUHJvZmlsZQAAOI2NVV1oHFUUPrtzZyMkzlNsNIV0qD8NJQ2TVjShtLp/3d02bpZJNtoi6GT27s6Yyc44M7v9oU9FUHwx6psUxL+3gCAo9Q/bPrQvlQol2tQgKD60+INQ6Ium65k7M5lpurHeZe58853vnnvuuWfvBei5qliWkRQBFpquLRcy4nOHj4g9K5CEh6AXBqFXUR0rXalMAjZPC3e1W99Dwntf2dXd/p+tt0YdFSBxH2Kz5qgLiI8B8KdVy3YBevqRHz/qWh72Yui3MUDEL3q44WPXw3M+fo1pZuQs4tOIBVVTaoiXEI/MxfhGDPsxsNZfoE1q66ro5aJim3XdoLFw72H+n23BaIXzbcOnz5mfPoTvYVz7KzUl5+FRxEuqkp9G/Ajia [...]
</div>
<div id="exercises" class="section level3">
<h3>Exercises</h3>
@@ -316,7 +333,7 @@ stat_density_common <-<span class="st"> </span>function(<span class="dt">mapp
<div id="a-simple-geom" class="section level3">
<h3>A simple geom</h3>
<p>It’s easiest to start with a simple example. The code below is a simplified version of <code>geom_point()</code>:</p>
-<pre class="sourceCode r"><code class="sourceCode r">GeomSimplePoint <-<span class="st"> </span><span class="kw">ggproto</span>(<span class="st">"GeomSimplePoint"</span>, Geom,
+<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r">GeomSimplePoint <-<span class="st"> </span><span class="kw">ggproto</span>(<span class="st">"GeomSimplePoint"</span>, Geom,
<span class="dt">required_aes =</span> <span class="kw">c</span>(<span class="st">"x"</span>, <span class="st">"y"</span>),
<span class="dt">default_aes =</span> <span class="kw">aes</span>(<span class="dt">shape =</span> <span class="dv">19</span>, <span class="dt">colour =</span> <span class="st">"black"</span>),
<span class="dt">draw_key =</span> draw_key_point,
@@ -342,8 +359,8 @@ geom_simple_point <-<span class="st"> </span>function(<span class="dt">mappin
}
<span class="kw">ggplot</span>(mpg, <span class="kw">aes</span>(displ, hwy)) +<span class="st"> </span>
-<span class="st"> </span><span class="kw">geom_simple_point</span>()</code></pre>
-<p><img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAASAAAAEgCAYAAAAUg66AAAAEDWlDQ1BJQ0MgUHJvZmlsZQAAOI2NVV1oHFUUPrtzZyMkzlNsNIV0qD8NJQ2TVjShtLp/3d02bpZJNtoi6GT27s6Yyc44M7v9oU9FUHwx6psUxL+3gCAo9Q/bPrQvlQol2tQgKD60+INQ6Ium65k7M5lpurHeZe58853vnnvuuWfvBei5qliWkRQBFpquLRcy4nOHj4g9K5CEh6AXBqFXUR0rXalMAjZPC3e1W99Dwntf2dXd/p+tt0YdFSBxH2Kz5qgLiI8B8KdVy3YBevqRHz/qWh72Yui3MUDEL3q44WPXw3M+fo1pZuQs4tOIBVVTaoiXEI/MxfhGDPsxsNZfoE1q66ro5aJim3XdoLFw72H+n23BaIXzbcOnz5mfPoTvYVz7KzUl5+FRxEuqkp9G/Ajia [...]
+<span class="st"> </span><span class="kw">geom_simple_point</span>()</code></pre></div>
+<p><img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAASAAAAEgCAYAAAAUg66AAAAEDWlDQ1BJQ0MgUHJvZmlsZQAAOI2NVV1oHFUUPrtzZyMkzlNsNIV0qD8NJQ2TVjShtLp/3d02bpZJNtoi6GT27s6Yyc44M7v9oU9FUHwx6psUxL+3gCAo9Q/bPrQvlQol2tQgKD60+INQ6Ium65k7M5lpurHeZe58853vnnvuuWfvBei5qliWkRQBFpquLRcy4nOHj4g9K5CEh6AXBqFXUR0rXalMAjZPC3e1W99Dwntf2dXd/p+tt0YdFSBxH2Kz5qgLiI8B8KdVy3YBevqRHz/qWh72Yui3MUDEL3q44WPXw3M+fo1pZuQs4tOIBVVTaoiXEI/MxfhGDPsxsNZfoE1q66ro5aJim3XdoLFw72H+n23BaIXzbcOnz5mfPoTvYVz7KzUl5+FRxEuqkp9G/Ajia [...]
<p>This is very similar to defining a new stat. You always need to provide fields/methods for the four pieces shown above:</p>
<ul>
<li><p><code>required_aes</code> is a character vector which lists all the aesthetics that the user must provide.</p></li>
@@ -363,7 +380,7 @@ geom_simple_point <-<span class="st"> </span>function(<span class="dt">mappin
<h3>Collective geoms</h3>
<p>Overriding <code>draw_panel()</code> is most appropriate if there is one graphic element per row. In other cases, you want graphic element per group. For example, take polygons: each row gives one vertex of a polygon. In this case, you should instead override <code>draw_group()</code>:</p>
<p>The following code makes a simplified version of <code>GeomPolygon</code>:</p>
-<pre class="sourceCode r"><code class="sourceCode r">GeomSimplePolygon <-<span class="st"> </span><span class="kw">ggproto</span>(<span class="st">"GeomPolygon"</span>, Geom,
+<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r">GeomSimplePolygon <-<span class="st"> </span><span class="kw">ggproto</span>(<span class="st">"GeomPolygon"</span>, Geom,
<span class="dt">required_aes =</span> <span class="kw">c</span>(<span class="st">"x"</span>, <span class="st">"y"</span>),
<span class="dt">default_aes =</span> <span class="kw">aes</span>(
@@ -405,8 +422,8 @@ geom_simple_polygon <-<span class="st"> </span>function(<span class="dt">mapp
<span class="kw">ggplot</span>(mpg, <span class="kw">aes</span>(displ, hwy)) +<span class="st"> </span>
<span class="st"> </span><span class="kw">geom_point</span>() +<span class="st"> </span>
-<span class="st"> </span><span class="kw">geom_simple_polygon</span>(<span class="kw">aes</span>(<span class="dt">colour =</span> class), <span class="dt">fill =</span> <span class="ot">NA</span>)</code></pre>
-<p><img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAASAAAAEgCAYAAAAUg66AAAAEDWlDQ1BJQ0MgUHJvZmlsZQAAOI2NVV1oHFUUPrtzZyMkzlNsNIV0qD8NJQ2TVjShtLp/3d02bpZJNtoi6GT27s6Yyc44M7v9oU9FUHwx6psUxL+3gCAo9Q/bPrQvlQol2tQgKD60+INQ6Ium65k7M5lpurHeZe58853vnnvuuWfvBei5qliWkRQBFpquLRcy4nOHj4g9K5CEh6AXBqFXUR0rXalMAjZPC3e1W99Dwntf2dXd/p+tt0YdFSBxH2Kz5qgLiI8B8KdVy3YBevqRHz/qWh72Yui3MUDEL3q44WPXw3M+fo1pZuQs4tOIBVVTaoiXEI/MxfhGDPsxsNZfoE1q66ro5aJim3XdoLFw72H+n23BaIXzbcOnz5mfPoTvYVz7KzUl5+FRxEuqkp9G/Ajia [...]
+<span class="st"> </span><span class="kw">geom_simple_polygon</span>(<span class="kw">aes</span>(<span class="dt">colour =</span> class), <span class="dt">fill =</span> <span class="ot">NA</span>)</code></pre></div>
+<p><img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAASAAAAEgCAYAAAAUg66AAAAEDWlDQ1BJQ0MgUHJvZmlsZQAAOI2NVV1oHFUUPrtzZyMkzlNsNIV0qD8NJQ2TVjShtLp/3d02bpZJNtoi6GT27s6Yyc44M7v9oU9FUHwx6psUxL+3gCAo9Q/bPrQvlQol2tQgKD60+INQ6Ium65k7M5lpurHeZe58853vnnvuuWfvBei5qliWkRQBFpquLRcy4nOHj4g9K5CEh6AXBqFXUR0rXalMAjZPC3e1W99Dwntf2dXd/p+tt0YdFSBxH2Kz5qgLiI8B8KdVy3YBevqRHz/qWh72Yui3MUDEL3q44WPXw3M+fo1pZuQs4tOIBVVTaoiXEI/MxfhGDPsxsNZfoE1q66ro5aJim3XdoLFw72H+n23BaIXzbcOnz5mfPoTvYVz7KzUl5+FRxEuqkp9G/Ajia [...]
<p>There are a few things to note here:</p>
<ul>
<li><p>We override <code>draw_group()</code> instead of <code>draw_layer()</code> because we want one polygon per group, not one polygon per row. If you look at the source code for the original <code>GeomPolygon</code> you’ll see it actually overrides <code>geom_layer()</code> because it uses some tricks to make <code>polygonGrob()</code> produce multiple polygons in one call. This is considerably more complicated, but gives better performance.</p></li>
@@ -417,7 +434,7 @@ geom_simple_polygon <-<span class="st"> </span>function(<span class="dt">mapp
<div id="inheriting-from-an-existing-geom" class="section level3">
<h3>Inheriting from an existing Geom</h3>
<p>Sometimes you just want to make a small modification to an existing geom. In this case, rather than inheriting from <code>Geom</code> you can inherit from an existing subclass. For example, we might want to change the defaults for <code>GeomPolygon</code> to work better with <code>StatChull</code>:</p>
-<pre class="sourceCode r"><code class="sourceCode r">GeomPolygonHollow <-<span class="st"> </span><span class="kw">ggproto</span>(<span class="st">"GeomPolygonHollow"</span>, GeomPolygon,
+<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r">GeomPolygonHollow <-<span class="st"> </span><span class="kw">ggproto</span>(<span class="st">"GeomPolygonHollow"</span>, GeomPolygon,
<span class="dt">default_aes =</span> <span class="kw">aes</span>(<span class="dt">colour =</span> <span class="st">"black"</span>, <span class="dt">fill =</span> <span class="ot">NA</span>, <span class="dt">size =</span> <span class="fl">0.5</span>, <span class="dt">linetype =</span> <span class="dv">1</span>,
<span class="dt">alpha =</span> <span class="ot">NA</span>)
)
@@ -433,8 +450,8 @@ geom_chull <-<span class="st"> </span>function(<span class="dt">mapping =</sp
<span class="kw">ggplot</span>(mpg, <span class="kw">aes</span>(displ, hwy)) +<span class="st"> </span>
<span class="st"> </span><span class="kw">geom_point</span>() +<span class="st"> </span>
-<span class="st"> </span><span class="kw">geom_chull</span>()</code></pre>
-<p><img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAASAAAAEgCAYAAAAUg66AAAAEDWlDQ1BJQ0MgUHJvZmlsZQAAOI2NVV1oHFUUPrtzZyMkzlNsNIV0qD8NJQ2TVjShtLp/3d02bpZJNtoi6GT27s6Yyc44M7v9oU9FUHwx6psUxL+3gCAo9Q/bPrQvlQol2tQgKD60+INQ6Ium65k7M5lpurHeZe58853vnnvuuWfvBei5qliWkRQBFpquLRcy4nOHj4g9K5CEh6AXBqFXUR0rXalMAjZPC3e1W99Dwntf2dXd/p+tt0YdFSBxH2Kz5qgLiI8B8KdVy3YBevqRHz/qWh72Yui3MUDEL3q44WPXw3M+fo1pZuQs4tOIBVVTaoiXEI/MxfhGDPsxsNZfoE1q66ro5aJim3XdoLFw72H+n23BaIXzbcOnz5mfPoTvYVz7KzUl5+FRxEuqkp9G/Ajia [...]
+<span class="st"> </span><span class="kw">geom_chull</span>()</code></pre></div>
+<p><img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAASAAAAEgCAYAAAAUg66AAAAEDWlDQ1BJQ0MgUHJvZmlsZQAAOI2NVV1oHFUUPrtzZyMkzlNsNIV0qD8NJQ2TVjShtLp/3d02bpZJNtoi6GT27s6Yyc44M7v9oU9FUHwx6psUxL+3gCAo9Q/bPrQvlQol2tQgKD60+INQ6Ium65k7M5lpurHeZe58853vnnvuuWfvBei5qliWkRQBFpquLRcy4nOHj4g9K5CEh6AXBqFXUR0rXalMAjZPC3e1W99Dwntf2dXd/p+tt0YdFSBxH2Kz5qgLiI8B8KdVy3YBevqRHz/qWh72Yui3MUDEL3q44WPXw3M+fo1pZuQs4tOIBVVTaoiXEI/MxfhGDPsxsNZfoE1q66ro5aJim3XdoLFw72H+n23BaIXzbcOnz5mfPoTvYVz7KzUl5+FRxEuqkp9G/Ajia [...]
<p>This doesn’t allow you to use different geoms with the stat, but that seems appropriate here since the convex hull is primarily a polygonal feature.</p>
</div>
<div id="exercises-1" class="section level3">
@@ -456,7 +473,7 @@ geom_chull <-<span class="st"> </span>function(<span class="dt">mapping =</sp
<div id="overriding-elements" class="section level3">
<h3>Overriding elements</h3>
<p>By default, when you add a new theme element, it inherits values from the existing theme. For example, the following code sets the key colour to red, but it inherits the existing fill colour:</p>
-<pre class="sourceCode r"><code class="sourceCode r"><span class="kw">theme_grey</span>()$legend.key
+<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="kw">theme_grey</span>()$legend.key
<span class="co">#> List of 4</span>
<span class="co">#> $ fill : chr "grey95"</span>
<span class="co">#> $ colour : chr "white"</span>
@@ -471,21 +488,26 @@ new_theme$legend.key
<span class="co">#> $ colour : chr "red"</span>
<span class="co">#> $ size : NULL</span>
<span class="co">#> $ linetype: NULL</span>
-<span class="co">#> - attr(*, "class")= chr [1:2] "element_rect" "element"</span></code></pre>
+<span class="co">#> - attr(*, "class")= chr [1:2] "element_rect" "element"</span></code></pre></div>
<p>To override it completely, use <code>%+replace%</code> instead of <code>+</code>:</p>
-<pre class="sourceCode r"><code class="sourceCode r">new_theme <-<span class="st"> </span><span class="kw">theme_grey</span>() %+replace%<span class="st"> </span><span class="kw">theme</span>(<span class="dt">legend.key =</span> <span class="kw">element_rect</span>(<span class="dt">colour =</span> <span class="st">"red"</span>))
+<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r">new_theme <-<span class="st"> </span><span class="kw">theme_grey</span>() %+replace%<span class="st"> </span><span class="kw">theme</span>(<span class="dt">legend.key =</span> <span class="kw">element_rect</span>(<span class="dt">colour =</span> <span class="st">"red"</span>))
new_theme$legend.key
<span class="co">#> List of 4</span>
<span class="co">#> $ fill : NULL</span>
<span class="co">#> $ colour : chr "red"</span>
<span class="co">#> $ size : NULL</span>
<span class="co">#> $ linetype: NULL</span>
-<span class="co">#> - attr(*, "class")= chr [1:2] "element_rect" "element"</span></code></pre>
+<span class="co">#> - attr(*, "class")= chr [1:2] "element_rect" "element"</span></code></pre></div>
</div>
<div id="global-elements" class="section level3">
<h3>Global elements</h3>
<p>There are four elements that affect the global appearance of the plot:</p>
-<table>
+<table style="width:82%;">
+<colgroup>
+<col width="19%"></col>
+<col width="27%"></col>
+<col width="34%"></col>
+</colgroup>
<thead>
<tr class="header">
<th align="left">Element</th>
@@ -517,15 +539,15 @@ new_theme$legend.key
</tbody>
</table>
<p>These set default properties that are inherited by more specific settings. These are most useful for setting an overall “background” colour and overall font settings (e.g. family and size).</p>
-<pre class="sourceCode r"><code class="sourceCode r">df <-<span class="st"> </span><span class="kw">data.frame</span>(<span class="dt">x =</span> <span class="dv">1</span>:<span class="dv">3</span>, <span class="dt">y =</span> <span class="dv">1</span>:<span class="dv">3</span>)
+<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r">df <-<span class="st"> </span><span class="kw">data.frame</span>(<span class="dt">x =</span> <span class="dv">1</span>:<span class="dv">3</span>, <span class="dt">y =</span> <span class="dv">1</span>:<span class="dv">3</span>)
base <-<span class="st"> </span><span class="kw">ggplot</span>(df, <span class="kw">aes</span>(x, y)) +<span class="st"> </span>
<span class="st"> </span><span class="kw">geom_point</span>() +<span class="st"> </span>
<span class="st"> </span><span class="kw">theme_minimal</span>()
-base</code></pre>
-<p><img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAASAAAAEgCAYAAAAUg66AAAAEDWlDQ1BJQ0MgUHJvZmlsZQAAOI2NVV1oHFUUPrtzZyMkzlNsNIV0qD8NJQ2TVjShtLp/3d02bpZJNtoi6GT27s6Yyc44M7v9oU9FUHwx6psUxL+3gCAo9Q/bPrQvlQol2tQgKD60+INQ6Ium65k7M5lpurHeZe58853vnnvuuWfvBei5qliWkRQBFpquLRcy4nOHj4g9K5CEh6AXBqFXUR0rXalMAjZPC3e1W99Dwntf2dXd/p+tt0YdFSBxH2Kz5qgLiI8B8KdVy3YBevqRHz/qWh72Yui3MUDEL3q44WPXw3M+fo1pZuQs4tOIBVVTaoiXEI/MxfhGDPsxsNZfoE1q66ro5aJim3XdoLFw72H+n23BaIXzbcOnz5mfPoTvYVz7KzUl5+FRxEuqkp9G/Ajia [...]
-<pre class="sourceCode r"><code class="sourceCode r">base +<span class="st"> </span><span class="kw">theme</span>(<span class="dt">text =</span> <span class="kw">element_text</span>(<span class="dt">colour =</span> <span class="st">"red"</span>))</code></pre>
-<p><img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAASAAAAEgCAYAAAAUg66AAAAEDWlDQ1BJQ0MgUHJvZmlsZQAAOI2NVV1oHFUUPrtzZyMkzlNsNIV0qD8NJQ2TVjShtLp/3d02bpZJNtoi6GT27s6Yyc44M7v9oU9FUHwx6psUxL+3gCAo9Q/bPrQvlQol2tQgKD60+INQ6Ium65k7M5lpurHeZe58853vnnvuuWfvBei5qliWkRQBFpquLRcy4nOHj4g9K5CEh6AXBqFXUR0rXalMAjZPC3e1W99Dwntf2dXd/p+tt0YdFSBxH2Kz5qgLiI8B8KdVy3YBevqRHz/qWh72Yui3MUDEL3q44WPXw3M+fo1pZuQs4tOIBVVTaoiXEI/MxfhGDPsxsNZfoE1q66ro5aJim3XdoLFw72H+n23BaIXzbcOnz5mfPoTvYVz7KzUl5+FRxEuqkp9G/Ajia [...]
+base</code></pre></div>
+<p><img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAASAAAAEgCAYAAAAUg66AAAAEDWlDQ1BJQ0MgUHJvZmlsZQAAOI2NVV1oHFUUPrtzZyMkzlNsNIV0qD8NJQ2TVjShtLp/3d02bpZJNtoi6GT27s6Yyc44M7v9oU9FUHwx6psUxL+3gCAo9Q/bPrQvlQol2tQgKD60+INQ6Ium65k7M5lpurHeZe58853vnnvuuWfvBei5qliWkRQBFpquLRcy4nOHj4g9K5CEh6AXBqFXUR0rXalMAjZPC3e1W99Dwntf2dXd/p+tt0YdFSBxH2Kz5qgLiI8B8KdVy3YBevqRHz/qWh72Yui3MUDEL3q44WPXw3M+fo1pZuQs4tOIBVVTaoiXEI/MxfhGDPsxsNZfoE1q66ro5aJim3XdoLFw72H+n23BaIXzbcOnz5mfPoTvYVz7KzUl5+FRxEuqkp9G/Ajia [...]
+<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r">base +<span class="st"> </span><span class="kw">theme</span>(<span class="dt">text =</span> <span class="kw">element_text</span>(<span class="dt">colour =</span> <span class="st">"red"</span>))</code></pre></div>
+<p><img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAASAAAAEgCAYAAAAUg66AAAAEDWlDQ1BJQ0MgUHJvZmlsZQAAOI2NVV1oHFUUPrtzZyMkzlNsNIV0qD8NJQ2TVjShtLp/3d02bpZJNtoi6GT27s6Yyc44M7v9oU9FUHwx6psUxL+3gCAo9Q/bPrQvlQol2tQgKD60+INQ6Ium65k7M5lpurHeZe58853vnnvuuWfvBei5qliWkRQBFpquLRcy4nOHj4g9K5CEh6AXBqFXUR0rXalMAjZPC3e1W99Dwntf2dXd/p+tt0YdFSBxH2Kz5qgLiI8B8KdVy3YBevqRHz/qWh72Yui3MUDEL3q44WPXw3M+fo1pZuQs4tOIBVVTaoiXEI/MxfhGDPsxsNZfoE1q66ro5aJim3XdoLFw72H+n23BaIXzbcOnz5mfPoTvYVz7KzUl5+FRxEuqkp9G/Ajia [...]
<p>You should generally start creating a theme by modifying these values.</p>
</div>
<div id="complete-vs-incomplete" class="section level3">
diff --git a/inst/doc/ggplot2-specs.Rmd b/inst/doc/ggplot2-specs.Rmd
index 5c2cf0b..4a78e6b 100644
--- a/inst/doc/ggplot2-specs.Rmd
+++ b/inst/doc/ggplot2-specs.Rmd
@@ -30,11 +30,11 @@ Colours can be specified with:
in the range `00` to `FF`
You can optionally make the colour transparent by using the form
- `"#RRGGBBAA".
+ `"#RRGGBBAA"`.
* An __NA__, for a completely transparent colour.
-* The [munsell](https://github.com/cwickham/munsell) package, Charlotte
+* The [munsell](https://github.com/cwickham/munsell) package, by Charlotte
Wickham, provides a wrapper around the colour system designed by Alfred
Munsell.
@@ -61,7 +61,7 @@ Line types can be specified with:
```
* The lengths of on/off stretches of line. This is done with a string
- containing 2, 4, 6, or 8 hexadecimal digits which give the lengths of c
+ containing 2, 4, 6, or 8 hexadecimal digits which give the lengths of
consecutive lengths. For example, 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.
diff --git a/inst/doc/ggplot2-specs.html b/inst/doc/ggplot2-specs.html
index f9e09e5..eea923f 100644
--- a/inst/doc/ggplot2-specs.html
+++ b/inst/doc/ggplot2-specs.html
@@ -7,10 +7,11 @@
<meta charset="utf-8">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="generator" content="pandoc" />
+<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="author" content="Hadley Wickham" />
-<meta name="date" content="2015-12-15" />
+<meta name="date" content="2016-02-29" />
<title>Aesthetic specifications</title>
@@ -18,32 +19,45 @@
<style type="text/css">code{white-space: pre;}</style>
<style type="text/css">
+div.sourceCode { overflow-x: auto; }
table.sourceCode, tr.sourceCode, td.lineNumbers, td.sourceCode {
margin: 0; padding: 0; vertical-align: baseline; border: none; }
table.sourceCode { width: 100%; line-height: 100%; }
td.lineNumbers { text-align: right; padding-right: 4px; padding-left: 4px; color: #aaaaaa; border-right: 1px solid #aaaaaa; }
td.sourceCode { padding-left: 5px; }
-code > span.kw { color: #007020; font-weight: bold; }
-code > span.dt { color: #902000; }
-code > span.dv { color: #40a070; }
-code > span.bn { color: #40a070; }
-code > span.fl { color: #40a070; }
-code > span.ch { color: #4070a0; }
-code > span.st { color: #4070a0; }
-code > span.co { color: #60a0b0; font-style: italic; }
-code > span.ot { color: #007020; }
-code > span.al { color: #ff0000; font-weight: bold; }
-code > span.fu { color: #06287e; }
-code > span.er { color: #ff0000; font-weight: bold; }
-</style>
-<style type="text/css">
- pre:not([class]) {
- background-color: white;
- }
+code > span.kw { color: #007020; font-weight: bold; } /* Keyword */
+code > span.dt { color: #902000; } /* DataType */
+code > span.dv { color: #40a070; } /* DecVal */
+code > span.bn { color: #40a070; } /* BaseN */
+code > span.fl { color: #40a070; } /* Float */
+code > span.ch { color: #4070a0; } /* Char */
+code > span.st { color: #4070a0; } /* String */
+code > span.co { color: #60a0b0; font-style: italic; } /* Comment */
+code > span.ot { color: #007020; } /* Other */
+code > span.al { color: #ff0000; font-weight: bold; } /* Alert */
+code > span.fu { color: #06287e; } /* Function */
+code > span.er { color: #ff0000; font-weight: bold; } /* Error */
+code > span.wa { color: #60a0b0; font-weight: bold; font-style: italic; } /* Warning */
+code > span.cn { color: #880000; } /* Constant */
+code > span.sc { color: #4070a0; } /* SpecialChar */
+code > span.vs { color: #4070a0; } /* VerbatimString */
+code > span.ss { color: #bb6688; } /* SpecialString */
+code > span.im { } /* Import */
+code > span.va { color: #19177c; } /* Variable */
+code > span.cf { color: #007020; font-weight: bold; } /* ControlFlow */
+code > span.op { color: #666666; } /* Operator */
+code > span.bu { } /* BuiltIn */
+code > span.ex { } /* Extension */
+code > span.pp { color: #bc7a00; } /* Preprocessor */
+code > span.at { color: #7d9029; } /* Attribute */
+code > span.do { color: #ba2121; font-style: italic; } /* Documentation */
+code > span.an { color: #60a0b0; font-weight: bold; font-style: italic; } /* Annotation */
+code > span.cv { color: #60a0b0; font-weight: bold; font-style: italic; } /* CommentVar */
+code > span.in { color: #60a0b0; font-weight: bold; font-style: italic; } /* Information */
</style>
-<link href="data:text/css,body%20%7B%0A%20%20background%2Dcolor%3A%20%23fff%3B%0A%20%20margin%3A%201em%20auto%3B%0A%20%20max%2Dwidth%3A%20700px%3B%0A%20%20overflow%3A%20visible%3B%0A%20%20padding%2Dleft%3A%202em%3B%0A%20%20padding%2Dright%3A%202em%3B%0A%20%20font%2Dfamily%3A%20%22Open%20Sans%22%2C%20%22Helvetica%20Neue%22%2C%20Helvetica%2C%20Arial%2C%20sans%2Dserif%3B%0A%20%20font%2Dsize%3A%2014px%3B%0A%20%20line%2Dheight%3A%201%2E35%3B%0A%7D%0A%0A%23header%20%7B%0A%20%20text%2Dalign%3A% [...]
+<link href="data:text/css;charset=utf-8,body%20%7B%0Abackground%2Dcolor%3A%20%23fff%3B%0Amargin%3A%201em%20auto%3B%0Amax%2Dwidth%3A%20700px%3B%0Aoverflow%3A%20visible%3B%0Apadding%2Dleft%3A%202em%3B%0Apadding%2Dright%3A%202em%3B%0Afont%2Dfamily%3A%20%22Open%20Sans%22%2C%20%22Helvetica%20Neue%22%2C%20Helvetica%2C%20Arial%2C%20sans%2Dserif%3B%0Afont%2Dsize%3A%2014px%3B%0Aline%2Dheight%3A%201%2E35%3B%0A%7D%0A%23header%20%7B%0Atext%2Dalign%3A%20center%3B%0A%7D%0A%23TOC%20%7B%0Aclear%3A%20bot [...]
</head>
@@ -51,10 +65,13 @@ code > span.er { color: #ff0000; font-weight: bold; }
-<div id="header">
+<div class="fluid-row" id="header">
+
+
<h1 class="title">Aesthetic specifications</h1>
<h4 class="author"><em>Hadley Wickham</em></h4>
-<h4 class="date"><em>2015-12-15</em></h4>
+<h4 class="date"><em>2016-02-29</em></h4>
+
</div>
@@ -65,9 +82,9 @@ code > span.er { color: #ff0000; font-weight: bold; }
<ul>
<li><p>A <strong>name</strong>, e.g., <code>"red"</code>. R has 657 built-in named colours, which can be listed with <code>colours()</code>. The Stowers Institute provides a nice printable pdf that lists all colours: <a href="http://research.stowers-institute.org/efg/R/Color/Chart/" class="uri">http://research.stowers-institute.org/efg/R/Color/Chart/</a>.</p></li>
<li><p>An <strong>rgb specification</strong>, with a string of the form <code>"#RRGGBB"</code> where each of the pairs <code>RR</code>, <code>GG</code>, <code>BB</code> consists of two hexadecimal digits giving a value in the range <code>00</code> to <code>FF</code></p>
-<p>You can optionally make the colour transparent by using the form `“#RRGGBBAA”.</p></li>
+<p>You can optionally make the colour transparent by using the form <code>"#RRGGBBAA"</code>.</p></li>
<li><p>An <strong>NA</strong>, for a completely transparent colour.</p></li>
-<li><p>The <a href="https://github.com/cwickham/munsell">munsell</a> package, Charlotte Wickham, provides a wrapper around the colour system designed by Alfred Munsell.</p></li>
+<li><p>The <a href="https://github.com/cwickham/munsell">munsell</a> package, by Charlotte Wickham, provides a wrapper around the colour system designed by Alfred Munsell.</p></li>
</ul>
</div>
<div id="sec:line-type-spec" class="section level2">
@@ -75,7 +92,7 @@ code > span.er { color: #ff0000; font-weight: bold; }
<p>Line types can be specified with:</p>
<ul>
<li><p>An <strong>integer</strong> or <strong>name</strong>: 0 = blank, 1 = solid, 2 = dashed, 3 = dotted, 4 = dotdash, 5 = longdash, 6 = twodash, as shown below:</p>
-<pre class="sourceCode r"><code class="sourceCode r">lty <-<span class="st"> </span><span class="kw">c</span>(<span class="st">"blank"</span>, <span class="st">"solid"</span>, <span class="st">"dashed"</span>, <span class="st">"dotted"</span>, <span class="st">"dotdash"</span>,
+<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r">lty <-<span class="st"> </span><span class="kw">c</span>(<span class="st">"blank"</span>, <span class="st">"solid"</span>, <span class="st">"dashed"</span>, <span class="st">"dotted"</span>, <span class="st">"dotdash"</span>,
<span class="st">"longdash"</span>,<span class="st">"twodash"</span>)
linetypes <-<span class="st"> </span><span class="kw">data.frame</span>(
<span class="dt">y =</span> <span class="kw">seq_along</span>(lty),
@@ -86,9 +103,9 @@ linetypes <-<span class="st"> </span><span class="kw">data.frame</span>(
<span class="st"> </span><span class="kw">scale_linetype_identity</span>() +<span class="st"> </span>
<span class="st"> </span><span class="kw">geom_text</span>(<span class="kw">aes</span>(<span class="dt">label =</span> lty), <span class="dt">hjust =</span> <span class="dv">0</span>, <span class="dt">nudge_y =</span> <span class="fl">0.2</span>) +
<span class="st"> </span><span class="kw">scale_x_continuous</span>(<span class="ot">NULL</span>, <span class="dt">breaks =</span> <span class="ot">NULL</span>) +<span class="st"> </span>
-<span class="st"> </span><span class="kw">scale_y_continuous</span>(<span class="ot">NULL</span>, <span class="dt">breaks =</span> <span class="ot">NULL</span>)</code></pre>
-<p><img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAASAAAAEgCAYAAAAUg66AAAAEDWlDQ1BJQ0MgUHJvZmlsZQAAOI2NVV1oHFUUPrtzZyMkzlNsNIV0qD8NJQ2TVjShtLp/3d02bpZJNtoi6GT27s6Yyc44M7v9oU9FUHwx6psUxL+3gCAo9Q/bPrQvlQol2tQgKD60+INQ6Ium65k7M5lpurHeZe58853vnnvuuWfvBei5qliWkRQBFpquLRcy4nOHj4g9K5CEh6AXBqFXUR0rXalMAjZPC3e1W99Dwntf2dXd/p+tt0YdFSBxH2Kz5qgLiI8B8KdVy3YBevqRHz/qWh72Yui3MUDEL3q44WPXw3M+fo1pZuQs4tOIBVVTaoiXEI/MxfhGDPsxsNZfoE1q66ro5aJim3XdoLFw72H+n23BaIXzbcOnz5mfPoTvYVz7KzUl5+FRxEuqkp9G/Ajia [...]
-<li><p>The lengths of on/off stretches of line. This is done with a string containing 2, 4, 6, or 8 hexadecimal digits which give the lengths of c consecutive lengths. For example, the string <code>"33"</code> specifies three units on followed by three off and <code>"3313"</code> specifies three units on followed by three off followed by one on and finally three off.</p>
+<span class="st"> </span><span class="kw">scale_y_continuous</span>(<span class="ot">NULL</span>, <span class="dt">breaks =</span> <span class="ot">NULL</span>)</code></pre></div>
+<p><img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAASAAAAEgCAYAAAAUg66AAAAEDWlDQ1BJQ0MgUHJvZmlsZQAAOI2NVV1oHFUUPrtzZyMkzlNsNIV0qD8NJQ2TVjShtLp/3d02bpZJNtoi6GT27s6Yyc44M7v9oU9FUHwx6psUxL+3gCAo9Q/bPrQvlQol2tQgKD60+INQ6Ium65k7M5lpurHeZe58853vnnvuuWfvBei5qliWkRQBFpquLRcy4nOHj4g9K5CEh6AXBqFXUR0rXalMAjZPC3e1W99Dwntf2dXd/p+tt0YdFSBxH2Kz5qgLiI8B8KdVy3YBevqRHz/qWh72Yui3MUDEL3q44WPXw3M+fo1pZuQs4tOIBVVTaoiXEI/MxfhGDPsxsNZfoE1q66ro5aJim3XdoLFw72H+n23BaIXzbcOnz5mfPoTvYVz7KzUl5+FRxEuqkp9G/Ajia [...]
+<li><p>The lengths of on/off stretches of line. This is done with a string containing 2, 4, 6, or 8 hexadecimal digits which give the lengths of consecutive lengths. For example, the string <code>"33"</code> specifies three units on followed by three off and <code>"3313"</code> specifies three units on followed by three off followed by one on and finally three off.</p>
<p>The five standard dash-dot line types described above correspond to 44, 13, 134, 73, and 2262.</p></li>
</ul>
<p>The <code>size</code> of a line is its width in mm.</p>
@@ -97,8 +114,8 @@ linetypes <-<span class="st"> </span><span class="kw">data.frame</span>(
<h2>Shape</h2>
<p>Shapes take four types of values:</p>
<ul>
-<li><p>An <strong>integer</strong> in <span class="math">\([0, 25]\)</span>:</p>
-<pre class="sourceCode r"><code class="sourceCode r">shapes <-<span class="st"> </span><span class="kw">data.frame</span>(
+<li><p>An <strong>integer</strong> in <span class="math inline">\([0, 25]\)</span>:</p>
+<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r">shapes <-<span class="st"> </span><span class="kw">data.frame</span>(
<span class="dt">shape =</span> <span class="kw">c</span>(<span class="dv">0</span>:<span class="dv">19</span>, <span class="dv">22</span>, <span class="dv">21</span>, <span class="dv">24</span>, <span class="dv">23</span>, <span class="dv">20</span>),
<span class="dt">x =</span> <span class="dv">0</span>:<span class="dv">24</span> %/%<span class="st"> </span><span class="dv">5</span>,
<span class="dt">y =</span> -(<span class="dv">0</span>:<span class="dv">24</span> %%<span class="st"> </span><span class="dv">5</span>)
@@ -109,19 +126,19 @@ linetypes <-<span class="st"> </span><span class="kw">data.frame</span>(
<span class="st"> </span><span class="kw">scale_shape_identity</span>() +
<span class="st"> </span><span class="kw">expand_limits</span>(<span class="dt">x =</span> <span class="fl">4.1</span>) +
<span class="st"> </span><span class="kw">scale_x_continuous</span>(<span class="ot">NULL</span>, <span class="dt">breaks =</span> <span class="ot">NULL</span>) +<span class="st"> </span>
-<span class="st"> </span><span class="kw">scale_y_continuous</span>(<span class="ot">NULL</span>, <span class="dt">breaks =</span> <span class="ot">NULL</span>)</code></pre>
-<p><img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAASAAAAEgCAYAAAAUg66AAAAEDWlDQ1BJQ0MgUHJvZmlsZQAAOI2NVV1oHFUUPrtzZyMkzlNsNIV0qD8NJQ2TVjShtLp/3d02bpZJNtoi6GT27s6Yyc44M7v9oU9FUHwx6psUxL+3gCAo9Q/bPrQvlQol2tQgKD60+INQ6Ium65k7M5lpurHeZe58853vnnvuuWfvBei5qliWkRQBFpquLRcy4nOHj4g9K5CEh6AXBqFXUR0rXalMAjZPC3e1W99Dwntf2dXd/p+tt0YdFSBxH2Kz5qgLiI8B8KdVy3YBevqRHz/qWh72Yui3MUDEL3q44WPXw3M+fo1pZuQs4tOIBVVTaoiXEI/MxfhGDPsxsNZfoE1q66ro5aJim3XdoLFw72H+n23BaIXzbcOnz5mfPoTvYVz7KzUl5+FRxEuqkp9G/Ajia [...]
+<span class="st"> </span><span class="kw">scale_y_continuous</span>(<span class="ot">NULL</span>, <span class="dt">breaks =</span> <span class="ot">NULL</span>)</code></pre></div>
+<p><img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAASAAAAEgCAYAAAAUg66AAAAEDWlDQ1BJQ0MgUHJvZmlsZQAAOI2NVV1oHFUUPrtzZyMkzlNsNIV0qD8NJQ2TVjShtLp/3d02bpZJNtoi6GT27s6Yyc44M7v9oU9FUHwx6psUxL+3gCAo9Q/bPrQvlQol2tQgKD60+INQ6Ium65k7M5lpurHeZe58853vnnvuuWfvBei5qliWkRQBFpquLRcy4nOHj4g9K5CEh6AXBqFXUR0rXalMAjZPC3e1W99Dwntf2dXd/p+tt0YdFSBxH2Kz5qgLiI8B8KdVy3YBevqRHz/qWh72Yui3MUDEL3q44WPXw3M+fo1pZuQs4tOIBVVTaoiXEI/MxfhGDPsxsNZfoE1q66ro5aJim3XdoLFw72H+n23BaIXzbcOnz5mfPoTvYVz7KzUl5+FRxEuqkp9G/Ajia [...]
<li><p>A <strong>single character</strong>, to use that character as a plotting symbol.</p></li>
<li><p>A <code>.</code> to draw the smallest rectangle that is visible, usualy 1 pixel.</p></li>
<li><p>An <code>NA</code>, to draw nothing.</p></li>
</ul>
<p>Note that shapes 21-24 have both stroke <code>colour</code> and a <code>fill</code>. The size of the filled part is controlled by <code>size</code>, the size of the stroke is controlled by <code>stroke</code>. Each is measured in mm, and the total size of the point is the sum of the two. Note that the size is constant along the diagonal in the following figure.</p>
-<pre class="sourceCode r"><code class="sourceCode r">sizes <-<span class="st"> </span><span class="kw">expand.grid</span>(<span class="dt">size =</span> (<span class="dv">0</span>:<span class="dv">3</span>) *<span class="st"> </span><span class="dv">2</span>, <span class="dt">stroke =</span> (<span class="dv">0</span>:<span class="dv">3</span>) *<span class="st"> </span><span class="dv">2</span>)
+<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r">sizes <-<span class="st"> </span><span class="kw">expand.grid</span>(<span class="dt">size =</span> (<span class="dv">0</span>:<span class="dv">3</span>) *<span class="st"> </span><span class="dv">2</span>, <span class="dt">stroke =</span> (<span class="dv">0</span>:<span class="dv">3</span>) *<span class="st"> </span><span class="dv">2</span>)
<span class="kw">ggplot</span>(sizes, <span class="kw">aes</span>(size, stroke, <span class="dt">size =</span> size, <span class="dt">stroke =</span> stroke)) +<span class="st"> </span>
<span class="st"> </span><span class="kw">geom_abline</span>(<span class="dt">slope =</span> -<span class="dv">1</span>, <span class="dt">intercept =</span> <span class="dv">6</span>, <span class="dt">colour =</span> <span class="st">"white"</span>, <span class="dt">size =</span> <span class="dv">6</span>) +<span class="st"> </span>
<span class="st"> </span><span class="kw">geom_point</span>(<span class="dt">shape =</span> <span class="dv">21</span>, <span class="dt">fill =</span> <span class="st">"red"</span>) +
-<span class="st"> </span><span class="kw">scale_size_identity</span>()</code></pre>
-<p><img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAASAAAAEgCAYAAAAUg66AAAAEDWlDQ1BJQ0MgUHJvZmlsZQAAOI2NVV1oHFUUPrtzZyMkzlNsNIV0qD8NJQ2TVjShtLp/3d02bpZJNtoi6GT27s6Yyc44M7v9oU9FUHwx6psUxL+3gCAo9Q/bPrQvlQol2tQgKD60+INQ6Ium65k7M5lpurHeZe58853vnnvuuWfvBei5qliWkRQBFpquLRcy4nOHj4g9K5CEh6AXBqFXUR0rXalMAjZPC3e1W99Dwntf2dXd/p+tt0YdFSBxH2Kz5qgLiI8B8KdVy3YBevqRHz/qWh72Yui3MUDEL3q44WPXw3M+fo1pZuQs4tOIBVVTaoiXEI/MxfhGDPsxsNZfoE1q66ro5aJim3XdoLFw72H+n23BaIXzbcOnz5mfPoTvYVz7KzUl5+FRxEuqkp9G/Ajia [...]
+<span class="st"> </span><span class="kw">scale_size_identity</span>()</code></pre></div>
+<p><img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAASAAAAEgCAYAAAAUg66AAAAEDWlDQ1BJQ0MgUHJvZmlsZQAAOI2NVV1oHFUUPrtzZyMkzlNsNIV0qD8NJQ2TVjShtLp/3d02bpZJNtoi6GT27s6Yyc44M7v9oU9FUHwx6psUxL+3gCAo9Q/bPrQvlQol2tQgKD60+INQ6Ium65k7M5lpurHeZe58853vnnvuuWfvBei5qliWkRQBFpquLRcy4nOHj4g9K5CEh6AXBqFXUR0rXalMAjZPC3e1W99Dwntf2dXd/p+tt0YdFSBxH2Kz5qgLiI8B8KdVy3YBevqRHz/qWh72Yui3MUDEL3q44WPXw3M+fo1pZuQs4tOIBVVTaoiXEI/MxfhGDPsxsNZfoE1q66ro5aJim3XdoLFw72H+n23BaIXzbcOnz5mfPoTvYVz7KzUl5+FRxEuqkp9G/Ajia [...]
</div>
<div id="text" class="section level2">
<h2>Text</h2>
@@ -131,10 +148,10 @@ linetypes <-<span class="st"> </span><span class="kw">data.frame</span>(
<div id="font-face" class="section level3">
<h3>Font face</h3>
<p>There are only three fonts that are guaranteed to work everywhere: “sans” (the default), “serif”, or “mono”:</p>
-<pre class="sourceCode r"><code class="sourceCode r">df <-<span class="st"> </span><span class="kw">data.frame</span>(<span class="dt">x =</span> <span class="dv">1</span>, <span class="dt">y =</span> <span class="dv">3</span>:<span class="dv">1</span>, <span class="dt">family =</span> <span class="kw">c</span>(<span class="st">"sans"</span>, <span class="st">"serif"</span>, <span class="st">"mono"</span>))
+<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r">df <-<span class="st"> </span><span class="kw">data.frame</span>(<span class="dt">x =</span> <span class="dv">1</span>, <span class="dt">y =</span> <span class="dv">3</span>:<span class="dv">1</span>, <span class="dt">family =</span> <span class="kw">c</span>(<span class="st">"sans"</span>, <span class="st">"serif"</span>, <span class="st">"mono"</span>))
<span class="kw">ggplot</span>(df, <span class="kw">aes</span>(x, y)) +<span class="st"> </span>
-<span class="st"> </span><span class="kw">geom_text</span>(<span class="kw">aes</span>(<span class="dt">label =</span> family, <span class="dt">family =</span> family))</code></pre>
-<p><img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAASAAAAEgCAYAAAAUg66AAAAEDWlDQ1BJQ0MgUHJvZmlsZQAAOI2NVV1oHFUUPrtzZyMkzlNsNIV0qD8NJQ2TVjShtLp/3d02bpZJNtoi6GT27s6Yyc44M7v9oU9FUHwx6psUxL+3gCAo9Q/bPrQvlQol2tQgKD60+INQ6Ium65k7M5lpurHeZe58853vnnvuuWfvBei5qliWkRQBFpquLRcy4nOHj4g9K5CEh6AXBqFXUR0rXalMAjZPC3e1W99Dwntf2dXd/p+tt0YdFSBxH2Kz5qgLiI8B8KdVy3YBevqRHz/qWh72Yui3MUDEL3q44WPXw3M+fo1pZuQs4tOIBVVTaoiXEI/MxfhGDPsxsNZfoE1q66ro5aJim3XdoLFw72H+n23BaIXzbcOnz5mfPoTvYVz7KzUl5+FRxEuqkp9G/Ajia [...]
+<span class="st"> </span><span class="kw">geom_text</span>(<span class="kw">aes</span>(<span class="dt">label =</span> family, <span class="dt">family =</span> family))</code></pre></div>
+<p><img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAASAAAAEgCAYAAAAUg66AAAAEDWlDQ1BJQ0MgUHJvZmlsZQAAOI2NVV1oHFUUPrtzZyMkzlNsNIV0qD8NJQ2TVjShtLp/3d02bpZJNtoi6GT27s6Yyc44M7v9oU9FUHwx6psUxL+3gCAo9Q/bPrQvlQol2tQgKD60+INQ6Ium65k7M5lpurHeZe58853vnnvuuWfvBei5qliWkRQBFpquLRcy4nOHj4g9K5CEh6AXBqFXUR0rXalMAjZPC3e1W99Dwntf2dXd/p+tt0YdFSBxH2Kz5qgLiI8B8KdVy3YBevqRHz/qWh72Yui3MUDEL3q44WPXw3M+fo1pZuQs4tOIBVVTaoiXEI/MxfhGDPsxsNZfoE1q66ro5aJim3XdoLFw72H+n23BaIXzbcOnz5mfPoTvYVz7KzUl5+FRxEuqkp9G/Ajia [...]
<p>It’s trickier to include a system font on a plot because text drawing is done differently by each graphics device (GD). There are five GDs in common use (<code>png()</code>, <code>pdf()</code>, on screen devices for Windows, Mac and Linux), so to have a font work everywhere you need to configure five devices in five different ways. Two packages simplify the quandary a bit:</p>
<ul>
<li><p><code>showtext</code> makes GD-independent plots by rendering all text as polygons.</p></li>
@@ -164,13 +181,13 @@ Find R news article
<li>top = 1, middle = 0.5, bottom = 0</li>
<li>left = 0, center = 0.5, right = 1</li>
</ul>
-<pre class="sourceCode r"><code class="sourceCode r">just <-<span class="st"> </span><span class="kw">expand.grid</span>(<span class="dt">hjust =</span> <span class="kw">c</span>(<span class="dv">0</span>, <span class="fl">0.5</span>, <span class="dv">1</span>), <span class="dt">vjust =</span> <span class="kw">c</span>(<span class="dv">0</span>, <span class="fl">0.5</span>, <span class="dv">1</span>))
+<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r">just <-<span class="st"> </span><span class="kw">expand.grid</span>(<span class="dt">hjust =</span> <span class="kw">c</span>(<span class="dv">0</span>, <span class="fl">0.5</span>, <span class="dv">1</span>), <span class="dt">vjust =</span> <span class="kw">c</span>(<span class="dv">0</span>, <span class="fl">0.5</span>, <span class="dv">1</span>))
just$label <-<span class="st"> </span><span class="kw">paste0</span>(just$hjust, <span class="st">", "</span>, just$vjust)
<span class="kw">ggplot</span>(just, <span class="kw">aes</span>(hjust, vjust)) +
<span class="st"> </span><span class="kw">geom_point</span>(<span class="dt">colour =</span> <span class="st">"grey70"</span>, <span class="dt">size =</span> <span class="dv">5</span>) +<span class="st"> </span>
-<span class="st"> </span><span class="kw">geom_text</span>(<span class="kw">aes</span>(<span class="dt">label =</span> label, <span class="dt">hjust =</span> hjust, <span class="dt">vjust =</span> vjust))</code></pre>
-<p><img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAASAAAAEgCAYAAAAUg66AAAAEDWlDQ1BJQ0MgUHJvZmlsZQAAOI2NVV1oHFUUPrtzZyMkzlNsNIV0qD8NJQ2TVjShtLp/3d02bpZJNtoi6GT27s6Yyc44M7v9oU9FUHwx6psUxL+3gCAo9Q/bPrQvlQol2tQgKD60+INQ6Ium65k7M5lpurHeZe58853vnnvuuWfvBei5qliWkRQBFpquLRcy4nOHj4g9K5CEh6AXBqFXUR0rXalMAjZPC3e1W99Dwntf2dXd/p+tt0YdFSBxH2Kz5qgLiI8B8KdVy3YBevqRHz/qWh72Yui3MUDEL3q44WPXw3M+fo1pZuQs4tOIBVVTaoiXEI/MxfhGDPsxsNZfoE1q66ro5aJim3XdoLFw72H+n23BaIXzbcOnz5mfPoTvYVz7KzUl5+FRxEuqkp9G/Ajia [...]
+<span class="st"> </span><span class="kw">geom_text</span>(<span class="kw">aes</span>(<span class="dt">label =</span> label, <span class="dt">hjust =</span> hjust, <span class="dt">vjust =</span> vjust))</code></pre></div>
+<p><img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAASAAAAEgCAYAAAAUg66AAAAEDWlDQ1BJQ0MgUHJvZmlsZQAAOI2NVV1oHFUUPrtzZyMkzlNsNIV0qD8NJQ2TVjShtLp/3d02bpZJNtoi6GT27s6Yyc44M7v9oU9FUHwx6psUxL+3gCAo9Q/bPrQvlQol2tQgKD60+INQ6Ium65k7M5lpurHeZe58853vnnvuuWfvBei5qliWkRQBFpquLRcy4nOHj4g9K5CEh6AXBqFXUR0rXalMAjZPC3e1W99Dwntf2dXd/p+tt0YdFSBxH2Kz5qgLiI8B8KdVy3YBevqRHz/qWh72Yui3MUDEL3q44WPXw3M+fo1pZuQs4tOIBVVTaoiXEI/MxfhGDPsxsNZfoE1q66ro5aJim3XdoLFw72H+n23BaIXzbcOnz5mfPoTvYVz7KzUl5+FRxEuqkp9G/Ajia [...]
<p>Note that you can use numbers outside the range (0, 1), but it’s not recommended.</p>
</div>
</div>
diff --git a/inst/staticdocs/index.r b/inst/staticdocs/index.r
index ff2ba23..cb02691 100644
--- a/inst/staticdocs/index.r
+++ b/inst/staticdocs/index.r
@@ -149,7 +149,8 @@ sd_section("Data",
"mpg",
"msleep",
"presidential",
- "seals"
+ "seals",
+ "txhousing"
)
)
diff --git a/man/aes_.Rd b/man/aes_.Rd
index eeff48f..c8af665 100644
--- a/man/aes_.Rd
+++ b/man/aes_.Rd
@@ -22,7 +22,7 @@ properties (aesthetics) of geoms. \code{\link{aes}} uses non-standard
evaluation to capture the variable names. \code{aes_} and \code{aes_string}
require you to explicitly quote the inputs either with \code{""} for
\code{aes_string()}, or with \code{quote} or \code{~} for \code{aes_()}.
-(\code{aes_q} is an alias to \code{aeq_})
+(\code{aes_q} is an alias to \code{aes_})
}
\details{
It's better to use \code{aes_q()}, because there's no easy way to create the
diff --git a/man/annotate.Rd b/man/annotate.Rd
index d8a0e63..5c2e430 100644
--- a/man/annotate.Rd
+++ b/man/annotate.Rd
@@ -14,8 +14,10 @@ annotate(geom, x = NULL, y = NULL, xmin = NULL, xmax = NULL,
\item{x, y, xmin, ymin, xmax, ymax, xend, yend}{positioning aesthetics -
you must specify at least one of these.}
-\item{...}{other aesthetics. These are not scaled so you can do (e.g.)
-\code{colour = "red"} to get a red point.}
+\item{...}{other arguments passed on to \code{\link{layer}}. These are
+often aesthetics, used to set an aesthetic to a fixed value, like
+\code{color = "red"} or \code{size = 3}. They may also be parameters
+to the paired geom/stat.}
\item{na.rm}{If \code{FALSE} (the default), removes missing values with
a warning. If \code{TRUE} silently removes missing values.}
diff --git a/man/annotation_custom.Rd b/man/annotation_custom.Rd
index 8378386..0a4d6a6 100644
--- a/man/annotation_custom.Rd
+++ b/man/annotation_custom.Rd
@@ -37,16 +37,13 @@ df <- data.frame(x = 1:10, y = 1:10)
base <- ggplot(df, aes(x, y)) +
geom_blank() +
theme_bw()
-# Adding a table
-\dontrun{
- if (require(gridExtra)) {
-base + annotation_custom(grob = tableGrob(head(iris[ ,1:3])),
- xmin = 3, xmax = 6, ymin = 2, ymax = 8)
-# full panel
-base + annotation_custom(grob = roundrectGrob(),
- xmin = -Inf, xmax = Inf, ymin = -Inf, ymax = Inf)
-}
-}
+
+# 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)) +
diff --git a/man/discrete_scale.Rd b/man/discrete_scale.Rd
index 9b4aafa..46b4a9e 100644
--- a/man/discrete_scale.Rd
+++ b/man/discrete_scale.Rd
@@ -49,8 +49,9 @@ for discrete scales and (0.05,0) for continuous scales.}
\item{na.value}{how should missing values be displayed?}
-\item{drop}{drop unused factor levels from the scale (\code{TRUE} or
-\code{FALSE})}
+\item{drop}{Should unused factor levels be omitted from the scale?
+The default, \code{TRUE}, uses the levels that appear in the data;
+\code{FALSE} uses all the levels in the factor.}
\item{guide}{the name of, or actual function, used to create the
guide. See \code{\link{guides}} for more info.}
diff --git a/man/facet_grid.Rd b/man/facet_grid.Rd
index ac22e97..f099188 100644
--- a/man/facet_grid.Rd
+++ b/man/facet_grid.Rd
@@ -65,66 +65,24 @@ will be shown, regardless of whether or not they appear in the data.}
Lay out panels in a grid.
}
\examples{
-\donttest{
-p <- ggplot(mtcars, aes(mpg, wt)) + geom_point()
-# With one variable
-p + facet_grid(. ~ cyl)
-p + facet_grid(cyl ~ .)
+p <- ggplot(mpg, aes(displ, cty)) + geom_point()
-# With two variables
-p + facet_grid(vs ~ am)
-p + facet_grid(am ~ vs)
-p + facet_grid(vs ~ am, margins=TRUE)
+p + facet_grid(. ~ cyl)
+p + facet_grid(drv ~ .)
+p + facet_grid(drv ~ cyl)
# To change plot order of facet grid,
# change the order of variable levels with factor()
-set.seed(6809)
-diamonds <- diamonds[sample(nrow(diamonds), 1000), ]
-diamonds$cut <- factor(diamonds$cut,
- levels = c("Ideal", "Very Good", "Fair", "Good", "Premium"))
-
-# Repeat first example with new order
-p <- ggplot(diamonds, aes(carat, ..density..)) +
- geom_histogram(binwidth = 1)
-p + facet_grid(. ~ cut)
-
-g <- ggplot(mtcars, aes(mpg, wt)) +
- geom_point()
-g + facet_grid(. ~ vs + am)
-g + facet_grid(vs + am ~ .)
-
-# You can also use strings, which makes it a little easier
-# when writing functions that generate faceting specifications
-
-p + facet_grid("cut ~ .")
-
-# see also ?plotmatrix for the scatterplot matrix
-
-# If there isn't any data for a given combination, that panel
-# will be empty
-
-g + facet_grid(cyl ~ vs)
-
# If you combine a facetted dataset with a dataset that lacks those
# facetting variables, the data will be repeated across the missing
# combinations:
-
-g + facet_grid(vs ~ cyl)
-
-df <- data.frame(mpg = 22, wt = 3)
-g + facet_grid(vs ~ cyl) +
+df <- data.frame(displ = mean(mpg$displ), cty = mean(mpg$cty))
+p +
+ facet_grid(. ~ cyl) +
geom_point(data = df, colour = "red", size = 2)
-df2 <- data.frame(mpg = c(19, 22), wt = c(2,4), vs = c(0, 1))
-g + facet_grid(vs ~ cyl) +
- geom_point(data = df2, colour = "red", size = 2)
-
-df3 <- data.frame(mpg = c(19, 22), wt = c(2,4), vs = c(1, 1))
-g + facet_grid(vs ~ cyl) +
- geom_point(data = df3, colour = "red", size = 2)
-
-
+# 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
@@ -132,52 +90,44 @@ mt <- ggplot(mtcars, aes(mpg, wt, colour = factor(cyl))) +
geom_point()
mt + facet_grid(. ~ 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
-mt + facet_grid(. ~ cyl, scales = "free", space = "free")
-
-mt + facet_grid(vs ~ am, scales = "free")
-mt + facet_grid(vs ~ am, scales = "free_x")
-mt + facet_grid(vs ~ am, scales = "free_y")
-mt + facet_grid(vs ~ am, scales = "free", space = "free")
-mt + facet_grid(vs ~ am, scales = "free", space = "free_x")
-mt + facet_grid(vs ~ am, scales = "free", space = "free_y")
-
-# You may need to set your own breaks for consistent display:
-mt + facet_grid(. ~ cyl, scales = "free_x", space = "free") +
- scale_x_continuous(breaks = seq(10, 36, by = 2))
-# Adding scale limits override free scales:
-last_plot() + xlim(10, 15)
-
-# Free scales are particularly useful for categorical variables
-ggplot(mpg, aes(cty, model)) +
+# 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")
-# particularly when you reorder factor levels
-mpg$model <- reorder(mpg$model, mpg$cty)
-manufacturer <- reorder(mpg$manufacturer, mpg$cty)
-last_plot() \%+\% mpg + theme(strip.text.y = element_text())
-
-# Use as.table to to control direction of horizontal facets, TRUE by default
-h <- ggplot(mtcars, aes(x = mpg, y = wt)) +
- geom_point()
-h + facet_grid(cyl ~ vs)
-h + facet_grid(cyl ~ vs, as.table = FALSE)
+ facet_grid(manufacturer ~ ., scales = "free", space = "free") +
+ theme(strip.text.y = element_text(angle = 0))
+
+# Facet labels ------------------------------------------------------
+p <- ggplot(mtcars, aes(wt, mpg)) + geom_point()
+p
+
+# label_both() displays both variable name and value
+p + facet_grid(vs ~ cyl, labeller = label_both)
-# Use labeller to control facet labels, label_value is default
-h + facet_grid(cyl ~ vs, labeller = label_both)
-# Using label_parsed, see ?plotmath for more options
+# label_parsed() parses text into mathematical expressions, see ?plotmath
mtcars$cyl2 <- factor(mtcars$cyl, labels = c("alpha", "beta", "sqrt(x, y)"))
-k <- ggplot(mtcars, aes(wt, mpg)) +
- geom_point()
-k + facet_grid(. ~ cyl2)
-k + facet_grid(. ~ cyl2, labeller = label_parsed)
-# For label_bquote the label value is x.
-p <- ggplot(mtcars, aes(wt, mpg)) +
- geom_point()
-p + facet_grid(. ~ vs, labeller = label_bquote(alpha ^ .(x)))
-p + facet_grid(. ~ vs, labeller = label_bquote(.(x) ^ .(x)))
+ggplot(mtcars, aes(wt, mpg)) +
+ geom_point() +
+ facet_grid(. ~ cyl2, labeller = label_parsed)
+
+# label_bquote() makes it easy to construct math expressions
+p + facet_grid(. ~ vs, labeller = label_bquote(cols = alpha ^ .(vs)))
+
+# The facet strips can be displayed near the axes with switch
+data <- transform(mtcars,
+ am = factor(am, levels = 0:1, c("Automatic", "Manual")),
+ gear = factor(gear, levels = 3:5, labels = c("Three", "Four", "Five"))
+)
+p <- ggplot(data, aes(mpg, disp)) + geom_point()
+p + facet_grid(am ~ gear, switch = "both")
+# It looks better without boxes around the strips
+p + facet_grid(am ~ gear, switch = "both") +
+ theme(strip.background = element_blank())
+# Margins ----------------------------------------------------------
+\donttest{
# Margins can be specified by logically (all yes or all no) or by specific
# variables as (character) variable names
mg <- ggplot(mtcars, aes(x = mpg, y = wt)) + geom_point()
@@ -190,20 +140,6 @@ mg + facet_grid(vs + am ~ gear, margins = "am")
mg + facet_grid(vs + am ~ gear, margins = "vs")
mg + facet_grid(vs + am ~ gear, margins = "gear")
mg + facet_grid(vs + am ~ gear, margins = c("gear", "am"))
-
-# The facet strips can be displayed near the axes with switch
-data <- transform(mtcars,
- am = factor(am, levels = 0:1, c("Automatic", "Manual")),
- gear = factor(gear, levels = 3:5, labels = c("Three", "Four", "Five"))
-)
-p <- ggplot(data, aes(mpg, disp)) + geom_point()
-p + facet_grid(am ~ gear, switch = "both") + theme_light()
-
-# It may be more aesthetic to use a theme without boxes around
-# around the strips.
-p + facet_grid(am ~ gear + vs, switch = "y") + theme_minimal()
-p + facet_grid(am ~ ., switch = "y") +
- theme_gray() \%+replace\% theme(strip.background = element_blank())
}
}
diff --git a/man/geom_abline.Rd b/man/geom_abline.Rd
index d5e6fc9..8fb31c2 100644
--- a/man/geom_abline.Rd
+++ b/man/geom_abline.Rd
@@ -18,23 +18,27 @@ geom_vline(mapping = NULL, data = NULL, ..., xintercept, na.rm = FALSE,
\arguments{
\item{mapping}{Set of aesthetic mappings created by \code{\link{aes}} or
\code{\link{aes_}}. If specified and \code{inherit.aes = TRUE} (the
-default), is combined with the default mapping at the top level of the
-plot. You only need to supply \code{mapping} if there isn't a mapping
-defined for the plot.}
-
-\item{data}{A data frame. If specified, overrides the default data frame
-defined at the top level of the plot.}
-
-\item{...}{other arguments passed on to \code{\link{layer}}. There are
- three types of arguments you can use here:
-
- \itemize{
- \item Aesthetics: to set an aesthetic to a fixed value, like
- \code{color = "red"} or \code{size = 3}.
- \item Other arguments to the layer, for example you override the
- default \code{stat} associated with the layer.
- \item Other arguments passed on to the stat.
- }}
+default), it is combined with the default mapping at the top level of the
+plot. You must supply \code{mapping} if there is no plot mapping.}
+
+\item{data}{The data to be displayed in this layer. There are three
+ options:
+
+ If \code{NULL}, the default, the data is inherited from the plot
+ data as specified in the call to \code{\link{ggplot}}.
+
+ A \code{data.frame}, or other object, will override the plot
+ data. All objects will be fortified to produce a data frame. See
+ \code{\link{fortify}} for which variables will be created.
+
+ A \code{function} will be called with a single argument,
+ the plot data. The return value must be a \code{data.frame.}, and
+ will be used as the layer data.}
+
+\item{...}{other arguments passed on to \code{\link{layer}}. These are
+often aesthetics, used to set an aesthetic to a fixed value, like
+\code{color = "red"} or \code{size = 3}. They may also be parameters
+to the paired geom/stat.}
\item{na.rm}{If \code{FALSE} (the default), removes missing values with
a warning. If \code{TRUE} silently removes missing values.}
diff --git a/man/geom_bar.Rd b/man/geom_bar.Rd
index fb5da7d..bfeec9b 100644
--- a/man/geom_bar.Rd
+++ b/man/geom_bar.Rd
@@ -6,43 +6,47 @@
\title{Bars, rectangles with bases on x-axis}
\usage{
geom_bar(mapping = NULL, data = NULL, stat = "count",
- position = "stack", width = NULL, binwidth = NULL, ..., na.rm = FALSE,
+ position = "stack", ..., width = NULL, binwidth = NULL, na.rm = FALSE,
show.legend = NA, inherit.aes = TRUE)
stat_count(mapping = NULL, data = NULL, geom = "bar",
- position = "stack", width = NULL, ..., na.rm = FALSE,
+ position = "stack", ..., width = NULL, na.rm = FALSE,
show.legend = NA, inherit.aes = TRUE)
}
\arguments{
\item{mapping}{Set of aesthetic mappings created by \code{\link{aes}} or
\code{\link{aes_}}. If specified and \code{inherit.aes = TRUE} (the
-default), is combined with the default mapping at the top level of the
-plot. You only need to supply \code{mapping} if there isn't a mapping
-defined for the plot.}
+default), it is combined with the default mapping at the top level of the
+plot. You must supply \code{mapping} if there is no plot mapping.}
-\item{data}{A data frame. If specified, overrides the default data frame
-defined at the top level of the plot.}
+\item{data}{The data to be displayed in this layer. There are three
+ options:
+
+ If \code{NULL}, the default, the data is inherited from the plot
+ data as specified in the call to \code{\link{ggplot}}.
+
+ A \code{data.frame}, or other object, will override the plot
+ data. All objects will be fortified to produce a data frame. See
+ \code{\link{fortify}} for which variables will be created.
+
+ A \code{function} will be called with a single argument,
+ the plot data. The return value must be a \code{data.frame.}, and
+ will be used as the layer data.}
\item{position}{Position adjustment, either as a string, or the result of
a call to a position adjustment function.}
+\item{...}{other arguments passed on to \code{\link{layer}}. These are
+often aesthetics, used to set an aesthetic to a fixed value, like
+\code{color = "red"} or \code{size = 3}. They may also be parameters
+to the paired geom/stat.}
+
\item{width}{Bar width. By default, set to 90\% of the resolution of the data.}
\item{binwidth}{\code{geom_bar} no longer has a binwidth argument - if
you use it you'll get an warning telling to you use
\code{\link{geom_histogram}} instead.}
-\item{...}{other arguments passed on to \code{\link{layer}}. There are
- three types of arguments you can use here:
-
- \itemize{
- \item Aesthetics: to set an aesthetic to a fixed value, like
- \code{color = "red"} or \code{size = 3}.
- \item Other arguments to the layer, for example you override the
- default \code{stat} associated with the layer.
- \item Other arguments passed on to the stat.
- }}
-
\item{na.rm}{If \code{FALSE} (the default), removes missing values with
a warning. If \code{TRUE} silently removes missing values.}
diff --git a/man/geom_bin2d.Rd b/man/geom_bin2d.Rd
index 3c0bc8b..d87d064 100644
--- a/man/geom_bin2d.Rd
+++ b/man/geom_bin2d.Rd
@@ -7,26 +7,41 @@
\title{Add heatmap of 2d bin counts.}
\usage{
geom_bin2d(mapping = NULL, data = NULL, stat = "bin2d",
- position = "identity", na.rm = FALSE, show.legend = NA,
- inherit.aes = TRUE, ...)
+ position = "identity", ..., na.rm = FALSE, show.legend = NA,
+ inherit.aes = TRUE)
stat_bin_2d(mapping = NULL, data = NULL, geom = "tile",
- position = "identity", bins = 30, binwidth = NULL, drop = TRUE,
- na.rm = FALSE, show.legend = NA, inherit.aes = TRUE, ...)
+ position = "identity", ..., bins = 30, binwidth = NULL, drop = TRUE,
+ na.rm = FALSE, show.legend = NA, inherit.aes = TRUE)
}
\arguments{
\item{mapping}{Set of aesthetic mappings created by \code{\link{aes}} or
\code{\link{aes_}}. If specified and \code{inherit.aes = TRUE} (the
-default), is combined with the default mapping at the top level of the
-plot. You only need to supply \code{mapping} if there isn't a mapping
-defined for the plot.}
+default), it is combined with the default mapping at the top level of the
+plot. You must supply \code{mapping} if there is no plot mapping.}
-\item{data}{A data frame. If specified, overrides the default data frame
-defined at the top level of the plot.}
+\item{data}{The data to be displayed in this layer. There are three
+ options:
+
+ If \code{NULL}, the default, the data is inherited from the plot
+ data as specified in the call to \code{\link{ggplot}}.
+
+ A \code{data.frame}, or other object, will override the plot
+ data. All objects will be fortified to produce a data frame. See
+ \code{\link{fortify}} for which variables will be created.
+
+ A \code{function} will be called with a single argument,
+ the plot data. The return value must be a \code{data.frame.}, and
+ will be used as the layer data.}
\item{position}{Position adjustment, either as a string, or the result of
a call to a position adjustment function.}
+\item{...}{other arguments passed on to \code{\link{layer}}. These are
+often aesthetics, used to set an aesthetic to a fixed value, like
+\code{color = "red"} or \code{size = 3}. They may also be parameters
+to the paired geom/stat.}
+
\item{na.rm}{If \code{FALSE} (the default), removes missing values with
a warning. If \code{TRUE} silently removes missing values.}
@@ -39,17 +54,6 @@ rather than combining with them. This is most useful for helper functions
that define both data and aesthetics and shouldn't inherit behaviour from
the default plot specification, e.g. \code{\link{borders}}.}
-\item{...}{other arguments passed on to \code{\link{layer}}. There are
- three types of arguments you can use here:
-
- \itemize{
- \item Aesthetics: to set an aesthetic to a fixed value, like
- \code{color = "red"} or \code{size = 3}.
- \item Other arguments to the layer, for example you override the
- default \code{stat} associated with the layer.
- \item Other arguments passed on to the stat.
- }}
-
\item{geom, stat}{Use to override the default connection between
\code{geom_bin2d} and \code{stat_bin2d}.}
diff --git a/man/geom_blank.Rd b/man/geom_blank.Rd
index a5ea94f..5938f28 100644
--- a/man/geom_blank.Rd
+++ b/man/geom_blank.Rd
@@ -5,17 +5,27 @@
\title{Blank, draws nothing.}
\usage{
geom_blank(mapping = NULL, data = NULL, stat = "identity",
- position = "identity", show.legend = NA, inherit.aes = TRUE, ...)
+ position = "identity", ..., show.legend = NA, inherit.aes = TRUE)
}
\arguments{
\item{mapping}{Set of aesthetic mappings created by \code{\link{aes}} or
\code{\link{aes_}}. If specified and \code{inherit.aes = TRUE} (the
-default), is combined with the default mapping at the top level of the
-plot. You only need to supply \code{mapping} if there isn't a mapping
-defined for the plot.}
+default), it is combined with the default mapping at the top level of the
+plot. You must supply \code{mapping} if there is no plot mapping.}
-\item{data}{A data frame. If specified, overrides the default data frame
-defined at the top level of the plot.}
+\item{data}{The data to be displayed in this layer. There are three
+ options:
+
+ If \code{NULL}, the default, the data is inherited from the plot
+ data as specified in the call to \code{\link{ggplot}}.
+
+ A \code{data.frame}, or other object, will override the plot
+ data. All objects will be fortified to produce a data frame. See
+ \code{\link{fortify}} for which variables will be created.
+
+ A \code{function} will be called with a single argument,
+ the plot data. The return value must be a \code{data.frame.}, and
+ will be used as the layer data.}
\item{stat}{The statistical transformation to use on the data for this
layer, as a string.}
@@ -23,6 +33,11 @@ layer, as a string.}
\item{position}{Position adjustment, either as a string, or the result of
a call to a position adjustment function.}
+\item{...}{other arguments passed on to \code{\link{layer}}. These are
+often aesthetics, used to set an aesthetic to a fixed value, like
+\code{color = "red"} or \code{size = 3}. They may also be parameters
+to the paired geom/stat.}
+
\item{show.legend}{logical. Should this layer be included in the legends?
\code{NA}, the default, includes if any aesthetics are mapped.
\code{FALSE} never includes, and \code{TRUE} always includes.}
@@ -31,37 +46,13 @@ a call to a position adjustment function.}
rather than combining with them. This is most useful for helper functions
that define both data and aesthetics and shouldn't inherit behaviour from
the default plot specification, e.g. \code{\link{borders}}.}
-
-\item{...}{other arguments passed on to \code{\link{layer}}. There are
- three types of arguments you can use here:
-
- \itemize{
- \item Aesthetics: to set an aesthetic to a fixed value, like
- \code{color = "red"} or \code{size = 3}.
- \item Other arguments to the layer, for example you override the
- default \code{stat} associated with the layer.
- \item Other arguments passed on to the stat.
- }}
}
\description{
The blank geom draws nothing, but can be a useful way of ensuring common
scales between different plots.
}
\examples{
-ggplot(mtcars, aes(wt, mpg)) + geom_blank()
+ggplot(mtcars, aes(wt, mpg))
# Nothing to see here!
-
-# Take the following scatter plot
-a <- ggplot(mtcars, aes(x = wt, y = mpg), . ~ cyl) + geom_point()
-# Add to that some lines with geom_abline()
-df <- data.frame(a = rnorm(10, 25), b = rnorm(10, 0))
-a + geom_abline(aes(intercept = a, slope = b), data = df)
-# Suppose you then wanted to remove the geom_point layer
-# If you just remove geom_point, you will get an error
-b <- ggplot(mtcars, aes(x = wt, y = mpg))
-\dontrun{b + geom_abline(aes(intercept = a, slope = b), data = df)}
-# Switching to geom_blank() gets the desired plot
-c <- ggplot(mtcars, aes(x = wt, y = mpg)) + geom_blank()
-c + geom_abline(aes(intercept = a, slope = b), data = df)
}
diff --git a/man/geom_boxplot.Rd b/man/geom_boxplot.Rd
index 4359bb8..da17798 100644
--- a/man/geom_boxplot.Rd
+++ b/man/geom_boxplot.Rd
@@ -6,31 +6,48 @@
\title{Box and whiskers plot.}
\usage{
geom_boxplot(mapping = NULL, data = NULL, stat = "boxplot",
- position = "dodge", outlier.colour = NULL, outlier.shape = 19,
- outlier.size = 1.5, outlier.stroke = 0.5, notch = FALSE,
- notchwidth = 0.5, varwidth = FALSE, na.rm = FALSE, show.legend = NA,
- inherit.aes = TRUE, ...)
+ position = "dodge", ..., outlier.colour = NULL, outlier.color = NULL,
+ outlier.shape = 19, outlier.size = 1.5, outlier.stroke = 0.5,
+ notch = FALSE, notchwidth = 0.5, varwidth = FALSE, na.rm = FALSE,
+ show.legend = NA, inherit.aes = TRUE)
stat_boxplot(mapping = NULL, data = NULL, geom = "boxplot",
- position = "dodge", coef = 1.5, na.rm = FALSE, show.legend = NA,
- inherit.aes = TRUE, ...)
+ position = "dodge", ..., coef = 1.5, na.rm = FALSE, show.legend = NA,
+ inherit.aes = TRUE)
}
\arguments{
\item{mapping}{Set of aesthetic mappings created by \code{\link{aes}} or
\code{\link{aes_}}. If specified and \code{inherit.aes = TRUE} (the
-default), is combined with the default mapping at the top level of the
-plot. You only need to supply \code{mapping} if there isn't a mapping
-defined for the plot.}
+default), it is combined with the default mapping at the top level of the
+plot. You must supply \code{mapping} if there is no plot mapping.}
-\item{data}{A data frame. If specified, overrides the default data frame
-defined at the top level of the plot.}
+\item{data}{The data to be displayed in this layer. There are three
+ options:
+
+ If \code{NULL}, the default, the data is inherited from the plot
+ data as specified in the call to \code{\link{ggplot}}.
+
+ A \code{data.frame}, or other object, will override the plot
+ data. All objects will be fortified to produce a data frame. See
+ \code{\link{fortify}} for which variables will be created.
+
+ A \code{function} will be called with a single argument,
+ the plot data. The return value must be a \code{data.frame.}, and
+ will be used as the layer data.}
\item{position}{Position adjustment, either as a string, or the result of
a call to a position adjustment function.}
-\item{outlier.colour, outlier.shape, outlier.size, outlier.stroke}{Default
-aesthetics for outliers. Set to \code{NULL} to inherit from the aesthetics
-used for the box.}
+\item{...}{other arguments passed on to \code{\link{layer}}. These are
+often aesthetics, used to set an aesthetic to a fixed value, like
+\code{color = "red"} or \code{size = 3}. They may also be parameters
+to the paired geom/stat.}
+
+\item{outlier.colour, outlier.color, outlier.shape, outlier.size, outlier.stroke}{Default aesthetics for outliers. Set to \code{NULL} to inherit from the
+ aesthetics used for the box.
+
+ In the unlikely event you specify both US and UK spellings of colour, the
+ US spelling will take precedence.}
\item{notch}{if \code{FALSE} (default) make a standard box plot. If
\code{TRUE}, make a notched box plot. Notches are used to compare groups;
@@ -57,17 +74,6 @@ rather than combining with them. This is most useful for helper functions
that define both data and aesthetics and shouldn't inherit behaviour from
the default plot specification, e.g. \code{\link{borders}}.}
-\item{...}{other arguments passed on to \code{\link{layer}}. There are
- three types of arguments you can use here:
-
- \itemize{
- \item Aesthetics: to set an aesthetic to a fixed value, like
- \code{color = "red"} or \code{size = 3}.
- \item Other arguments to the layer, for example you override the
- default \code{stat} associated with the layer.
- \item Other arguments passed on to the stat.
- }}
-
\item{geom, stat}{Use to override the default connection between
\code{geom_boxplot} and \code{stat_boxplot}.}
diff --git a/man/geom_contour.Rd b/man/geom_contour.Rd
index aae9058..8e1474b 100644
--- a/man/geom_contour.Rd
+++ b/man/geom_contour.Rd
@@ -6,23 +6,32 @@
\title{Display contours of a 3d surface in 2d.}
\usage{
geom_contour(mapping = NULL, data = NULL, stat = "contour",
- position = "identity", lineend = "butt", linejoin = "round",
- linemitre = 1, na.rm = FALSE, show.legend = NA, inherit.aes = TRUE,
- ...)
+ position = "identity", ..., lineend = "butt", linejoin = "round",
+ linemitre = 1, na.rm = FALSE, show.legend = NA, inherit.aes = TRUE)
stat_contour(mapping = NULL, data = NULL, geom = "contour",
- position = "identity", na.rm = FALSE, show.legend = NA,
- inherit.aes = TRUE, ...)
+ position = "identity", ..., na.rm = FALSE, show.legend = NA,
+ inherit.aes = TRUE)
}
\arguments{
\item{mapping}{Set of aesthetic mappings created by \code{\link{aes}} or
\code{\link{aes_}}. If specified and \code{inherit.aes = TRUE} (the
-default), is combined with the default mapping at the top level of the
-plot. You only need to supply \code{mapping} if there isn't a mapping
-defined for the plot.}
+default), it is combined with the default mapping at the top level of the
+plot. You must supply \code{mapping} if there is no plot mapping.}
-\item{data}{A data frame. If specified, overrides the default data frame
-defined at the top level of the plot.}
+\item{data}{The data to be displayed in this layer. There are three
+ options:
+
+ If \code{NULL}, the default, the data is inherited from the plot
+ data as specified in the call to \code{\link{ggplot}}.
+
+ A \code{data.frame}, or other object, will override the plot
+ data. All objects will be fortified to produce a data frame. See
+ \code{\link{fortify}} for which variables will be created.
+
+ A \code{function} will be called with a single argument,
+ the plot data. The return value must be a \code{data.frame.}, and
+ will be used as the layer data.}
\item{stat}{The statistical transformation to use on the data for this
layer, as a string.}
@@ -30,6 +39,11 @@ layer, as a string.}
\item{position}{Position adjustment, either as a string, or the result of
a call to a position adjustment function.}
+\item{...}{other arguments passed on to \code{\link{layer}}. These are
+often aesthetics, used to set an aesthetic to a fixed value, like
+\code{color = "red"} or \code{size = 3}. They may also be parameters
+to the paired geom/stat.}
+
\item{lineend}{Line end style (round, butt, square)}
\item{linejoin}{Line join style (round, mitre, bevel)}
@@ -48,17 +62,6 @@ rather than combining with them. This is most useful for helper functions
that define both data and aesthetics and shouldn't inherit behaviour from
the default plot specification, e.g. \code{\link{borders}}.}
-\item{...}{other arguments passed on to \code{\link{layer}}. There are
- three types of arguments you can use here:
-
- \itemize{
- \item Aesthetics: to set an aesthetic to a fixed value, like
- \code{color = "red"} or \code{size = 3}.
- \item Other arguments to the layer, for example you override the
- default \code{stat} associated with the layer.
- \item Other arguments passed on to the stat.
- }}
-
\item{geom}{The geometric object to use display the data}
}
\description{
diff --git a/man/geom_count.Rd b/man/geom_count.Rd
index 142087a..e8904f7 100644
--- a/man/geom_count.Rd
+++ b/man/geom_count.Rd
@@ -6,26 +6,41 @@
\title{Count the number of observations at each location.}
\usage{
geom_count(mapping = NULL, data = NULL, stat = "sum",
- position = "identity", na.rm = FALSE, show.legend = NA,
- inherit.aes = TRUE, ...)
+ position = "identity", ..., na.rm = FALSE, show.legend = NA,
+ inherit.aes = TRUE)
stat_sum(mapping = NULL, data = NULL, geom = "point",
- position = "identity", na.rm = FALSE, show.legend = NA,
- inherit.aes = TRUE, ...)
+ position = "identity", ..., na.rm = FALSE, show.legend = NA,
+ inherit.aes = TRUE)
}
\arguments{
\item{mapping}{Set of aesthetic mappings created by \code{\link{aes}} or
\code{\link{aes_}}. If specified and \code{inherit.aes = TRUE} (the
-default), is combined with the default mapping at the top level of the
-plot. You only need to supply \code{mapping} if there isn't a mapping
-defined for the plot.}
+default), it is combined with the default mapping at the top level of the
+plot. You must supply \code{mapping} if there is no plot mapping.}
-\item{data}{A data frame. If specified, overrides the default data frame
-defined at the top level of the plot.}
+\item{data}{The data to be displayed in this layer. There are three
+ options:
+
+ If \code{NULL}, the default, the data is inherited from the plot
+ data as specified in the call to \code{\link{ggplot}}.
+
+ A \code{data.frame}, or other object, will override the plot
+ data. All objects will be fortified to produce a data frame. See
+ \code{\link{fortify}} for which variables will be created.
+
+ A \code{function} will be called with a single argument,
+ the plot data. The return value must be a \code{data.frame.}, and
+ will be used as the layer data.}
\item{position}{Position adjustment, either as a string, or the result of
a call to a position adjustment function.}
+\item{...}{other arguments passed on to \code{\link{layer}}. These are
+often aesthetics, used to set an aesthetic to a fixed value, like
+\code{color = "red"} or \code{size = 3}. They may also be parameters
+to the paired geom/stat.}
+
\item{na.rm}{If \code{FALSE} (the default), removes missing values with
a warning. If \code{TRUE} silently removes missing values.}
@@ -38,17 +53,6 @@ rather than combining with them. This is most useful for helper functions
that define both data and aesthetics and shouldn't inherit behaviour from
the default plot specification, e.g. \code{\link{borders}}.}
-\item{...}{other arguments passed on to \code{\link{layer}}. There are
- three types of arguments you can use here:
-
- \itemize{
- \item Aesthetics: to set an aesthetic to a fixed value, like
- \code{color = "red"} or \code{size = 3}.
- \item Other arguments to the layer, for example you override the
- default \code{stat} associated with the layer.
- \item Other arguments passed on to the stat.
- }}
-
\item{geom, stat}{Use to override the default connection between
\code{geom_count} and \code{stat_sum}.}
}
diff --git a/man/geom_density.Rd b/man/geom_density.Rd
index f60d327..6b6ad69 100644
--- a/man/geom_density.Rd
+++ b/man/geom_density.Rd
@@ -6,26 +6,41 @@
\title{Display a smooth density estimate.}
\usage{
geom_density(mapping = NULL, data = NULL, stat = "density",
- position = "identity", na.rm = FALSE, show.legend = NA,
- inherit.aes = TRUE, ...)
+ position = "identity", ..., na.rm = FALSE, show.legend = NA,
+ inherit.aes = TRUE)
stat_density(mapping = NULL, data = NULL, geom = "area",
- position = "stack", adjust = 1, kernel = "gaussian", trim = FALSE,
- na.rm = FALSE, show.legend = NA, inherit.aes = TRUE, ...)
+ position = "stack", ..., bw = "nrd0", adjust = 1, kernel = "gaussian",
+ trim = FALSE, na.rm = FALSE, show.legend = NA, inherit.aes = TRUE)
}
\arguments{
\item{mapping}{Set of aesthetic mappings created by \code{\link{aes}} or
\code{\link{aes_}}. If specified and \code{inherit.aes = TRUE} (the
-default), is combined with the default mapping at the top level of the
-plot. You only need to supply \code{mapping} if there isn't a mapping
-defined for the plot.}
+default), it is combined with the default mapping at the top level of the
+plot. You must supply \code{mapping} if there is no plot mapping.}
-\item{data}{A data frame. If specified, overrides the default data frame
-defined at the top level of the plot.}
+\item{data}{The data to be displayed in this layer. There are three
+ options:
+
+ If \code{NULL}, the default, the data is inherited from the plot
+ data as specified in the call to \code{\link{ggplot}}.
+
+ A \code{data.frame}, or other object, will override the plot
+ data. All objects will be fortified to produce a data frame. See
+ \code{\link{fortify}} for which variables will be created.
+
+ A \code{function} will be called with a single argument,
+ the plot data. The return value must be a \code{data.frame.}, and
+ will be used as the layer data.}
\item{position}{Position adjustment, either as a string, or the result of
a call to a position adjustment function.}
+\item{...}{other arguments passed on to \code{\link{layer}}. These are
+often aesthetics, used to set an aesthetic to a fixed value, like
+\code{color = "red"} or \code{size = 3}. They may also be parameters
+to the paired geom/stat.}
+
\item{na.rm}{If \code{FALSE} (the default), removes missing values with
a warning. If \code{TRUE} silently removes missing values.}
@@ -38,21 +53,14 @@ rather than combining with them. This is most useful for helper functions
that define both data and aesthetics and shouldn't inherit behaviour from
the default plot specification, e.g. \code{\link{borders}}.}
-\item{...}{other arguments passed on to \code{\link{layer}}. There are
- three types of arguments you can use here:
-
- \itemize{
- \item Aesthetics: to set an aesthetic to a fixed value, like
- \code{color = "red"} or \code{size = 3}.
- \item Other arguments to the layer, for example you override the
- default \code{stat} associated with the layer.
- \item Other arguments passed on to the stat.
- }}
-
\item{geom, stat}{Use to override the default connection between
\code{geom_density} and \code{stat_density}.}
-\item{adjust}{see \code{\link{density}} for details}
+\item{bw}{the smoothing bandwidth to be used, see
+\code{\link{density}} for details}
+
+\item{adjust}{adjustment of the bandwidth, see
+\code{\link{density}} for details}
\item{kernel}{kernel used for density estimation, see
\code{\link{density}} for details}
diff --git a/man/geom_density_2d.Rd b/man/geom_density_2d.Rd
index 34d8083..6129c18 100644
--- a/man/geom_density_2d.Rd
+++ b/man/geom_density_2d.Rd
@@ -8,27 +8,41 @@
\title{Contours from a 2d density estimate.}
\usage{
geom_density_2d(mapping = NULL, data = NULL, stat = "density2d",
- position = "identity", lineend = "butt", linejoin = "round",
- linemitre = 1, na.rm = FALSE, show.legend = NA, inherit.aes = TRUE,
- ...)
+ position = "identity", ..., lineend = "butt", linejoin = "round",
+ linemitre = 1, na.rm = FALSE, show.legend = NA, inherit.aes = TRUE)
stat_density_2d(mapping = NULL, data = NULL, geom = "density_2d",
- position = "identity", contour = TRUE, n = 100, h = NULL,
- na.rm = FALSE, show.legend = NA, inherit.aes = TRUE, ...)
+ position = "identity", ..., contour = TRUE, n = 100, h = NULL,
+ na.rm = FALSE, show.legend = NA, inherit.aes = TRUE)
}
\arguments{
\item{mapping}{Set of aesthetic mappings created by \code{\link{aes}} or
\code{\link{aes_}}. If specified and \code{inherit.aes = TRUE} (the
-default), is combined with the default mapping at the top level of the
-plot. You only need to supply \code{mapping} if there isn't a mapping
-defined for the plot.}
+default), it is combined with the default mapping at the top level of the
+plot. You must supply \code{mapping} if there is no plot mapping.}
-\item{data}{A data frame. If specified, overrides the default data frame
-defined at the top level of the plot.}
+\item{data}{The data to be displayed in this layer. There are three
+ options:
+
+ If \code{NULL}, the default, the data is inherited from the plot
+ data as specified in the call to \code{\link{ggplot}}.
+
+ A \code{data.frame}, or other object, will override the plot
+ data. All objects will be fortified to produce a data frame. See
+ \code{\link{fortify}} for which variables will be created.
+
+ A \code{function} will be called with a single argument,
+ the plot data. The return value must be a \code{data.frame.}, and
+ will be used as the layer data.}
\item{position}{Position adjustment, either as a string, or the result of
a call to a position adjustment function.}
+\item{...}{other arguments passed on to \code{\link{layer}}. These are
+often aesthetics, used to set an aesthetic to a fixed value, like
+\code{color = "red"} or \code{size = 3}. They may also be parameters
+to the paired geom/stat.}
+
\item{lineend}{Line end style (round, butt, square)}
\item{linejoin}{Line join style (round, mitre, bevel)}
@@ -47,17 +61,6 @@ rather than combining with them. This is most useful for helper functions
that define both data and aesthetics and shouldn't inherit behaviour from
the default plot specification, e.g. \code{\link{borders}}.}
-\item{...}{other arguments passed on to \code{\link{layer}}. There are
- three types of arguments you can use here:
-
- \itemize{
- \item Aesthetics: to set an aesthetic to a fixed value, like
- \code{color = "red"} or \code{size = 3}.
- \item Other arguments to the layer, for example you override the
- default \code{stat} associated with the layer.
- \item Other arguments passed on to the stat.
- }}
-
\item{geom, stat}{Use to override the default connection between
\code{geom_density_2d} and \code{stat_density_2d}.}
diff --git a/man/geom_dotplot.Rd b/man/geom_dotplot.Rd
index 8aca317..b640123 100644
--- a/man/geom_dotplot.Rd
+++ b/man/geom_dotplot.Rd
@@ -4,26 +4,41 @@
\alias{geom_dotplot}
\title{Dot plot}
\usage{
-geom_dotplot(mapping = NULL, data = NULL, position = "identity",
+geom_dotplot(mapping = NULL, data = NULL, position = "identity", ...,
binwidth = NULL, binaxis = "x", method = "dotdensity",
binpositions = "bygroup", stackdir = "up", stackratio = 1,
dotsize = 1, stackgroups = FALSE, origin = NULL, right = TRUE,
width = 0.9, drop = FALSE, na.rm = FALSE, show.legend = NA,
- inherit.aes = TRUE, ...)
+ inherit.aes = TRUE)
}
\arguments{
\item{mapping}{Set of aesthetic mappings created by \code{\link{aes}} or
\code{\link{aes_}}. If specified and \code{inherit.aes = TRUE} (the
-default), is combined with the default mapping at the top level of the
-plot. You only need to supply \code{mapping} if there isn't a mapping
-defined for the plot.}
+default), it is combined with the default mapping at the top level of the
+plot. You must supply \code{mapping} if there is no plot mapping.}
-\item{data}{A data frame. If specified, overrides the default data frame
-defined at the top level of the plot.}
+\item{data}{The data to be displayed in this layer. There are three
+ options:
+
+ If \code{NULL}, the default, the data is inherited from the plot
+ data as specified in the call to \code{\link{ggplot}}.
+
+ A \code{data.frame}, or other object, will override the plot
+ data. All objects will be fortified to produce a data frame. See
+ \code{\link{fortify}} for which variables will be created.
+
+ A \code{function} will be called with a single argument,
+ the plot data. The return value must be a \code{data.frame.}, and
+ will be used as the layer data.}
\item{position}{Position adjustment, either as a string, or the result of
a call to a position adjustment function.}
+\item{...}{other arguments passed on to \code{\link{layer}}. These are
+often aesthetics, used to set an aesthetic to a fixed value, like
+\code{color = "red"} or \code{size = 3}. They may also be parameters
+to the paired geom/stat.}
+
\item{binwidth}{When \code{method} is "dotdensity", this specifies maximum bin
width. When \code{method} is "histodot", this specifies bin width.
Defaults to 1/30 of the range of the data}
@@ -71,17 +86,6 @@ a warning. If \code{TRUE} silently removes missing values.}
rather than combining with them. This is most useful for helper functions
that define both data and aesthetics and shouldn't inherit behaviour from
the default plot specification, e.g. \code{\link{borders}}.}
-
-\item{...}{other arguments passed on to \code{\link{layer}}. There are
- three types of arguments you can use here:
-
- \itemize{
- \item Aesthetics: to set an aesthetic to a fixed value, like
- \code{color = "red"} or \code{size = 3}.
- \item Other arguments to the layer, for example you override the
- default \code{stat} associated with the layer.
- \item Other arguments passed on to the stat.
- }}
}
\description{
In a dot plot, the width of a dot corresponds to the bin width
diff --git a/man/geom_errorbarh.Rd b/man/geom_errorbarh.Rd
index 1f2207a..b19f68e 100644
--- a/man/geom_errorbarh.Rd
+++ b/man/geom_errorbarh.Rd
@@ -5,18 +5,28 @@
\title{Horizontal error bars}
\usage{
geom_errorbarh(mapping = NULL, data = NULL, stat = "identity",
- position = "identity", na.rm = FALSE, show.legend = NA,
- inherit.aes = TRUE, ...)
+ position = "identity", ..., na.rm = FALSE, show.legend = NA,
+ inherit.aes = TRUE)
}
\arguments{
\item{mapping}{Set of aesthetic mappings created by \code{\link{aes}} or
\code{\link{aes_}}. If specified and \code{inherit.aes = TRUE} (the
-default), is combined with the default mapping at the top level of the
-plot. You only need to supply \code{mapping} if there isn't a mapping
-defined for the plot.}
+default), it is combined with the default mapping at the top level of the
+plot. You must supply \code{mapping} if there is no plot mapping.}
-\item{data}{A data frame. If specified, overrides the default data frame
-defined at the top level of the plot.}
+\item{data}{The data to be displayed in this layer. There are three
+ options:
+
+ If \code{NULL}, the default, the data is inherited from the plot
+ data as specified in the call to \code{\link{ggplot}}.
+
+ A \code{data.frame}, or other object, will override the plot
+ data. All objects will be fortified to produce a data frame. See
+ \code{\link{fortify}} for which variables will be created.
+
+ A \code{function} will be called with a single argument,
+ the plot data. The return value must be a \code{data.frame.}, and
+ will be used as the layer data.}
\item{stat}{The statistical transformation to use on the data for this
layer, as a string.}
@@ -24,6 +34,11 @@ layer, as a string.}
\item{position}{Position adjustment, either as a string, or the result of
a call to a position adjustment function.}
+\item{...}{other arguments passed on to \code{\link{layer}}. These are
+often aesthetics, used to set an aesthetic to a fixed value, like
+\code{color = "red"} or \code{size = 3}. They may also be parameters
+to the paired geom/stat.}
+
\item{na.rm}{If \code{FALSE} (the default), removes missing values with
a warning. If \code{TRUE} silently removes missing values.}
@@ -35,17 +50,6 @@ a warning. If \code{TRUE} silently removes missing values.}
rather than combining with them. This is most useful for helper functions
that define both data and aesthetics and shouldn't inherit behaviour from
the default plot specification, e.g. \code{\link{borders}}.}
-
-\item{...}{other arguments passed on to \code{\link{layer}}. There are
- three types of arguments you can use here:
-
- \itemize{
- \item Aesthetics: to set an aesthetic to a fixed value, like
- \code{color = "red"} or \code{size = 3}.
- \item Other arguments to the layer, for example you override the
- default \code{stat} associated with the layer.
- \item Other arguments passed on to the stat.
- }}
}
\description{
Horizontal error bars
diff --git a/man/geom_hex.Rd b/man/geom_hex.Rd
index ca45583..573da8c 100644
--- a/man/geom_hex.Rd
+++ b/man/geom_hex.Rd
@@ -7,26 +7,41 @@
\title{Hexagon binning.}
\usage{
geom_hex(mapping = NULL, data = NULL, stat = "binhex",
- position = "identity", na.rm = FALSE, show.legend = NA,
- inherit.aes = TRUE, ...)
+ position = "identity", ..., na.rm = FALSE, show.legend = NA,
+ inherit.aes = TRUE)
stat_bin_hex(mapping = NULL, data = NULL, geom = "hex",
- position = "identity", bins = 30, binwidth = NULL, na.rm = FALSE,
- show.legend = NA, inherit.aes = TRUE, ...)
+ position = "identity", ..., bins = 30, binwidth = NULL, na.rm = FALSE,
+ show.legend = NA, inherit.aes = TRUE)
}
\arguments{
\item{mapping}{Set of aesthetic mappings created by \code{\link{aes}} or
\code{\link{aes_}}. If specified and \code{inherit.aes = TRUE} (the
-default), is combined with the default mapping at the top level of the
-plot. You only need to supply \code{mapping} if there isn't a mapping
-defined for the plot.}
+default), it is combined with the default mapping at the top level of the
+plot. You must supply \code{mapping} if there is no plot mapping.}
-\item{data}{A data frame. If specified, overrides the default data frame
-defined at the top level of the plot.}
+\item{data}{The data to be displayed in this layer. There are three
+ options:
+
+ If \code{NULL}, the default, the data is inherited from the plot
+ data as specified in the call to \code{\link{ggplot}}.
+
+ A \code{data.frame}, or other object, will override the plot
+ data. All objects will be fortified to produce a data frame. See
+ \code{\link{fortify}} for which variables will be created.
+
+ A \code{function} will be called with a single argument,
+ the plot data. The return value must be a \code{data.frame.}, and
+ will be used as the layer data.}
\item{position}{Position adjustment, either as a string, or the result of
a call to a position adjustment function.}
+\item{...}{other arguments passed on to \code{\link{layer}}. These are
+often aesthetics, used to set an aesthetic to a fixed value, like
+\code{color = "red"} or \code{size = 3}. They may also be parameters
+to the paired geom/stat.}
+
\item{na.rm}{If \code{FALSE} (the default), removes missing values with
a warning. If \code{TRUE} silently removes missing values.}
@@ -39,17 +54,6 @@ rather than combining with them. This is most useful for helper functions
that define both data and aesthetics and shouldn't inherit behaviour from
the default plot specification, e.g. \code{\link{borders}}.}
-\item{...}{other arguments passed on to \code{\link{layer}}. There are
- three types of arguments you can use here:
-
- \itemize{
- \item Aesthetics: to set an aesthetic to a fixed value, like
- \code{color = "red"} or \code{size = 3}.
- \item Other arguments to the layer, for example you override the
- default \code{stat} associated with the layer.
- \item Other arguments passed on to the stat.
- }}
-
\item{geom, stat}{Override the default connection between \code{geom_hex} and
\code{stat_binhex.}}
diff --git a/man/geom_histogram.Rd b/man/geom_histogram.Rd
index 929343f..5b749ee 100644
--- a/man/geom_histogram.Rd
+++ b/man/geom_histogram.Rd
@@ -7,32 +7,46 @@
\title{Histograms and frequency polygons.}
\usage{
geom_freqpoly(mapping = NULL, data = NULL, stat = "bin",
- position = "identity", na.rm = FALSE, show.legend = NA,
- inherit.aes = TRUE, ...)
+ position = "identity", ..., na.rm = FALSE, show.legend = NA,
+ inherit.aes = TRUE)
geom_histogram(mapping = NULL, data = NULL, stat = "bin",
- binwidth = NULL, bins = NULL, origin = NULL, right = FALSE,
- position = "stack", na.rm = FALSE, show.legend = NA,
- inherit.aes = TRUE, ...)
+ position = "stack", ..., binwidth = NULL, bins = NULL, na.rm = FALSE,
+ show.legend = NA, inherit.aes = TRUE)
stat_bin(mapping = NULL, data = NULL, geom = "bar", position = "stack",
- width = 0.9, drop = FALSE, right = FALSE, binwidth = NULL,
- bins = NULL, origin = NULL, breaks = NULL, na.rm = FALSE,
- show.legend = NA, inherit.aes = TRUE, ...)
+ ..., binwidth = NULL, bins = NULL, center = NULL, boundary = NULL,
+ closed = c("right", "left"), pad = FALSE, na.rm = FALSE,
+ show.legend = NA, inherit.aes = TRUE)
}
\arguments{
\item{mapping}{Set of aesthetic mappings created by \code{\link{aes}} or
\code{\link{aes_}}. If specified and \code{inherit.aes = TRUE} (the
-default), is combined with the default mapping at the top level of the
-plot. You only need to supply \code{mapping} if there isn't a mapping
-defined for the plot.}
+default), it is combined with the default mapping at the top level of the
+plot. You must supply \code{mapping} if there is no plot mapping.}
-\item{data}{A data frame. If specified, overrides the default data frame
-defined at the top level of the plot.}
+\item{data}{The data to be displayed in this layer. There are three
+ options:
+
+ If \code{NULL}, the default, the data is inherited from the plot
+ data as specified in the call to \code{\link{ggplot}}.
+
+ A \code{data.frame}, or other object, will override the plot
+ data. All objects will be fortified to produce a data frame. See
+ \code{\link{fortify}} for which variables will be created.
+
+ A \code{function} will be called with a single argument,
+ the plot data. The return value must be a \code{data.frame.}, and
+ will be used as the layer data.}
\item{position}{Position adjustment, either as a string, or the result of
a call to a position adjustment function.}
+\item{...}{other arguments passed on to \code{\link{layer}}. These are
+often aesthetics, used to set an aesthetic to a fixed value, like
+\code{color = "red"} or \code{size = 3}. They may also be parameters
+to the paired geom/stat.}
+
\item{na.rm}{If \code{FALSE} (the default), removes missing values with
a warning. If \code{TRUE} silently removes missing values.}
@@ -45,37 +59,37 @@ rather than combining with them. This is most useful for helper functions
that define both data and aesthetics and shouldn't inherit behaviour from
the default plot specification, e.g. \code{\link{borders}}.}
-\item{...}{other arguments passed on to \code{\link{layer}}. There are
- three types of arguments you can use here:
+\item{binwidth}{The width of the bins. The default is to use \code{bins}
+ bins that cover the range of the data. You should always override
+ this value, exploring multiple widths to find the best to illustrate the
+ stories in your data.
- \itemize{
- \item Aesthetics: to set an aesthetic to a fixed value, like
- \code{color = "red"} or \code{size = 3}.
- \item Other arguments to the layer, for example you override the
- default \code{stat} associated with the layer.
- \item Other arguments passed on to the stat.
- }}
+ The bin width of a date variable is the number of days in each time; the
+ bin width of a time variable is the number of seconds.}
-\item{binwidth}{Bin width to use. Defaults to 1/\code{bins} of the range of
-the data}
-
-\item{bins}{Number of bins. Overridden by \code{binwidth} or \code{breaks}.
-Defaults to 30}
-
-\item{origin}{Origin of first bin}
-
-\item{right}{If \code{TRUE}, right-closed, left-open, if \code{FALSE},
-the default, right-open, left-closed.}
+\item{bins}{Number of bins. Overridden by \code{binwidth}. Defaults to 30}
\item{geom, stat}{Use to override the default connection between
\code{geom_histogram}/\code{geom_freqpoly} and \code{stat_bin}.}
-\item{width}{Width of bars when used with categorical data}
+\item{center}{The center of one of the bins. Note that if center is above or
+below the range of the data, things will be shifted by an appropriate
+number of \code{width}s. To center on integers, for example, use
+\code{width=1} and \code{center=0}, even if \code{0} is outside the range
+of the data. At most one of \code{center} and \code{boundary} may be
+specified.}
+
+\item{boundary}{A boundary between two bins. As with \code{center}, things
+are shifted when \code{boundary} is outside the range of the data. For
+example, to center on integers, use \code{width = 1} and \code{boundary =
+0.5}, even if \code{1} is outside the range of the data. At most one of
+\code{center} and \code{boundary} may be specified.}
-\item{drop}{If TRUE, remove all bins with zero counts}
+\item{closed}{One of \code{"right"} or \code{"left"} indicating whether right
+or left edges of bins are included in the bin.}
-\item{breaks}{Actual breaks to use. Overrides bin width, bin number and
-origin}
+\item{pad}{If \code{TRUE}, adds empty bins at either end of x. This ensures
+frequency polygons touch 0. Defaults to \code{FALSE}.}
}
\description{
Display a 1d distribution by dividing into bins and counting the number
diff --git a/man/geom_jitter.Rd b/man/geom_jitter.Rd
index c330354..787defe 100644
--- a/man/geom_jitter.Rd
+++ b/man/geom_jitter.Rd
@@ -4,19 +4,40 @@
\alias{geom_jitter}
\title{Points, jittered to reduce overplotting.}
\usage{
-geom_jitter(mapping = NULL, data = NULL, width = NULL, height = NULL,
- stat = "identity", position = "jitter", na.rm = FALSE,
- show.legend = NA, inherit.aes = TRUE, ...)
+geom_jitter(mapping = NULL, data = NULL, stat = "identity",
+ position = "jitter", ..., width = NULL, height = NULL, na.rm = FALSE,
+ show.legend = NA, inherit.aes = TRUE)
}
\arguments{
\item{mapping}{Set of aesthetic mappings created by \code{\link{aes}} or
\code{\link{aes_}}. If specified and \code{inherit.aes = TRUE} (the
-default), is combined with the default mapping at the top level of the
-plot. You only need to supply \code{mapping} if there isn't a mapping
-defined for the plot.}
+default), it is combined with the default mapping at the top level of the
+plot. You must supply \code{mapping} if there is no plot mapping.}
-\item{data}{A data frame. If specified, overrides the default data frame
-defined at the top level of the plot.}
+\item{data}{The data to be displayed in this layer. There are three
+ options:
+
+ If \code{NULL}, the default, the data is inherited from the plot
+ data as specified in the call to \code{\link{ggplot}}.
+
+ A \code{data.frame}, or other object, will override the plot
+ data. All objects will be fortified to produce a data frame. See
+ \code{\link{fortify}} for which variables will be created.
+
+ A \code{function} will be called with a single argument,
+ the plot data. The return value must be a \code{data.frame.}, and
+ will be used as the layer data.}
+
+\item{stat}{The statistical transformation to use on the data for this
+layer, as a string.}
+
+\item{position}{Position adjustment, either as a string, or the result of
+a call to a position adjustment function.}
+
+\item{...}{other arguments passed on to \code{\link{layer}}. These are
+often aesthetics, used to set an aesthetic to a fixed value, like
+\code{color = "red"} or \code{size = 3}. They may also be parameters
+to the paired geom/stat.}
\item{width}{Amount of vertical and horizontal jitter. The jitter
is added in both positive and negative directions, so the total spread
@@ -36,12 +57,6 @@ defined at the top level of the plot.}
is aligned on the integers, so a width or height of 0.5 will spread the
data so it's not possible to see the distinction between the categories.}
-\item{stat}{The statistical transformation to use on the data for this
-layer, as a string.}
-
-\item{position}{Position adjustment, either as a string, or the result of
-a call to a position adjustment function.}
-
\item{na.rm}{If \code{FALSE} (the default), removes missing values with
a warning. If \code{TRUE} silently removes missing values.}
@@ -53,17 +68,6 @@ a warning. If \code{TRUE} silently removes missing values.}
rather than combining with them. This is most useful for helper functions
that define both data and aesthetics and shouldn't inherit behaviour from
the default plot specification, e.g. \code{\link{borders}}.}
-
-\item{...}{other arguments passed on to \code{\link{layer}}. There are
- three types of arguments you can use here:
-
- \itemize{
- \item Aesthetics: to set an aesthetic to a fixed value, like
- \code{color = "red"} or \code{size = 3}.
- \item Other arguments to the layer, for example you override the
- default \code{stat} associated with the layer.
- \item Other arguments passed on to the stat.
- }}
}
\description{
The jitter geom is a convenient default for geom_point with position =
diff --git a/man/geom_linerange.Rd b/man/geom_linerange.Rd
index bf248b2..2571bb5 100644
--- a/man/geom_linerange.Rd
+++ b/man/geom_linerange.Rd
@@ -8,16 +8,16 @@
\title{Vertical intervals: lines, crossbars & errorbars.}
\usage{
geom_crossbar(mapping = NULL, data = NULL, stat = "identity",
- position = "identity", fatten = 2.5, na.rm = FALSE, show.legend = NA,
- inherit.aes = TRUE, ...)
+ position = "identity", ..., fatten = 2.5, na.rm = FALSE,
+ show.legend = NA, inherit.aes = TRUE)
geom_errorbar(mapping = NULL, data = NULL, stat = "identity",
- position = "identity", na.rm = FALSE, show.legend = NA,
- inherit.aes = TRUE, ...)
+ position = "identity", ..., na.rm = FALSE, show.legend = NA,
+ inherit.aes = TRUE)
geom_linerange(mapping = NULL, data = NULL, stat = "identity",
- position = "identity", na.rm = FALSE, show.legend = NA,
- inherit.aes = TRUE, ...)
+ position = "identity", ..., na.rm = FALSE, show.legend = NA,
+ inherit.aes = TRUE)
geom_pointrange(mapping = NULL, data = NULL, stat = "identity",
position = "identity", ..., fatten = 4, na.rm = FALSE,
@@ -26,12 +26,22 @@ geom_pointrange(mapping = NULL, data = NULL, stat = "identity",
\arguments{
\item{mapping}{Set of aesthetic mappings created by \code{\link{aes}} or
\code{\link{aes_}}. If specified and \code{inherit.aes = TRUE} (the
-default), is combined with the default mapping at the top level of the
-plot. You only need to supply \code{mapping} if there isn't a mapping
-defined for the plot.}
+default), it is combined with the default mapping at the top level of the
+plot. You must supply \code{mapping} if there is no plot mapping.}
+
+\item{data}{The data to be displayed in this layer. There are three
+ options:
+
+ If \code{NULL}, the default, the data is inherited from the plot
+ data as specified in the call to \code{\link{ggplot}}.
+
+ A \code{data.frame}, or other object, will override the plot
+ data. All objects will be fortified to produce a data frame. See
+ \code{\link{fortify}} for which variables will be created.
-\item{data}{A data frame. If specified, overrides the default data frame
-defined at the top level of the plot.}
+ A \code{function} will be called with a single argument,
+ the plot data. The return value must be a \code{data.frame.}, and
+ will be used as the layer data.}
\item{stat}{The statistical transformation to use on the data for this
layer, as a string.}
@@ -39,6 +49,11 @@ layer, as a string.}
\item{position}{Position adjustment, either as a string, or the result of
a call to a position adjustment function.}
+\item{...}{other arguments passed on to \code{\link{layer}}. These are
+often aesthetics, used to set an aesthetic to a fixed value, like
+\code{color = "red"} or \code{size = 3}. They may also be parameters
+to the paired geom/stat.}
+
\item{fatten}{A multiplicative factor used to increase the size of the
middle bar in \code{geom_crossbar()} and the middle point in
\code{geom_pointrange()}.}
@@ -54,17 +69,6 @@ a warning. If \code{TRUE} silently removes missing values.}
rather than combining with them. This is most useful for helper functions
that define both data and aesthetics and shouldn't inherit behaviour from
the default plot specification, e.g. \code{\link{borders}}.}
-
-\item{...}{other arguments passed on to \code{\link{layer}}. There are
- three types of arguments you can use here:
-
- \itemize{
- \item Aesthetics: to set an aesthetic to a fixed value, like
- \code{color = "red"} or \code{size = 3}.
- \item Other arguments to the layer, for example you override the
- default \code{stat} associated with the layer.
- \item Other arguments passed on to the stat.
- }}
}
\description{
Various ways of representing a vertical interval defined by \code{x},
diff --git a/man/geom_map.Rd b/man/geom_map.Rd
index c623ce2..900c430 100644
--- a/man/geom_map.Rd
+++ b/man/geom_map.Rd
@@ -4,27 +4,42 @@
\alias{geom_map}
\title{Polygons from a reference map.}
\usage{
-geom_map(mapping = NULL, data = NULL, map, stat = "identity",
- na.rm = FALSE, show.legend = NA, inherit.aes = TRUE, ...)
+geom_map(mapping = NULL, data = NULL, stat = "identity", ..., map,
+ na.rm = FALSE, show.legend = NA, inherit.aes = TRUE)
}
\arguments{
\item{mapping}{Set of aesthetic mappings created by \code{\link{aes}} or
\code{\link{aes_}}. If specified and \code{inherit.aes = TRUE} (the
-default), is combined with the default mapping at the top level of the
-plot. You only need to supply \code{mapping} if there isn't a mapping
-defined for the plot.}
+default), it is combined with the default mapping at the top level of the
+plot. You must supply \code{mapping} if there is no plot mapping.}
-\item{data}{A data frame. If specified, overrides the default data frame
-defined at the top level of the plot.}
+\item{data}{The data to be displayed in this layer. There are three
+ options:
+
+ If \code{NULL}, the default, the data is inherited from the plot
+ data as specified in the call to \code{\link{ggplot}}.
+
+ A \code{data.frame}, or other object, will override the plot
+ data. All objects will be fortified to produce a data frame. See
+ \code{\link{fortify}} for which variables will be created.
+
+ A \code{function} will be called with a single argument,
+ the plot data. The return value must be a \code{data.frame.}, and
+ will be used as the layer data.}
+
+\item{stat}{The statistical transformation to use on the data for this
+layer, as a string.}
+
+\item{...}{other arguments passed on to \code{\link{layer}}. These are
+often aesthetics, used to set an aesthetic to a fixed value, like
+\code{color = "red"} or \code{size = 3}. They may also be parameters
+to the paired geom/stat.}
\item{map}{Data frame that contains the map coordinates. This will
typically be created using \code{\link{fortify}} on a spatial object.
It must contain columns \code{x} or \code{long}, \code{y} or
\code{lat}, and \code{region} or \code{id}.}
-\item{stat}{The statistical transformation to use on the data for this
-layer, as a string.}
-
\item{na.rm}{If \code{FALSE} (the default), removes missing values with
a warning. If \code{TRUE} silently removes missing values.}
@@ -36,17 +51,6 @@ a warning. If \code{TRUE} silently removes missing values.}
rather than combining with them. This is most useful for helper functions
that define both data and aesthetics and shouldn't inherit behaviour from
the default plot specification, e.g. \code{\link{borders}}.}
-
-\item{...}{other arguments passed on to \code{\link{layer}}. There are
- three types of arguments you can use here:
-
- \itemize{
- \item Aesthetics: to set an aesthetic to a fixed value, like
- \code{color = "red"} or \code{size = 3}.
- \item Other arguments to the layer, for example you override the
- default \code{stat} associated with the layer.
- \item Other arguments passed on to the stat.
- }}
}
\description{
Does not affect position scales.
diff --git a/man/geom_path.Rd b/man/geom_path.Rd
index 8eefff1..458d8d9 100644
--- a/man/geom_path.Rd
+++ b/man/geom_path.Rd
@@ -7,9 +7,9 @@
\title{Connect observations.}
\usage{
geom_path(mapping = NULL, data = NULL, stat = "identity",
- position = "identity", lineend = "butt", linejoin = "round",
- linemitre = 1, na.rm = FALSE, arrow = NULL, show.legend = NA,
- inherit.aes = TRUE, ...)
+ position = "identity", ..., lineend = "butt", linejoin = "round",
+ linemitre = 1, arrow = NULL, na.rm = FALSE, show.legend = NA,
+ inherit.aes = TRUE)
geom_line(mapping = NULL, data = NULL, stat = "identity",
position = "identity", na.rm = FALSE, show.legend = NA,
@@ -22,12 +22,22 @@ geom_step(mapping = NULL, data = NULL, stat = "identity",
\arguments{
\item{mapping}{Set of aesthetic mappings created by \code{\link{aes}} or
\code{\link{aes_}}. If specified and \code{inherit.aes = TRUE} (the
-default), is combined with the default mapping at the top level of the
-plot. You only need to supply \code{mapping} if there isn't a mapping
-defined for the plot.}
+default), it is combined with the default mapping at the top level of the
+plot. You must supply \code{mapping} if there is no plot mapping.}
+
+\item{data}{The data to be displayed in this layer. There are three
+ options:
+
+ If \code{NULL}, the default, the data is inherited from the plot
+ data as specified in the call to \code{\link{ggplot}}.
-\item{data}{A data frame. If specified, overrides the default data frame
-defined at the top level of the plot.}
+ A \code{data.frame}, or other object, will override the plot
+ data. All objects will be fortified to produce a data frame. See
+ \code{\link{fortify}} for which variables will be created.
+
+ A \code{function} will be called with a single argument,
+ the plot data. The return value must be a \code{data.frame.}, and
+ will be used as the layer data.}
\item{stat}{The statistical transformation to use on the data for this
layer, as a string.}
@@ -35,17 +45,22 @@ layer, as a string.}
\item{position}{Position adjustment, either as a string, or the result of
a call to a position adjustment function.}
+\item{...}{other arguments passed on to \code{\link{layer}}. These are
+often aesthetics, used to set an aesthetic to a fixed value, like
+\code{color = "red"} or \code{size = 3}. They may also be parameters
+to the paired geom/stat.}
+
\item{lineend}{Line end style (round, butt, square)}
\item{linejoin}{Line join style (round, mitre, bevel)}
\item{linemitre}{Line mitre limit (number greater than 1)}
+\item{arrow}{Arrow specification, as created by \code{\link[grid]{arrow}}}
+
\item{na.rm}{If \code{FALSE} (the default), removes missing values with
a warning. If \code{TRUE} silently removes missing values.}
-\item{arrow}{Arrow specification, as created by \code{\link[grid]{arrow}}}
-
\item{show.legend}{logical. Should this layer be included in the legends?
\code{NA}, the default, includes if any aesthetics are mapped.
\code{FALSE} never includes, and \code{TRUE} always includes.}
@@ -55,17 +70,6 @@ rather than combining with them. This is most useful for helper functions
that define both data and aesthetics and shouldn't inherit behaviour from
the default plot specification, e.g. \code{\link{borders}}.}
-\item{...}{other arguments passed on to \code{\link{layer}}. There are
- three types of arguments you can use here:
-
- \itemize{
- \item Aesthetics: to set an aesthetic to a fixed value, like
- \code{color = "red"} or \code{size = 3}.
- \item Other arguments to the layer, for example you override the
- default \code{stat} associated with the layer.
- \item Other arguments passed on to the stat.
- }}
-
\item{direction}{direction of stairs: 'vh' for vertical then horizontal, or
'hv' for horizontal then vertical}
}
diff --git a/man/geom_point.Rd b/man/geom_point.Rd
index 87cd111..9f09da5 100644
--- a/man/geom_point.Rd
+++ b/man/geom_point.Rd
@@ -5,18 +5,28 @@
\title{Points, as for a scatterplot}
\usage{
geom_point(mapping = NULL, data = NULL, stat = "identity",
- position = "identity", na.rm = FALSE, show.legend = NA,
- inherit.aes = TRUE, ...)
+ position = "identity", ..., na.rm = FALSE, show.legend = NA,
+ inherit.aes = TRUE)
}
\arguments{
\item{mapping}{Set of aesthetic mappings created by \code{\link{aes}} or
\code{\link{aes_}}. If specified and \code{inherit.aes = TRUE} (the
-default), is combined with the default mapping at the top level of the
-plot. You only need to supply \code{mapping} if there isn't a mapping
-defined for the plot.}
+default), it is combined with the default mapping at the top level of the
+plot. You must supply \code{mapping} if there is no plot mapping.}
-\item{data}{A data frame. If specified, overrides the default data frame
-defined at the top level of the plot.}
+\item{data}{The data to be displayed in this layer. There are three
+ options:
+
+ If \code{NULL}, the default, the data is inherited from the plot
+ data as specified in the call to \code{\link{ggplot}}.
+
+ A \code{data.frame}, or other object, will override the plot
+ data. All objects will be fortified to produce a data frame. See
+ \code{\link{fortify}} for which variables will be created.
+
+ A \code{function} will be called with a single argument,
+ the plot data. The return value must be a \code{data.frame.}, and
+ will be used as the layer data.}
\item{stat}{The statistical transformation to use on the data for this
layer, as a string.}
@@ -24,6 +34,11 @@ layer, as a string.}
\item{position}{Position adjustment, either as a string, or the result of
a call to a position adjustment function.}
+\item{...}{other arguments passed on to \code{\link{layer}}. These are
+often aesthetics, used to set an aesthetic to a fixed value, like
+\code{color = "red"} or \code{size = 3}. They may also be parameters
+to the paired geom/stat.}
+
\item{na.rm}{If \code{FALSE} (the default), removes missing values with
a warning. If \code{TRUE} silently removes missing values.}
@@ -35,17 +50,6 @@ a warning. If \code{TRUE} silently removes missing values.}
rather than combining with them. This is most useful for helper functions
that define both data and aesthetics and shouldn't inherit behaviour from
the default plot specification, e.g. \code{\link{borders}}.}
-
-\item{...}{other arguments passed on to \code{\link{layer}}. There are
- three types of arguments you can use here:
-
- \itemize{
- \item Aesthetics: to set an aesthetic to a fixed value, like
- \code{color = "red"} or \code{size = 3}.
- \item Other arguments to the layer, for example you override the
- default \code{stat} associated with the layer.
- \item Other arguments passed on to the stat.
- }}
}
\description{
The point geom is used to create scatterplots.
diff --git a/man/geom_polygon.Rd b/man/geom_polygon.Rd
index 0065219..74ccde0 100644
--- a/man/geom_polygon.Rd
+++ b/man/geom_polygon.Rd
@@ -5,18 +5,28 @@
\title{Polygon, a filled path.}
\usage{
geom_polygon(mapping = NULL, data = NULL, stat = "identity",
- position = "identity", na.rm = FALSE, show.legend = NA,
- inherit.aes = TRUE, ...)
+ position = "identity", ..., na.rm = FALSE, show.legend = NA,
+ inherit.aes = TRUE)
}
\arguments{
\item{mapping}{Set of aesthetic mappings created by \code{\link{aes}} or
\code{\link{aes_}}. If specified and \code{inherit.aes = TRUE} (the
-default), is combined with the default mapping at the top level of the
-plot. You only need to supply \code{mapping} if there isn't a mapping
-defined for the plot.}
+default), it is combined with the default mapping at the top level of the
+plot. You must supply \code{mapping} if there is no plot mapping.}
-\item{data}{A data frame. If specified, overrides the default data frame
-defined at the top level of the plot.}
+\item{data}{The data to be displayed in this layer. There are three
+ options:
+
+ If \code{NULL}, the default, the data is inherited from the plot
+ data as specified in the call to \code{\link{ggplot}}.
+
+ A \code{data.frame}, or other object, will override the plot
+ data. All objects will be fortified to produce a data frame. See
+ \code{\link{fortify}} for which variables will be created.
+
+ A \code{function} will be called with a single argument,
+ the plot data. The return value must be a \code{data.frame.}, and
+ will be used as the layer data.}
\item{stat}{The statistical transformation to use on the data for this
layer, as a string.}
@@ -24,6 +34,11 @@ layer, as a string.}
\item{position}{Position adjustment, either as a string, or the result of
a call to a position adjustment function.}
+\item{...}{other arguments passed on to \code{\link{layer}}. These are
+often aesthetics, used to set an aesthetic to a fixed value, like
+\code{color = "red"} or \code{size = 3}. They may also be parameters
+to the paired geom/stat.}
+
\item{na.rm}{If \code{FALSE} (the default), removes missing values with
a warning. If \code{TRUE} silently removes missing values.}
@@ -35,17 +50,6 @@ a warning. If \code{TRUE} silently removes missing values.}
rather than combining with them. This is most useful for helper functions
that define both data and aesthetics and shouldn't inherit behaviour from
the default plot specification, e.g. \code{\link{borders}}.}
-
-\item{...}{other arguments passed on to \code{\link{layer}}. There are
- three types of arguments you can use here:
-
- \itemize{
- \item Aesthetics: to set an aesthetic to a fixed value, like
- \code{color = "red"} or \code{size = 3}.
- \item Other arguments to the layer, for example you override the
- default \code{stat} associated with the layer.
- \item Other arguments passed on to the stat.
- }}
}
\description{
Polygon, a filled path.
diff --git a/man/geom_quantile.Rd b/man/geom_quantile.Rd
index 64633c3..1760e9f 100644
--- a/man/geom_quantile.Rd
+++ b/man/geom_quantile.Rd
@@ -6,28 +6,42 @@
\title{Add quantile lines from a quantile regression.}
\usage{
geom_quantile(mapping = NULL, data = NULL, stat = "quantile",
- position = "identity", lineend = "butt", linejoin = "round",
- linemitre = 1, na.rm = FALSE, show.legend = NA, inherit.aes = TRUE,
- ...)
+ position = "identity", ..., lineend = "butt", linejoin = "round",
+ linemitre = 1, na.rm = FALSE, show.legend = NA, inherit.aes = TRUE)
stat_quantile(mapping = NULL, data = NULL, geom = "quantile",
- position = "identity", quantiles = c(0.25, 0.5, 0.75), formula = NULL,
- method = "rq", method.args = list(), na.rm = FALSE, show.legend = NA,
- inherit.aes = TRUE, ...)
+ position = "identity", ..., quantiles = c(0.25, 0.5, 0.75),
+ formula = NULL, method = "rq", method.args = list(), na.rm = FALSE,
+ show.legend = NA, inherit.aes = TRUE)
}
\arguments{
\item{mapping}{Set of aesthetic mappings created by \code{\link{aes}} or
\code{\link{aes_}}. If specified and \code{inherit.aes = TRUE} (the
-default), is combined with the default mapping at the top level of the
-plot. You only need to supply \code{mapping} if there isn't a mapping
-defined for the plot.}
+default), it is combined with the default mapping at the top level of the
+plot. You must supply \code{mapping} if there is no plot mapping.}
-\item{data}{A data frame. If specified, overrides the default data frame
-defined at the top level of the plot.}
+\item{data}{The data to be displayed in this layer. There are three
+ options:
+
+ If \code{NULL}, the default, the data is inherited from the plot
+ data as specified in the call to \code{\link{ggplot}}.
+
+ A \code{data.frame}, or other object, will override the plot
+ data. All objects will be fortified to produce a data frame. See
+ \code{\link{fortify}} for which variables will be created.
+
+ A \code{function} will be called with a single argument,
+ the plot data. The return value must be a \code{data.frame.}, and
+ will be used as the layer data.}
\item{position}{Position adjustment, either as a string, or the result of
a call to a position adjustment function.}
+\item{...}{other arguments passed on to \code{\link{layer}}. These are
+often aesthetics, used to set an aesthetic to a fixed value, like
+\code{color = "red"} or \code{size = 3}. They may also be parameters
+to the paired geom/stat.}
+
\item{lineend}{Line end style (round, butt, square)}
\item{linejoin}{Line join style (round, mitre, bevel)}
@@ -46,17 +60,6 @@ rather than combining with them. This is most useful for helper functions
that define both data and aesthetics and shouldn't inherit behaviour from
the default plot specification, e.g. \code{\link{borders}}.}
-\item{...}{other arguments passed on to \code{\link{layer}}. There are
- three types of arguments you can use here:
-
- \itemize{
- \item Aesthetics: to set an aesthetic to a fixed value, like
- \code{color = "red"} or \code{size = 3}.
- \item Other arguments to the layer, for example you override the
- default \code{stat} associated with the layer.
- \item Other arguments passed on to the stat.
- }}
-
\item{geom, stat}{Use to override the default connection between
\code{geom_quantile} and \code{stat_quantile}.}
diff --git a/man/geom_ribbon.Rd b/man/geom_ribbon.Rd
index 74b12ea..73dc930 100644
--- a/man/geom_ribbon.Rd
+++ b/man/geom_ribbon.Rd
@@ -6,8 +6,8 @@
\title{Ribbons and area plots.}
\usage{
geom_ribbon(mapping = NULL, data = NULL, stat = "identity",
- position = "identity", na.rm = FALSE, show.legend = NA,
- inherit.aes = TRUE, ...)
+ position = "identity", ..., na.rm = FALSE, show.legend = NA,
+ inherit.aes = TRUE)
geom_area(mapping = NULL, data = NULL, stat = "identity",
position = "stack", na.rm = FALSE, show.legend = NA,
@@ -16,12 +16,22 @@ geom_area(mapping = NULL, data = NULL, stat = "identity",
\arguments{
\item{mapping}{Set of aesthetic mappings created by \code{\link{aes}} or
\code{\link{aes_}}. If specified and \code{inherit.aes = TRUE} (the
-default), is combined with the default mapping at the top level of the
-plot. You only need to supply \code{mapping} if there isn't a mapping
-defined for the plot.}
+default), it is combined with the default mapping at the top level of the
+plot. You must supply \code{mapping} if there is no plot mapping.}
+
+\item{data}{The data to be displayed in this layer. There are three
+ options:
+
+ If \code{NULL}, the default, the data is inherited from the plot
+ data as specified in the call to \code{\link{ggplot}}.
+
+ A \code{data.frame}, or other object, will override the plot
+ data. All objects will be fortified to produce a data frame. See
+ \code{\link{fortify}} for which variables will be created.
-\item{data}{A data frame. If specified, overrides the default data frame
-defined at the top level of the plot.}
+ A \code{function} will be called with a single argument,
+ the plot data. The return value must be a \code{data.frame.}, and
+ will be used as the layer data.}
\item{stat}{The statistical transformation to use on the data for this
layer, as a string.}
@@ -29,6 +39,11 @@ layer, as a string.}
\item{position}{Position adjustment, either as a string, or the result of
a call to a position adjustment function.}
+\item{...}{other arguments passed on to \code{\link{layer}}. These are
+often aesthetics, used to set an aesthetic to a fixed value, like
+\code{color = "red"} or \code{size = 3}. They may also be parameters
+to the paired geom/stat.}
+
\item{na.rm}{If \code{FALSE} (the default), removes missing values with
a warning. If \code{TRUE} silently removes missing values.}
@@ -40,17 +55,6 @@ a warning. If \code{TRUE} silently removes missing values.}
rather than combining with them. This is most useful for helper functions
that define both data and aesthetics and shouldn't inherit behaviour from
the default plot specification, e.g. \code{\link{borders}}.}
-
-\item{...}{other arguments passed on to \code{\link{layer}}. There are
- three types of arguments you can use here:
-
- \itemize{
- \item Aesthetics: to set an aesthetic to a fixed value, like
- \code{color = "red"} or \code{size = 3}.
- \item Other arguments to the layer, for example you override the
- default \code{stat} associated with the layer.
- \item Other arguments passed on to the stat.
- }}
}
\description{
For each continuous x value, \code{geom_interval} displays a y interval.
diff --git a/man/geom_rug.Rd b/man/geom_rug.Rd
index 8215bd2..165e913 100644
--- a/man/geom_rug.Rd
+++ b/man/geom_rug.Rd
@@ -5,18 +5,28 @@
\title{Marginal rug plots.}
\usage{
geom_rug(mapping = NULL, data = NULL, stat = "identity",
- position = "identity", sides = "bl", na.rm = FALSE, show.legend = NA,
- inherit.aes = TRUE, ...)
+ position = "identity", ..., sides = "bl", na.rm = FALSE,
+ show.legend = NA, inherit.aes = TRUE)
}
\arguments{
\item{mapping}{Set of aesthetic mappings created by \code{\link{aes}} or
\code{\link{aes_}}. If specified and \code{inherit.aes = TRUE} (the
-default), is combined with the default mapping at the top level of the
-plot. You only need to supply \code{mapping} if there isn't a mapping
-defined for the plot.}
+default), it is combined with the default mapping at the top level of the
+plot. You must supply \code{mapping} if there is no plot mapping.}
-\item{data}{A data frame. If specified, overrides the default data frame
-defined at the top level of the plot.}
+\item{data}{The data to be displayed in this layer. There are three
+ options:
+
+ If \code{NULL}, the default, the data is inherited from the plot
+ data as specified in the call to \code{\link{ggplot}}.
+
+ A \code{data.frame}, or other object, will override the plot
+ data. All objects will be fortified to produce a data frame. See
+ \code{\link{fortify}} for which variables will be created.
+
+ A \code{function} will be called with a single argument,
+ the plot data. The return value must be a \code{data.frame.}, and
+ will be used as the layer data.}
\item{stat}{The statistical transformation to use on the data for this
layer, as a string.}
@@ -24,6 +34,11 @@ layer, as a string.}
\item{position}{Position adjustment, either as a string, or the result of
a call to a position adjustment function.}
+\item{...}{other arguments passed on to \code{\link{layer}}. These are
+often aesthetics, used to set an aesthetic to a fixed value, like
+\code{color = "red"} or \code{size = 3}. They may also be parameters
+to the paired geom/stat.}
+
\item{sides}{A string that controls which sides of the plot the rugs appear on.
It can be set to a string containing any of \code{"trbl"}, for top, right,
bottom, and left.}
@@ -39,17 +54,6 @@ a warning. If \code{TRUE} silently removes missing values.}
rather than combining with them. This is most useful for helper functions
that define both data and aesthetics and shouldn't inherit behaviour from
the default plot specification, e.g. \code{\link{borders}}.}
-
-\item{...}{other arguments passed on to \code{\link{layer}}. There are
- three types of arguments you can use here:
-
- \itemize{
- \item Aesthetics: to set an aesthetic to a fixed value, like
- \code{color = "red"} or \code{size = 3}.
- \item Other arguments to the layer, for example you override the
- default \code{stat} associated with the layer.
- \item Other arguments passed on to the stat.
- }}
}
\description{
Marginal rug plots.
diff --git a/man/geom_segment.Rd b/man/geom_segment.Rd
index 2811552..3a5e0b7 100644
--- a/man/geom_segment.Rd
+++ b/man/geom_segment.Rd
@@ -6,23 +6,33 @@
\title{Line segments and curves.}
\usage{
geom_segment(mapping = NULL, data = NULL, stat = "identity",
- position = "identity", arrow = NULL, lineend = "butt", na.rm = FALSE,
- show.legend = NA, inherit.aes = TRUE, ...)
+ position = "identity", ..., arrow = NULL, lineend = "butt",
+ na.rm = FALSE, show.legend = NA, inherit.aes = TRUE)
geom_curve(mapping = NULL, data = NULL, stat = "identity",
- position = "identity", curvature = 0.5, angle = 90, ncp = 5,
+ position = "identity", ..., curvature = 0.5, angle = 90, ncp = 5,
arrow = NULL, lineend = "butt", na.rm = FALSE, show.legend = NA,
- inherit.aes = TRUE, ...)
+ inherit.aes = TRUE)
}
\arguments{
\item{mapping}{Set of aesthetic mappings created by \code{\link{aes}} or
\code{\link{aes_}}. If specified and \code{inherit.aes = TRUE} (the
-default), is combined with the default mapping at the top level of the
-plot. You only need to supply \code{mapping} if there isn't a mapping
-defined for the plot.}
+default), it is combined with the default mapping at the top level of the
+plot. You must supply \code{mapping} if there is no plot mapping.}
-\item{data}{A data frame. If specified, overrides the default data frame
-defined at the top level of the plot.}
+\item{data}{The data to be displayed in this layer. There are three
+ options:
+
+ If \code{NULL}, the default, the data is inherited from the plot
+ data as specified in the call to \code{\link{ggplot}}.
+
+ A \code{data.frame}, or other object, will override the plot
+ data. All objects will be fortified to produce a data frame. See
+ \code{\link{fortify}} for which variables will be created.
+
+ A \code{function} will be called with a single argument,
+ the plot data. The return value must be a \code{data.frame.}, and
+ will be used as the layer data.}
\item{stat}{The statistical transformation to use on the data for this
layer, as a string.}
@@ -30,6 +40,11 @@ layer, as a string.}
\item{position}{Position adjustment, either as a string, or the result of
a call to a position adjustment function.}
+\item{...}{other arguments passed on to \code{\link{layer}}. These are
+often aesthetics, used to set an aesthetic to a fixed value, like
+\code{color = "red"} or \code{size = 3}. They may also be parameters
+to the paired geom/stat.}
+
\item{arrow}{specification for arrow heads, as created by arrow()}
\item{lineend}{Line end style (round, butt, square)}
@@ -46,17 +61,6 @@ rather than combining with them. This is most useful for helper functions
that define both data and aesthetics and shouldn't inherit behaviour from
the default plot specification, e.g. \code{\link{borders}}.}
-\item{...}{other arguments passed on to \code{\link{layer}}. There are
- three types of arguments you can use here:
-
- \itemize{
- \item Aesthetics: to set an aesthetic to a fixed value, like
- \code{color = "red"} or \code{size = 3}.
- \item Other arguments to the layer, for example you override the
- default \code{stat} associated with the layer.
- \item Other arguments passed on to the stat.
- }}
-
\item{curvature}{A numeric value giving the amount of curvature.
Negative values produce left-hand curves, positive values
produce right-hand curves, and zero produces a straight line.}
diff --git a/man/geom_smooth.Rd b/man/geom_smooth.Rd
index cbccc26..67a36ca 100644
--- a/man/geom_smooth.Rd
+++ b/man/geom_smooth.Rd
@@ -6,24 +6,42 @@
\title{Add a smoothed conditional mean.}
\usage{
geom_smooth(mapping = NULL, data = NULL, stat = "smooth",
- method = "auto", formula = y ~ x, se = TRUE, position = "identity",
- na.rm = FALSE, show.legend = NA, inherit.aes = TRUE, ...)
+ position = "identity", ..., method = "auto", formula = y ~ x,
+ se = TRUE, na.rm = FALSE, show.legend = NA, inherit.aes = TRUE)
stat_smooth(mapping = NULL, data = NULL, geom = "smooth",
- position = "identity", method = "auto", formula = y ~ x, se = TRUE,
- n = 80, span = 0.75, fullrange = FALSE, level = 0.95,
+ position = "identity", ..., method = "auto", formula = y ~ x,
+ se = TRUE, n = 80, span = 0.75, fullrange = FALSE, level = 0.95,
method.args = list(), na.rm = FALSE, show.legend = NA,
- inherit.aes = TRUE, ...)
+ inherit.aes = TRUE)
}
\arguments{
\item{mapping}{Set of aesthetic mappings created by \code{\link{aes}} or
\code{\link{aes_}}. If specified and \code{inherit.aes = TRUE} (the
-default), is combined with the default mapping at the top level of the
-plot. You only need to supply \code{mapping} if there isn't a mapping
-defined for the plot.}
+default), it is combined with the default mapping at the top level of the
+plot. You must supply \code{mapping} if there is no plot mapping.}
-\item{data}{A data frame. If specified, overrides the default data frame
-defined at the top level of the plot.}
+\item{data}{The data to be displayed in this layer. There are three
+ options:
+
+ If \code{NULL}, the default, the data is inherited from the plot
+ data as specified in the call to \code{\link{ggplot}}.
+
+ A \code{data.frame}, or other object, will override the plot
+ data. All objects will be fortified to produce a data frame. See
+ \code{\link{fortify}} for which variables will be created.
+
+ A \code{function} will be called with a single argument,
+ the plot data. The return value must be a \code{data.frame.}, and
+ will be used as the layer data.}
+
+\item{position}{Position adjustment, either as a string, or the result of
+a call to a position adjustment function.}
+
+\item{...}{other arguments passed on to \code{\link{layer}}. These are
+often aesthetics, used to set an aesthetic to a fixed value, like
+\code{color = "red"} or \code{size = 3}. They may also be parameters
+to the paired geom/stat.}
\item{method}{smoothing method (function) to use, eg. lm, glm, gam, loess,
rlm. For datasets with n < 1000 default is \code{\link{loess}}. For datasets
@@ -36,9 +54,6 @@ for more details.}
\item{se}{display confidence interval around smooth? (TRUE by default, see
level to control}
-\item{position}{Position adjustment, either as a string, or the result of
-a call to a position adjustment function.}
-
\item{na.rm}{If \code{FALSE} (the default), removes missing values with
a warning. If \code{TRUE} silently removes missing values.}
@@ -51,17 +66,6 @@ rather than combining with them. This is most useful for helper functions
that define both data and aesthetics and shouldn't inherit behaviour from
the default plot specification, e.g. \code{\link{borders}}.}
-\item{...}{other arguments passed on to \code{\link{layer}}. There are
- three types of arguments you can use here:
-
- \itemize{
- \item Aesthetics: to set an aesthetic to a fixed value, like
- \code{color = "red"} or \code{size = 3}.
- \item Other arguments to the layer, for example you override the
- default \code{stat} associated with the layer.
- \item Other arguments passed on to the stat.
- }}
-
\item{geom, stat}{Use to override the default connection between
\code{geom_smooth} and \code{stat_smooth}.}
@@ -139,13 +143,12 @@ ggplot(mpg, aes(displ, hwy)) +
geom_smooth(span = 0.8) +
facet_wrap(~drv)
-\dontrun{
-# To fit a logistic regression, you need to coerce the values to
-# a numeric vector lying between 0 and 1.
+\donttest{
binomial_smooth <- function(...) {
geom_smooth(method = "glm", method.args = list(family = "binomial"), ...)
}
-
+# To fit a logistic regression, you need to coerce the values to
+# a numeric vector lying between 0 and 1.
ggplot(rpart::kyphosis, aes(Age, Kyphosis)) +
geom_jitter(height = 0.05) +
binomial_smooth()
diff --git a/man/geom_spoke.Rd b/man/geom_spoke.Rd
index b74a4ba..0e0316f 100644
--- a/man/geom_spoke.Rd
+++ b/man/geom_spoke.Rd
@@ -6,18 +6,28 @@
\title{A line segment parameterised by location, direction and distance.}
\usage{
geom_spoke(mapping = NULL, data = NULL, stat = "identity",
- position = "identity", na.rm = FALSE, show.legend = NA,
- inherit.aes = TRUE, ...)
+ position = "identity", ..., na.rm = FALSE, show.legend = NA,
+ inherit.aes = TRUE)
}
\arguments{
\item{mapping}{Set of aesthetic mappings created by \code{\link{aes}} or
\code{\link{aes_}}. If specified and \code{inherit.aes = TRUE} (the
-default), is combined with the default mapping at the top level of the
-plot. You only need to supply \code{mapping} if there isn't a mapping
-defined for the plot.}
+default), it is combined with the default mapping at the top level of the
+plot. You must supply \code{mapping} if there is no plot mapping.}
-\item{data}{A data frame. If specified, overrides the default data frame
-defined at the top level of the plot.}
+\item{data}{The data to be displayed in this layer. There are three
+ options:
+
+ If \code{NULL}, the default, the data is inherited from the plot
+ data as specified in the call to \code{\link{ggplot}}.
+
+ A \code{data.frame}, or other object, will override the plot
+ data. All objects will be fortified to produce a data frame. See
+ \code{\link{fortify}} for which variables will be created.
+
+ A \code{function} will be called with a single argument,
+ the plot data. The return value must be a \code{data.frame.}, and
+ will be used as the layer data.}
\item{stat}{The statistical transformation to use on the data for this
layer, as a string.}
@@ -25,6 +35,11 @@ layer, as a string.}
\item{position}{Position adjustment, either as a string, or the result of
a call to a position adjustment function.}
+\item{...}{other arguments passed on to \code{\link{layer}}. These are
+often aesthetics, used to set an aesthetic to a fixed value, like
+\code{color = "red"} or \code{size = 3}. They may also be parameters
+to the paired geom/stat.}
+
\item{na.rm}{If \code{FALSE} (the default), removes missing values with
a warning. If \code{TRUE} silently removes missing values.}
@@ -36,17 +51,6 @@ a warning. If \code{TRUE} silently removes missing values.}
rather than combining with them. This is most useful for helper functions
that define both data and aesthetics and shouldn't inherit behaviour from
the default plot specification, e.g. \code{\link{borders}}.}
-
-\item{...}{other arguments passed on to \code{\link{layer}}. There are
- three types of arguments you can use here:
-
- \itemize{
- \item Aesthetics: to set an aesthetic to a fixed value, like
- \code{color = "red"} or \code{size = 3}.
- \item Other arguments to the layer, for example you override the
- default \code{stat} associated with the layer.
- \item Other arguments passed on to the stat.
- }}
}
\description{
A line segment parameterised by location, direction and distance.
diff --git a/man/geom_text.Rd b/man/geom_text.Rd
index 1a620b5..5efb40f 100644
--- a/man/geom_text.Rd
+++ b/man/geom_text.Rd
@@ -6,25 +6,35 @@
\title{Textual annotations.}
\usage{
geom_label(mapping = NULL, data = NULL, stat = "identity",
- position = "identity", parse = FALSE, ..., nudge_x = 0, nudge_y = 0,
+ position = "identity", ..., parse = FALSE, nudge_x = 0, nudge_y = 0,
label.padding = unit(0.25, "lines"), label.r = unit(0.15, "lines"),
label.size = 0.25, na.rm = FALSE, show.legend = NA,
inherit.aes = TRUE)
geom_text(mapping = NULL, data = NULL, stat = "identity",
- position = "identity", parse = FALSE, ..., nudge_x = 0, nudge_y = 0,
+ position = "identity", ..., parse = FALSE, nudge_x = 0, nudge_y = 0,
check_overlap = FALSE, na.rm = FALSE, show.legend = NA,
inherit.aes = TRUE)
}
\arguments{
\item{mapping}{Set of aesthetic mappings created by \code{\link{aes}} or
\code{\link{aes_}}. If specified and \code{inherit.aes = TRUE} (the
-default), is combined with the default mapping at the top level of the
-plot. You only need to supply \code{mapping} if there isn't a mapping
-defined for the plot.}
+default), it is combined with the default mapping at the top level of the
+plot. You must supply \code{mapping} if there is no plot mapping.}
-\item{data}{A data frame. If specified, overrides the default data frame
-defined at the top level of the plot.}
+\item{data}{The data to be displayed in this layer. There are three
+ options:
+
+ If \code{NULL}, the default, the data is inherited from the plot
+ data as specified in the call to \code{\link{ggplot}}.
+
+ A \code{data.frame}, or other object, will override the plot
+ data. All objects will be fortified to produce a data frame. See
+ \code{\link{fortify}} for which variables will be created.
+
+ A \code{function} will be called with a single argument,
+ the plot data. The return value must be a \code{data.frame.}, and
+ will be used as the layer data.}
\item{stat}{The statistical transformation to use on the data for this
layer, as a string.}
@@ -32,20 +42,14 @@ layer, as a string.}
\item{position}{Position adjustment, either as a string, or the result of
a call to a position adjustment function.}
+\item{...}{other arguments passed on to \code{\link{layer}}. These are
+often aesthetics, used to set an aesthetic to a fixed value, like
+\code{color = "red"} or \code{size = 3}. They may also be parameters
+to the paired geom/stat.}
+
\item{parse}{If TRUE, the labels will be parsed into expressions and
displayed as described in ?plotmath}
-\item{...}{other arguments passed on to \code{\link{layer}}. There are
- three types of arguments you can use here:
-
- \itemize{
- \item Aesthetics: to set an aesthetic to a fixed value, like
- \code{color = "red"} or \code{size = 3}.
- \item Other arguments to the layer, for example you override the
- default \code{stat} associated with the layer.
- \item Other arguments passed on to the stat.
- }}
-
\item{nudge_x, nudge_y}{Horizontal and vertical adjustment to nudge labels by.
Useful for offsetting text from points, particularly on discrete scales.}
@@ -119,6 +123,7 @@ p + geom_point() + geom_text(hjust = 0, nudge_x = 0.05)
p + geom_point() + geom_text(vjust = 0, nudge_y = 0.5)
p + geom_point() + geom_text(angle = 45)
\dontrun{
+# Doesn't work on all systems
p + geom_text(family = "Times New Roman")
}
diff --git a/man/geom_tile.Rd b/man/geom_tile.Rd
index b8c8eca..096b101 100644
--- a/man/geom_tile.Rd
+++ b/man/geom_tile.Rd
@@ -7,26 +7,37 @@
\title{Draw rectangles.}
\usage{
geom_raster(mapping = NULL, data = NULL, stat = "identity",
- position = "identity", hjust = 0.5, vjust = 0.5, interpolate = FALSE,
- na.rm = FALSE, show.legend = NA, inherit.aes = TRUE, ...)
+ position = "identity", ..., hjust = 0.5, vjust = 0.5,
+ interpolate = FALSE, na.rm = FALSE, show.legend = NA,
+ inherit.aes = TRUE)
geom_rect(mapping = NULL, data = NULL, stat = "identity",
- position = "identity", na.rm = FALSE, show.legend = NA,
- inherit.aes = TRUE, ...)
+ position = "identity", ..., na.rm = FALSE, show.legend = NA,
+ inherit.aes = TRUE)
geom_tile(mapping = NULL, data = NULL, stat = "identity",
- position = "identity", na.rm = FALSE, show.legend = NA,
- inherit.aes = TRUE, ...)
+ position = "identity", ..., na.rm = FALSE, show.legend = NA,
+ inherit.aes = TRUE)
}
\arguments{
\item{mapping}{Set of aesthetic mappings created by \code{\link{aes}} or
\code{\link{aes_}}. If specified and \code{inherit.aes = TRUE} (the
-default), is combined with the default mapping at the top level of the
-plot. You only need to supply \code{mapping} if there isn't a mapping
-defined for the plot.}
+default), it is combined with the default mapping at the top level of the
+plot. You must supply \code{mapping} if there is no plot mapping.}
-\item{data}{A data frame. If specified, overrides the default data frame
-defined at the top level of the plot.}
+\item{data}{The data to be displayed in this layer. There are three
+ options:
+
+ If \code{NULL}, the default, the data is inherited from the plot
+ data as specified in the call to \code{\link{ggplot}}.
+
+ A \code{data.frame}, or other object, will override the plot
+ data. All objects will be fortified to produce a data frame. See
+ \code{\link{fortify}} for which variables will be created.
+
+ A \code{function} will be called with a single argument,
+ the plot data. The return value must be a \code{data.frame.}, and
+ will be used as the layer data.}
\item{stat}{The statistical transformation to use on the data for this
layer, as a string.}
@@ -34,6 +45,11 @@ layer, as a string.}
\item{position}{Position adjustment, either as a string, or the result of
a call to a position adjustment function.}
+\item{...}{other arguments passed on to \code{\link{layer}}. These are
+often aesthetics, used to set an aesthetic to a fixed value, like
+\code{color = "red"} or \code{size = 3}. They may also be parameters
+to the paired geom/stat.}
+
\item{hjust, vjust}{horizontal and vertical justification of the grob. Each
justification value should be a number between 0 and 1. Defaults to 0.5
for both, centering each pixel over its data location.}
@@ -52,17 +68,6 @@ a warning. If \code{TRUE} silently removes missing values.}
rather than combining with them. This is most useful for helper functions
that define both data and aesthetics and shouldn't inherit behaviour from
the default plot specification, e.g. \code{\link{borders}}.}
-
-\item{...}{other arguments passed on to \code{\link{layer}}. There are
- three types of arguments you can use here:
-
- \itemize{
- \item Aesthetics: to set an aesthetic to a fixed value, like
- \code{color = "red"} or \code{size = 3}.
- \item Other arguments to the layer, for example you override the
- default \code{stat} associated with the layer.
- \item Other arguments passed on to the stat.
- }}
}
\description{
\code{geom_rect} and \code{geom_tile} do the same thing, but are
diff --git a/man/geom_violin.Rd b/man/geom_violin.Rd
index 00b6a74..545833b 100644
--- a/man/geom_violin.Rd
+++ b/man/geom_violin.Rd
@@ -6,31 +6,45 @@
\title{Violin plot.}
\usage{
geom_violin(mapping = NULL, data = NULL, stat = "ydensity",
- draw_quantiles = NULL, position = "dodge", trim = TRUE,
- scale = "area", na.rm = FALSE, show.legend = NA, inherit.aes = TRUE,
- ...)
+ position = "dodge", ..., draw_quantiles = NULL, trim = TRUE,
+ scale = "area", na.rm = FALSE, show.legend = NA, inherit.aes = TRUE)
stat_ydensity(mapping = NULL, data = NULL, geom = "violin",
- position = "dodge", adjust = 1, kernel = "gaussian", trim = TRUE,
- scale = "area", na.rm = FALSE, show.legend = NA, inherit.aes = TRUE,
- ...)
+ position = "dodge", ..., bw = "nrd0", adjust = 1, kernel = "gaussian",
+ trim = TRUE, scale = "area", na.rm = FALSE, show.legend = NA,
+ inherit.aes = TRUE)
}
\arguments{
\item{mapping}{Set of aesthetic mappings created by \code{\link{aes}} or
\code{\link{aes_}}. If specified and \code{inherit.aes = TRUE} (the
-default), is combined with the default mapping at the top level of the
-plot. You only need to supply \code{mapping} if there isn't a mapping
-defined for the plot.}
+default), it is combined with the default mapping at the top level of the
+plot. You must supply \code{mapping} if there is no plot mapping.}
-\item{data}{A data frame. If specified, overrides the default data frame
-defined at the top level of the plot.}
+\item{data}{The data to be displayed in this layer. There are three
+ options:
-\item{draw_quantiles}{If \code{not(NULL)} (default), draw horizontal lines
-at the given quantiles of the density estimate.}
+ If \code{NULL}, the default, the data is inherited from the plot
+ data as specified in the call to \code{\link{ggplot}}.
+
+ A \code{data.frame}, or other object, will override the plot
+ data. All objects will be fortified to produce a data frame. See
+ \code{\link{fortify}} for which variables will be created.
+
+ A \code{function} will be called with a single argument,
+ the plot data. The return value must be a \code{data.frame.}, and
+ will be used as the layer data.}
\item{position}{Position adjustment, either as a string, or the result of
a call to a position adjustment function.}
+\item{...}{other arguments passed on to \code{\link{layer}}. These are
+often aesthetics, used to set an aesthetic to a fixed value, like
+\code{color = "red"} or \code{size = 3}. They may also be parameters
+to the paired geom/stat.}
+
+\item{draw_quantiles}{If \code{not(NULL)} (default), draw horizontal lines
+at the given quantiles of the density estimate.}
+
\item{trim}{If \code{TRUE} (default), trim the tails of the violins
to the range of the data. If \code{FALSE}, don't trim the tails.}
@@ -50,21 +64,14 @@ rather than combining with them. This is most useful for helper functions
that define both data and aesthetics and shouldn't inherit behaviour from
the default plot specification, e.g. \code{\link{borders}}.}
-\item{...}{other arguments passed on to \code{\link{layer}}. There are
- three types of arguments you can use here:
-
- \itemize{
- \item Aesthetics: to set an aesthetic to a fixed value, like
- \code{color = "red"} or \code{size = 3}.
- \item Other arguments to the layer, for example you override the
- default \code{stat} associated with the layer.
- \item Other arguments passed on to the stat.
- }}
-
\item{geom, stat}{Use to override the default connection between
\code{geom_violin} and \code{stat_ydensity}.}
-\item{adjust}{see \code{\link{density}} for details}
+\item{bw}{the smoothing bandwidth to be used, see
+\code{\link{density}} for details}
+
+\item{adjust}{adjustment of the bandwidth, see
+\code{\link{density}} for details}
\item{kernel}{kernel used for density estimation, see
\code{\link{density}} for details}
diff --git a/man/gg-add.Rd b/man/gg-add.Rd
index f7e990a..f72e242 100644
--- a/man/gg-add.Rd
+++ b/man/gg-add.Rd
@@ -4,7 +4,7 @@
\alias{+.gg}
\alias{\%+\%}
\alias{\%+replace\%}
-\title{Modify a ggplot or theme object by adding on new components.}
+\title{Add a new component to a ggplot or theme object.}
\usage{
\method{+}{gg}(e1, e2)
diff --git a/man/ggtheme.Rd b/man/ggtheme.Rd
index da5ab28..a0d6677 100644
--- a/man/ggtheme.Rd
+++ b/man/ggtheme.Rd
@@ -84,6 +84,7 @@ p + theme_gray()
p + theme_bw()
p + theme_linedraw()
p + theme_light()
+p + theme_dark()
p + theme_minimal()
p + theme_classic()
p + theme_void()
diff --git a/man/guide_legend.Rd b/man/guide_legend.Rd
index 4e9f8ba..e40dc89 100644
--- a/man/guide_legend.Rd
+++ b/man/guide_legend.Rd
@@ -108,7 +108,6 @@ p1 + scale_fill_continuous(guide = "legend")
p1 + scale_fill_continuous(guide = guide_legend())
# Guide title
-
p1 + scale_fill_continuous(guide = guide_legend(title = "V")) # title text
p1 + scale_fill_continuous(guide = guide_legend(title = NULL)) # no title
@@ -121,24 +120,38 @@ p1 + guides(fill = guide_legend(keywidth = 3, keyheight = 1))
p1 + guides(fill = guide_legend(title = "LEFT", title.position = "left"))
# title text styles via element_text
-p1 + guides(fill = guide_legend(
- title.theme = element_text(size=15, face="italic", colour = "red", angle = 45)))
+p1 + guides(fill =
+ guide_legend(
+ title.theme = element_text(
+ size = 15,
+ face = "italic",
+ colour = "red",
+ angle = 0
+ )
+ )
+)
# label position
-p1 + guides(fill = guide_legend(label.position = "bottom"))
+p1 + guides(fill = guide_legend(label.position = "left", label.hjust = 1))
# label styles
p1 + scale_fill_continuous(breaks = c(5, 10, 15),
labels = paste("long", c(5, 10, 15)),
- guide = guide_legend(direction = "horizontal", title.position = "top",
- label.position="bottom", label.hjust = 0.5, label.vjust = 0.5,
- label.theme = element_text(angle = 90)))
+ guide = guide_legend(
+ direction = "horizontal",
+ title.position = "top",
+ label.position = "bottom",
+ label.hjust = 0.5,
+ label.vjust = 1,
+ label.theme = element_text(angle = 90)
+ )
+)
# Set aesthetic of legend key
# very low alpha value make it difficult to see legend key
p3 <- ggplot(diamonds, aes(carat, price)) +
- geom_point(aes(colour=color), alpha=1/100)
+ geom_point(aes(colour = color), alpha = 1/100)
p3
# override.aes overwrites the alpha
diff --git a/man/layer.Rd b/man/layer.Rd
index 4896e44..050e38e 100644
--- a/man/layer.Rd
+++ b/man/layer.Rd
@@ -9,18 +9,32 @@ layer(geom = NULL, stat = NULL, data = NULL, mapping = NULL,
show.legend = NA)
}
\arguments{
-\item{geom, stat, position}{Geom, stat and position adjustment to use in
-this layer. Can either be the name of a ggproto object, or the object
-itself.}
+\item{geom}{The geometric object to use display the data}
-\item{data}{A data frame. If specified, overrides the default data frame
-defined at the top level of the plot.}
+\item{stat}{The statistical transformation to use on the data for this
+layer, as a string.}
+
+\item{data}{The data to be displayed in this layer. There are three
+ options:
+
+ If \code{NULL}, the default, the data is inherited from the plot
+ data as specified in the call to \code{\link{ggplot}}.
+
+ A \code{data.frame}, or other object, will override the plot
+ data. All objects will be fortified to produce a data frame. See
+ \code{\link{fortify}} for which variables will be created.
+
+ A \code{function} will be called with a single argument,
+ the plot data. The return value must be a \code{data.frame.}, and
+ will be used as the layer data.}
\item{mapping}{Set of aesthetic mappings created by \code{\link{aes}} or
\code{\link{aes_}}. If specified and \code{inherit.aes = TRUE} (the
-default), is combined with the default mapping at the top level of the
-plot. You only need to supply \code{mapping} if there isn't a mapping
-defined for the plot.}
+default), it is combined with the default mapping at the top level of the
+plot. You must supply \code{mapping} if there is no plot mapping.}
+
+\item{position}{Position adjustment, either as a string, or the result of
+a call to a position adjustment function.}
\item{params}{Additional parameters to the \code{geom} and \code{stat}.}
@@ -37,7 +51,9 @@ layer.}
\code{FALSE} never includes, and \code{TRUE} always includes.}
}
\description{
-Create a new layer
+A layer is a combination of data, stat and geom with a potential position
+adjustment. Usually layers are created using \code{geom_*} or \code{stat_*}
+calls but it can also be created directly using this function.
}
\examples{
# geom calls are just a short cut for layer
@@ -47,5 +63,12 @@ ggplot(mpg, aes(displ, hwy)) +
layer(geom = "point", stat = "identity", position = "identity",
params = list(na.rm = FALSE)
)
+
+# use a function as data to plot a subset of global data
+ggplot(mpg, aes(displ, hwy)) +
+ layer(geom = "point", stat = "identity", position = "identity",
+ data = head, params = list(na.rm = FALSE)
+ )
+
}
diff --git a/man/margin.Rd b/man/margin.Rd
index ed5dc1c..96c15ed 100644
--- a/man/margin.Rd
+++ b/man/margin.Rd
@@ -7,13 +7,13 @@
margin(t = 0, r = 0, b = 0, l = 0, unit = "pt")
}
\arguments{
-\item{t, b, r, l}{Dimensions of each margin. (To remember order, think trouble).}
+\item{t, r, b, l}{Dimensions of each margin. (To remember order, think trouble).}
\item{unit}{Default units of dimensions. Defaults to "pt" so it
can be most easily scaled with the text.}
}
\description{
-This is a convenience function that creates a grid unit object of the
+This is a convenient function that creates a grid unit object of the
correct length to use for setting margins.
}
\examples{
diff --git a/man/presidential.Rd b/man/presidential.Rd
index 53f5243..26a70da 100644
--- a/man/presidential.Rd
+++ b/man/presidential.Rd
@@ -3,14 +3,14 @@
\docType{data}
\name{presidential}
\alias{presidential}
-\title{Terms of 10 presidents from Eisenhower to Bush W.}
-\format{A data frame with 10 rows and 4 variables}
+\title{Terms of 11 presidents from Eisenhower to Obama.}
+\format{A data frame with 11 rows and 4 variables}
\usage{
presidential
}
\description{
The names of each president, the start and end date of their term, and
-their party of 10 US presidents from Eisenhower to Bush W.
+their party of 11 US presidents from Eisenhower to Obama.
}
\keyword{datasets}
diff --git a/man/scale_discrete.Rd b/man/scale_discrete.Rd
index 79c7f45..9efab43 100644
--- a/man/scale_discrete.Rd
+++ b/man/scale_discrete.Rd
@@ -26,10 +26,9 @@ level, and increasing by one for each level (i.e. the labels are placed
at integer positions). This is what allows jittering to work.
}
\examples{
-\donttest{
-ggplot(diamonds, aes(cut)) + stat_bin()
ggplot(diamonds, aes(cut)) + geom_bar()
+\donttest{
# The discrete position scale is added automatically whenever you
# have a discrete position.
@@ -40,9 +39,6 @@ d + scale_x_discrete("Cut")
d + scale_x_discrete("Cut", labels = c("Fair" = "F","Good" = "G",
"Very Good" = "VG","Perfect" = "P","Ideal" = "I"))
-d + scale_y_discrete("Clarity")
-d + scale_x_discrete("Cut") + scale_y_discrete("Clarity")
-
# Use limits to adjust the which levels (and in what order)
# are displayed
d + scale_x_discrete(limits=c("Fair","Ideal"))
diff --git a/man/scale_gradient.Rd b/man/scale_gradient.Rd
index 38a3ee0..1f77123 100644
--- a/man/scale_gradient.Rd
+++ b/man/scale_gradient.Rd
@@ -6,10 +6,14 @@
\alias{scale_color_gradient2}
\alias{scale_color_gradientn}
\alias{scale_colour_continuous}
+\alias{scale_colour_date}
+\alias{scale_colour_datetime}
\alias{scale_colour_gradient}
\alias{scale_colour_gradient2}
\alias{scale_colour_gradientn}
\alias{scale_fill_continuous}
+\alias{scale_fill_date}
+\alias{scale_fill_datetime}
\alias{scale_fill_gradient}
\alias{scale_fill_gradient2}
\alias{scale_fill_gradientn}
diff --git a/man/scale_shape.Rd b/man/scale_shape.Rd
index 19ecbea..fc4f6ea 100644
--- a/man/scale_shape.Rd
+++ b/man/scale_shape.Rd
@@ -7,10 +7,6 @@
\title{Scale for shapes, aka glyphs.}
\usage{
scale_shape(..., solid = TRUE)
-
-scale_shape_discrete(..., solid = TRUE)
-
-scale_shape_continuous(...)
}
\arguments{
\item{...}{common discrete scale parameters: \code{name}, \code{breaks},
diff --git a/man/scale_size.Rd b/man/scale_size.Rd
index b1ef060..86c76e8 100644
--- a/man/scale_size.Rd
+++ b/man/scale_size.Rd
@@ -5,6 +5,8 @@
\alias{scale_size}
\alias{scale_size_area}
\alias{scale_size_continuous}
+\alias{scale_size_date}
+\alias{scale_size_datetime}
\alias{scale_size_discrete}
\title{Scale size (area or radius).}
\usage{
diff --git a/man/stat_ecdf.Rd b/man/stat_ecdf.Rd
index 28db7ab..d396dba 100644
--- a/man/stat_ecdf.Rd
+++ b/man/stat_ecdf.Rd
@@ -5,25 +5,45 @@
\title{Empirical Cumulative Density Function}
\usage{
stat_ecdf(mapping = NULL, data = NULL, geom = "step",
- position = "identity", n = NULL, na.rm = FALSE, show.legend = NA,
- inherit.aes = TRUE, ...)
+ position = "identity", ..., n = NULL, pad = TRUE, na.rm = FALSE,
+ show.legend = NA, inherit.aes = TRUE)
}
\arguments{
-\item{mapping}{The aesthetic mapping, usually constructed with
-\code{\link{aes}} or \code{\link{aes_string}}. Only needs to be set
-at the layer level if you are overriding the plot defaults.}
+\item{mapping}{Set of aesthetic mappings created by \code{\link{aes}} or
+\code{\link{aes_}}. If specified and \code{inherit.aes = TRUE} (the
+default), it is combined with the default mapping at the top level of the
+plot. You must supply \code{mapping} if there is no plot mapping.}
-\item{data}{A layer specific dataset - only needed if you want to override
-the plot defaults.}
+\item{data}{The data to be displayed in this layer. There are three
+ options:
+
+ If \code{NULL}, the default, the data is inherited from the plot
+ data as specified in the call to \code{\link{ggplot}}.
+
+ A \code{data.frame}, or other object, will override the plot
+ data. All objects will be fortified to produce a data frame. See
+ \code{\link{fortify}} for which variables will be created.
+
+ A \code{function} will be called with a single argument,
+ the plot data. The return value must be a \code{data.frame.}, and
+ will be used as the layer data.}
\item{geom}{The geometric object to use display the data}
-\item{position}{The position adjustment to use for overlapping points
-on this layer}
+\item{position}{Position adjustment, either as a string, or the result of
+a call to a position adjustment function.}
+
+\item{...}{other arguments passed on to \code{\link{layer}}. These are
+often aesthetics, used to set an aesthetic to a fixed value, like
+\code{color = "red"} or \code{size = 3}. They may also be parameters
+to the paired geom/stat.}
\item{n}{if NULL, do not interpolate. If not NULL, this is the number
of points to interpolate with.}
+\item{pad}{If \code{TRUE}, pad the ecdf with additional points (-Inf, 0)
+and (Inf, 1)}
+
\item{na.rm}{If \code{FALSE} (the default), removes missing values with
a warning. If \code{TRUE} silently removes missing values.}
@@ -35,10 +55,6 @@ a warning. If \code{TRUE} silently removes missing values.}
rather than combining with them. This is most useful for helper functions
that define both data and aesthetics and shouldn't inherit behaviour from
the default plot specification, e.g. \code{\link{borders}}.}
-
-\item{...}{other arguments passed on to \code{\link{layer}}. This can
-include aesthetics whose values you want to set, not map. See
-\code{\link{layer}} for more details.}
}
\description{
Empirical Cumulative Density Function
diff --git a/man/stat_ellipse.Rd b/man/stat_ellipse.Rd
index 5abfd3e..9fdb2b8 100644
--- a/man/stat_ellipse.Rd
+++ b/man/stat_ellipse.Rd
@@ -5,21 +5,38 @@
\title{Plot data ellipses.}
\usage{
stat_ellipse(mapping = NULL, data = NULL, geom = "path",
- position = "identity", type = "t", level = 0.95, segments = 51,
- na.rm = FALSE, show.legend = NA, inherit.aes = TRUE, ...)
+ position = "identity", ..., type = "t", level = 0.95, segments = 51,
+ na.rm = FALSE, show.legend = NA, inherit.aes = TRUE)
}
\arguments{
-\item{mapping}{The aesthetic mapping, usually constructed with
-\code{\link{aes}} or \code{\link{aes_string}}. Only needs to be set
-at the layer level if you are overriding the plot defaults.}
+\item{mapping}{Set of aesthetic mappings created by \code{\link{aes}} or
+\code{\link{aes_}}. If specified and \code{inherit.aes = TRUE} (the
+default), it is combined with the default mapping at the top level of the
+plot. You must supply \code{mapping} if there is no plot mapping.}
-\item{data}{A layer specific dataset - only needed if you want to override
-the plot defaults.}
+\item{data}{The data to be displayed in this layer. There are three
+ options:
+
+ If \code{NULL}, the default, the data is inherited from the plot
+ data as specified in the call to \code{\link{ggplot}}.
+
+ A \code{data.frame}, or other object, will override the plot
+ data. All objects will be fortified to produce a data frame. See
+ \code{\link{fortify}} for which variables will be created.
+
+ A \code{function} will be called with a single argument,
+ the plot data. The return value must be a \code{data.frame.}, and
+ will be used as the layer data.}
\item{geom}{The geometric object to use display the data}
-\item{position}{The position adjustment to use for overlapping points
-on this layer}
+\item{position}{Position adjustment, either as a string, or the result of
+a call to a position adjustment function.}
+
+\item{...}{other arguments passed on to \code{\link{layer}}. These are
+often aesthetics, used to set an aesthetic to a fixed value, like
+\code{color = "red"} or \code{size = 3}. They may also be parameters
+to the paired geom/stat.}
\item{type}{The type of ellipse.
The default \code{"t"} assumes a multivariate t-distribution, and
@@ -44,10 +61,6 @@ a warning. If \code{TRUE} silently removes missing values.}
rather than combining with them. This is most useful for helper functions
that define both data and aesthetics and shouldn't inherit behaviour from
the default plot specification, e.g. \code{\link{borders}}.}
-
-\item{...}{other arguments passed on to \code{\link{layer}}. This can
-include aesthetics whose values you want to set, not map. See
-\code{\link{layer}} for more details.}
}
\description{
The method for calculating the ellipses has been modified from
diff --git a/man/stat_function.Rd b/man/stat_function.Rd
index f9548db..fedd28d 100644
--- a/man/stat_function.Rd
+++ b/man/stat_function.Rd
@@ -5,24 +5,43 @@
\title{Superimpose a function.}
\usage{
stat_function(mapping = NULL, data = NULL, geom = "path",
- position = "identity", fun, n = 101, args = list(), na.rm = FALSE,
- show.legend = NA, inherit.aes = TRUE, ...)
+ position = "identity", ..., fun, xlim = NULL, n = 101, args = list(),
+ na.rm = FALSE, show.legend = NA, inherit.aes = TRUE)
}
\arguments{
-\item{mapping}{The aesthetic mapping, usually constructed with
-\code{\link{aes}} or \code{\link{aes_string}}. Only needs to be set
-at the layer level if you are overriding the plot defaults.}
+\item{mapping}{Set of aesthetic mappings created by \code{\link{aes}} or
+\code{\link{aes_}}. If specified and \code{inherit.aes = TRUE} (the
+default), it is combined with the default mapping at the top level of the
+plot. You must supply \code{mapping} if there is no plot mapping.}
-\item{data}{A layer specific dataset - only needed if you want to override
-the plot defaults.}
+\item{data}{The data to be displayed in this layer. There are three
+ options:
+
+ If \code{NULL}, the default, the data is inherited from the plot
+ data as specified in the call to \code{\link{ggplot}}.
+
+ A \code{data.frame}, or other object, will override the plot
+ data. All objects will be fortified to produce a data frame. See
+ \code{\link{fortify}} for which variables will be created.
+
+ A \code{function} will be called with a single argument,
+ the plot data. The return value must be a \code{data.frame.}, and
+ will be used as the layer data.}
\item{geom}{The geometric object to use display the data}
-\item{position}{The position adjustment to use for overlapping points
-on this layer}
+\item{position}{Position adjustment, either as a string, or the result of
+a call to a position adjustment function.}
+
+\item{...}{other arguments passed on to \code{\link{layer}}. These are
+often aesthetics, used to set an aesthetic to a fixed value, like
+\code{color = "red"} or \code{size = 3}. They may also be parameters
+to the paired geom/stat.}
\item{fun}{function to use}
+\item{xlim}{Optionally, restrict the range of the function to this range.}
+
\item{n}{number of points to interpolate along}
\item{args}{list of additional arguments to pass to \code{fun}}
@@ -38,10 +57,6 @@ a warning. If \code{TRUE} silently removes missing values.}
rather than combining with them. This is most useful for helper functions
that define both data and aesthetics and shouldn't inherit behaviour from
the default plot specification, e.g. \code{\link{borders}}.}
-
-\item{...}{other arguments passed on to \code{\link{layer}}. This can
-include aesthetics whose values you want to set, not map. See
-\code{\link{layer}} for more details.}
}
\description{
Superimpose a function.
@@ -66,7 +81,7 @@ df <- data.frame(
x <- df$x
base <- ggplot(df, aes(x)) + geom_density()
base + stat_function(fun = dnorm, colour = "red")
-base + stat_function(fun = dnorm, colour = "red", arg = list(mean = 3))
+base + stat_function(fun = dnorm, colour = "red", args = list(mean = 3))
# Plot functions without data
# Examples adapted from Kohske Takahashi
diff --git a/man/stat_identity.Rd b/man/stat_identity.Rd
index ca50612..ffeb036 100644
--- a/man/stat_identity.Rd
+++ b/man/stat_identity.Rd
@@ -5,20 +5,37 @@
\title{Identity statistic.}
\usage{
stat_identity(mapping = NULL, data = NULL, geom = "point",
- position = "identity", show.legend = NA, inherit.aes = TRUE, ...)
+ position = "identity", ..., show.legend = NA, inherit.aes = TRUE)
}
\arguments{
-\item{mapping}{The aesthetic mapping, usually constructed with
-\code{\link{aes}} or \code{\link{aes_string}}. Only needs to be set
-at the layer level if you are overriding the plot defaults.}
+\item{mapping}{Set of aesthetic mappings created by \code{\link{aes}} or
+\code{\link{aes_}}. If specified and \code{inherit.aes = TRUE} (the
+default), it is combined with the default mapping at the top level of the
+plot. You must supply \code{mapping} if there is no plot mapping.}
-\item{data}{A layer specific dataset - only needed if you want to override
-the plot defaults.}
+\item{data}{The data to be displayed in this layer. There are three
+ options:
+
+ If \code{NULL}, the default, the data is inherited from the plot
+ data as specified in the call to \code{\link{ggplot}}.
+
+ A \code{data.frame}, or other object, will override the plot
+ data. All objects will be fortified to produce a data frame. See
+ \code{\link{fortify}} for which variables will be created.
+
+ A \code{function} will be called with a single argument,
+ the plot data. The return value must be a \code{data.frame.}, and
+ will be used as the layer data.}
\item{geom}{The geometric object to use display the data}
-\item{position}{The position adjustment to use for overlapping points
-on this layer}
+\item{position}{Position adjustment, either as a string, or the result of
+a call to a position adjustment function.}
+
+\item{...}{other arguments passed on to \code{\link{layer}}. These are
+often aesthetics, used to set an aesthetic to a fixed value, like
+\code{color = "red"} or \code{size = 3}. They may also be parameters
+to the paired geom/stat.}
\item{show.legend}{logical. Should this layer be included in the legends?
\code{NA}, the default, includes if any aesthetics are mapped.
@@ -28,10 +45,6 @@ on this layer}
rather than combining with them. This is most useful for helper functions
that define both data and aesthetics and shouldn't inherit behaviour from
the default plot specification, e.g. \code{\link{borders}}.}
-
-\item{...}{other arguments passed on to \code{\link{layer}}. This can
-include aesthetics whose values you want to set, not map. See
-\code{\link{layer}} for more details.}
}
\description{
The identity statistic leaves the data unchanged.
diff --git a/man/stat_qq.Rd b/man/stat_qq.Rd
index 897d8a3..9af1e22 100644
--- a/man/stat_qq.Rd
+++ b/man/stat_qq.Rd
@@ -6,25 +6,42 @@
\title{Calculation for quantile-quantile plot.}
\usage{
stat_qq(mapping = NULL, data = NULL, geom = "point",
- position = "identity", distribution = stats::qnorm, dparams = list(),
- na.rm = FALSE, show.legend = NA, inherit.aes = TRUE, ...)
+ position = "identity", ..., distribution = stats::qnorm,
+ dparams = list(), na.rm = FALSE, show.legend = NA, inherit.aes = TRUE)
geom_qq(mapping = NULL, data = NULL, geom = "point",
- position = "identity", distribution = stats::qnorm, dparams = list(),
- na.rm = FALSE, show.legend = NA, inherit.aes = TRUE, ...)
+ position = "identity", ..., distribution = stats::qnorm,
+ dparams = list(), na.rm = FALSE, show.legend = NA, inherit.aes = TRUE)
}
\arguments{
-\item{mapping}{The aesthetic mapping, usually constructed with
-\code{\link{aes}} or \code{\link{aes_string}}. Only needs to be set
-at the layer level if you are overriding the plot defaults.}
+\item{mapping}{Set of aesthetic mappings created by \code{\link{aes}} or
+\code{\link{aes_}}. If specified and \code{inherit.aes = TRUE} (the
+default), it is combined with the default mapping at the top level of the
+plot. You must supply \code{mapping} if there is no plot mapping.}
-\item{data}{A layer specific dataset - only needed if you want to override
-the plot defaults.}
+\item{data}{The data to be displayed in this layer. There are three
+ options:
+
+ If \code{NULL}, the default, the data is inherited from the plot
+ data as specified in the call to \code{\link{ggplot}}.
+
+ A \code{data.frame}, or other object, will override the plot
+ data. All objects will be fortified to produce a data frame. See
+ \code{\link{fortify}} for which variables will be created.
+
+ A \code{function} will be called with a single argument,
+ the plot data. The return value must be a \code{data.frame.}, and
+ will be used as the layer data.}
\item{geom}{The geometric object to use display the data}
-\item{position}{The position adjustment to use for overlapping points
-on this layer}
+\item{position}{Position adjustment, either as a string, or the result of
+a call to a position adjustment function.}
+
+\item{...}{other arguments passed on to \code{\link{layer}}. These are
+often aesthetics, used to set an aesthetic to a fixed value, like
+\code{color = "red"} or \code{size = 3}. They may also be parameters
+to the paired geom/stat.}
\item{distribution}{Distribution function to use, if x not specified}
@@ -42,10 +59,6 @@ a warning. If \code{TRUE} silently removes missing values.}
rather than combining with them. This is most useful for helper functions
that define both data and aesthetics and shouldn't inherit behaviour from
the default plot specification, e.g. \code{\link{borders}}.}
-
-\item{...}{other arguments passed on to \code{\link{layer}}. This can
-include aesthetics whose values you want to set, not map. See
-\code{\link{layer}} for more details.}
}
\description{
Calculation for quantile-quantile plot.
diff --git a/man/stat_summary.Rd b/man/stat_summary.Rd
index 731f907..2b2b973 100644
--- a/man/stat_summary.Rd
+++ b/man/stat_summary.Rd
@@ -6,28 +6,46 @@
\title{Summarise y values at unique/binned x x.}
\usage{
stat_summary_bin(mapping = NULL, data = NULL, geom = "pointrange",
- fun.data = NULL, fun.y = NULL, fun.ymax = NULL, fun.ymin = NULL,
- fun.args = list(), na.rm = FALSE, position = "identity",
- show.legend = NA, inherit.aes = TRUE, ...)
+ position = "identity", ..., fun.data = NULL, fun.y = NULL,
+ fun.ymax = NULL, fun.ymin = NULL, fun.args = list(), na.rm = FALSE,
+ show.legend = NA, inherit.aes = TRUE)
stat_summary(mapping = NULL, data = NULL, geom = "pointrange",
- fun.data = NULL, fun.y = NULL, fun.ymax = NULL, fun.ymin = NULL,
- fun.args = list(), na.rm = FALSE, position = "identity",
- show.legend = NA, inherit.aes = TRUE, ...)
+ position = "identity", ..., fun.data = NULL, fun.y = NULL,
+ fun.ymax = NULL, fun.ymin = NULL, fun.args = list(), na.rm = FALSE,
+ show.legend = NA, inherit.aes = TRUE)
}
\arguments{
\item{mapping}{Set of aesthetic mappings created by \code{\link{aes}} or
\code{\link{aes_}}. If specified and \code{inherit.aes = TRUE} (the
-default), is combined with the default mapping at the top level of the
-plot. You only need to supply \code{mapping} if there isn't a mapping
-defined for the plot.}
+default), it is combined with the default mapping at the top level of the
+plot. You must supply \code{mapping} if there is no plot mapping.}
-\item{data}{A data frame. If specified, overrides the default data frame
-defined at the top level of the plot.}
+\item{data}{The data to be displayed in this layer. There are three
+ options:
+
+ If \code{NULL}, the default, the data is inherited from the plot
+ data as specified in the call to \code{\link{ggplot}}.
+
+ A \code{data.frame}, or other object, will override the plot
+ data. All objects will be fortified to produce a data frame. See
+ \code{\link{fortify}} for which variables will be created.
+
+ A \code{function} will be called with a single argument,
+ the plot data. The return value must be a \code{data.frame.}, and
+ will be used as the layer data.}
\item{geom}{Use to override the default connection between
\code{geom_histogram}/\code{geom_freqpoly} and \code{stat_bin}.}
+\item{position}{Position adjustment, either as a string, or the result of
+a call to a position adjustment function.}
+
+\item{...}{other arguments passed on to \code{\link{layer}}. These are
+often aesthetics, used to set an aesthetic to a fixed value, like
+\code{color = "red"} or \code{size = 3}. They may also be parameters
+to the paired geom/stat.}
+
\item{fun.data}{A function that is given the complete data and should
return a data frame with variables \code{ymin}, \code{y}, and \code{ymax}.}
@@ -40,9 +58,6 @@ single number.}
\item{na.rm}{If \code{FALSE} (the default), removes missing values with
a warning. If \code{TRUE} silently removes missing values.}
-\item{position}{Position adjustment, either as a string, or the result of
-a call to a position adjustment function.}
-
\item{show.legend}{logical. Should this layer be included in the legends?
\code{NA}, the default, includes if any aesthetics are mapped.
\code{FALSE} never includes, and \code{TRUE} always includes.}
@@ -51,22 +66,11 @@ a call to a position adjustment function.}
rather than combining with them. This is most useful for helper functions
that define both data and aesthetics and shouldn't inherit behaviour from
the default plot specification, e.g. \code{\link{borders}}.}
-
-\item{...}{other arguments passed on to \code{\link{layer}}. There are
- three types of arguments you can use here:
-
- \itemize{
- \item Aesthetics: to set an aesthetic to a fixed value, like
- \code{color = "red"} or \code{size = 3}.
- \item Other arguments to the layer, for example you override the
- default \code{stat} associated with the layer.
- \item Other arguments passed on to the stat.
- }}
}
\description{
\code{stat_summary} operates on unique \code{x}; \code{stat_summary_bin}
operators on binned \code{x}. They are more flexible versions of
-\code{\link{stat_bin}}: instead of just counting, the can compute any
+\code{\link{stat_bin}}: instead of just counting, they can compute any
aggregate.
}
\section{Aesthetics}{
@@ -103,26 +107,18 @@ d + stat_summary(fun.data = "mean_cl_boot", colour = "red", size = 2)
# You can supply individual functions to summarise the value at
# each x:
-d + stat_summary(fun.y = "median", colour = "red", size = 2)
-d + stat_summary(fun.y = "mean", colour = "red", size = 2)
+d + stat_summary(fun.y = "median", colour = "red", size = 2, geom = "point")
+d + stat_summary(fun.y = "mean", colour = "red", size = 2, geom = "point")
d + aes(colour = factor(vs)) + stat_summary(fun.y = mean, geom="line")
d + stat_summary(fun.y = mean, fun.ymin = min, fun.ymax = max,
colour = "red")
-#' d <- ggplot(diamonds, aes(carat, price))
-d + geom_smooth()
-d + geom_line(stat = "summary_bin", binwidth = 0.1, fun.y = "mean")
-
d <- ggplot(diamonds, aes(cut))
d + geom_bar()
d + stat_summary_bin(aes(y = price), fun.y = "mean", geom = "bar")
-\donttest{
-# A set of useful summary functions is provided from the Hmisc package:
-stat_sum_df <- function(fun, geom="crossbar", ...) {
- stat_summary(fun.data=fun, colour="red", geom=geom, width=0.2, ...)
-}
+\donttest{
# Don't use ylim to zoom into a summary plot - this throws the
# data away
p <- ggplot(mtcars, aes(cyl, mpg)) +
@@ -132,28 +128,18 @@ p + ylim(15, 30)
# Instead use coord_cartesian
p + coord_cartesian(ylim = c(15, 30))
+# A set of useful summary functions is provided from the Hmisc package:
+stat_sum_df <- function(fun, geom="crossbar", ...) {
+ stat_summary(fun.data=fun, colour="red", geom=geom, width=0.2, ...)
+}
+d <- ggplot(mtcars, aes(cyl, mpg)) + geom_point()
# The crossbar geom needs grouping to be specified when used with
# a continuous x axis.
d + stat_sum_df("mean_cl_boot", mapping = aes(group = cyl))
d + stat_sum_df("mean_sdl", mapping = aes(group = cyl))
-d + stat_sum_df("mean_sdl", mult = 1, mapping = aes(group = cyl))
+d + stat_sum_df("mean_sdl", fun.args = list(mult = 1), mapping = aes(group = cyl))
d + stat_sum_df("median_hilow", mapping = aes(group = cyl))
-# There are lots of different geoms you can use to display the summaries
-
-d + stat_sum_df("mean_cl_normal", mapping = aes(group = cyl))
-d + stat_sum_df("mean_cl_normal", geom = "errorbar")
-d + stat_sum_df("mean_cl_normal", geom = "pointrange")
-d + stat_sum_df("mean_cl_normal", geom = "smooth")
-
-# Summaries are more useful with a bigger data set:
-mpg2 <- subset(mpg, cyl != 5L)
-m <- ggplot(mpg2, aes(x=cyl, y=hwy)) +
- geom_point() +
- stat_summary(fun.data = "mean_sdl", geom = "linerange",
- colour = "red", size = 2, mult = 1) +
- xlab("cyl")
-m
# An example with highly skewed distributions:
if (require("ggplot2movies")) {
set.seed(596)
diff --git a/man/stat_summary_2d.Rd b/man/stat_summary_2d.Rd
index c7c0877..6674b31 100644
--- a/man/stat_summary_2d.Rd
+++ b/man/stat_summary_2d.Rd
@@ -7,27 +7,44 @@
\title{Bin and summarise in 2d (rectangle & hexagons)}
\usage{
stat_summary_2d(mapping = NULL, data = NULL, geom = "tile",
- position = "identity", bins = 30, binwidth = NULL, drop = TRUE,
+ position = "identity", ..., bins = 30, binwidth = NULL, drop = TRUE,
fun = "mean", fun.args = list(), na.rm = FALSE, show.legend = NA,
- inherit.aes = TRUE, ...)
+ inherit.aes = TRUE)
stat_summary_hex(mapping = NULL, data = NULL, geom = "hex",
- position = "identity", bins = 30, binwidth = NULL, drop = TRUE,
+ position = "identity", ..., bins = 30, binwidth = NULL, drop = TRUE,
fun = "mean", fun.args = list(), na.rm = FALSE, show.legend = NA,
- inherit.aes = TRUE, ...)
+ inherit.aes = TRUE)
}
\arguments{
-\item{mapping}{The aesthetic mapping, usually constructed with
-\code{\link{aes}} or \code{\link{aes_string}}. Only needs to be set
-at the layer level if you are overriding the plot defaults.}
+\item{mapping}{Set of aesthetic mappings created by \code{\link{aes}} or
+\code{\link{aes_}}. If specified and \code{inherit.aes = TRUE} (the
+default), it is combined with the default mapping at the top level of the
+plot. You must supply \code{mapping} if there is no plot mapping.}
-\item{data}{A layer specific dataset - only needed if you want to override
-the plot defaults.}
+\item{data}{The data to be displayed in this layer. There are three
+ options:
+
+ If \code{NULL}, the default, the data is inherited from the plot
+ data as specified in the call to \code{\link{ggplot}}.
+
+ A \code{data.frame}, or other object, will override the plot
+ data. All objects will be fortified to produce a data frame. See
+ \code{\link{fortify}} for which variables will be created.
+
+ A \code{function} will be called with a single argument,
+ the plot data. The return value must be a \code{data.frame.}, and
+ will be used as the layer data.}
\item{geom}{The geometric object to use display the data}
-\item{position}{The position adjustment to use for overlapping points
-on this layer}
+\item{position}{Position adjustment, either as a string, or the result of
+a call to a position adjustment function.}
+
+\item{...}{other arguments passed on to \code{\link{layer}}. These are
+often aesthetics, used to set an aesthetic to a fixed value, like
+\code{color = "red"} or \code{size = 3}. They may also be parameters
+to the paired geom/stat.}
\item{bins}{numeric vector giving number of bins in both vertical and
horizontal directions. Set to 30 by default.}
@@ -52,10 +69,6 @@ a warning. If \code{TRUE} silently removes missing values.}
rather than combining with them. This is most useful for helper functions
that define both data and aesthetics and shouldn't inherit behaviour from
the default plot specification, e.g. \code{\link{borders}}.}
-
-\item{...}{other arguments passed on to \code{\link{layer}}. This can
-include aesthetics whose values you want to set, not map. See
-\code{\link{layer}} for more details.}
}
\description{
\code{stat_summary_2d} is a 2d variation of \code{\link{stat_summary}}.
@@ -72,6 +85,14 @@ are summarised with \code{fun}.
\item \code{z}: value passed to the summary function
}
}
+
+\section{Computed variables}{
+
+\describe{
+ \item{x,y}{Location}
+ \item{value}{Value of summary statistic.}
+}
+}
\examples{
d <- ggplot(diamonds, aes(carat, depth, z = price))
d + stat_summary_2d()
diff --git a/man/stat_unique.Rd b/man/stat_unique.Rd
index 223594c..886614e 100644
--- a/man/stat_unique.Rd
+++ b/man/stat_unique.Rd
@@ -5,21 +5,38 @@
\title{Remove duplicates.}
\usage{
stat_unique(mapping = NULL, data = NULL, geom = "point",
- position = "identity", na.rm = FALSE, show.legend = NA,
- inherit.aes = TRUE, ...)
+ position = "identity", ..., na.rm = FALSE, show.legend = NA,
+ inherit.aes = TRUE)
}
\arguments{
-\item{mapping}{The aesthetic mapping, usually constructed with
-\code{\link{aes}} or \code{\link{aes_string}}. Only needs to be set
-at the layer level if you are overriding the plot defaults.}
+\item{mapping}{Set of aesthetic mappings created by \code{\link{aes}} or
+\code{\link{aes_}}. If specified and \code{inherit.aes = TRUE} (the
+default), it is combined with the default mapping at the top level of the
+plot. You must supply \code{mapping} if there is no plot mapping.}
-\item{data}{A layer specific dataset - only needed if you want to override
-the plot defaults.}
+\item{data}{The data to be displayed in this layer. There are three
+ options:
+
+ If \code{NULL}, the default, the data is inherited from the plot
+ data as specified in the call to \code{\link{ggplot}}.
+
+ A \code{data.frame}, or other object, will override the plot
+ data. All objects will be fortified to produce a data frame. See
+ \code{\link{fortify}} for which variables will be created.
+
+ A \code{function} will be called with a single argument,
+ the plot data. The return value must be a \code{data.frame.}, and
+ will be used as the layer data.}
\item{geom}{The geometric object to use display the data}
-\item{position}{The position adjustment to use for overlapping points
-on this layer}
+\item{position}{Position adjustment, either as a string, or the result of
+a call to a position adjustment function.}
+
+\item{...}{other arguments passed on to \code{\link{layer}}. These are
+often aesthetics, used to set an aesthetic to a fixed value, like
+\code{color = "red"} or \code{size = 3}. They may also be parameters
+to the paired geom/stat.}
\item{na.rm}{If \code{FALSE} (the default), removes missing values with
a warning. If \code{TRUE} silently removes missing values.}
@@ -32,10 +49,6 @@ a warning. If \code{TRUE} silently removes missing values.}
rather than combining with them. This is most useful for helper functions
that define both data and aesthetics and shouldn't inherit behaviour from
the default plot specification, e.g. \code{\link{borders}}.}
-
-\item{...}{other arguments passed on to \code{\link{layer}}. This can
-include aesthetics whose values you want to set, not map. See
-\code{\link{layer}} for more details.}
}
\description{
Remove duplicates.
diff --git a/man/theme.Rd b/man/theme.Rd
index bf024c5..b26b8e0 100644
--- a/man/theme.Rd
+++ b/man/theme.Rd
@@ -278,35 +278,6 @@ mytheme <- theme_grey() + theme(plot.title = element_text(colour = "red"))
p + mytheme
}
-
-\dontrun{
-## Run this to generate a graph of the element inheritance tree
-build_element_graph <- function(tree) {
- require(igraph)
- require(plyr)
-
- inheritdf <- function(name, item) {
- if (length(item$inherit) == 0)
- data.frame()
- else
- data.frame(child = name, parent = item$inherit)
- }
-
- edges <- plyr::rbind.fill(mapply(inheritdf, names(tree), tree))
-
- # Explicitly add vertices (since not all are in edge list)
- vertices <- data.frame(name = names(tree))
- graph.data.frame(edges, vertices = vertices)
-}
-
-g <- build_element_graph(ggplot2:::.element_tree)
-V(g)$label <- V(g)$name
-
-set.seed(324)
-par(mar=c(0,0,0,0)) # Remove unnecessary margins
-plot(g, layout=layout.fruchterman.reingold, vertex.size=4, vertex.label.dist=.25)
-
-}
}
\seealso{
\code{\link{+.gg}}
diff --git a/man/theme_update.Rd b/man/theme_update.Rd
index 6cabafe..ec90647 100644
--- a/man/theme_update.Rd
+++ b/man/theme_update.Rd
@@ -2,12 +2,15 @@
% Please edit documentation in R/theme.r
\name{theme_update}
\alias{theme_get}
+\alias{theme_replace}
\alias{theme_set}
\alias{theme_update}
\title{Get, set and update themes.}
\usage{
theme_update(...)
+theme_replace(...)
+
theme_get()
theme_set(new)
@@ -18,8 +21,13 @@ theme_set(new)
\item{new}{new theme (a list of theme elements)}
}
\description{
-Use \code{theme_update} to modify a small number of elements of the current
-theme or use \code{theme_set} to completely override it.
+Use \code{theme_get} to get the current theme, and \code{theme_set} to
+completely override it. \code{theme_update} and \code{theme_replace} are
+shorthands for changing individual elements in the current theme.
+\code{theme_update} uses the \code{+} operator, so that any unspecified
+values in the theme element will default to the values they are set in the
+theme. \code{theme_replace} will completely replace the element, so any
+unspecified values will overwrite the current value in the theme with \code{NULL}s.
}
\examples{
p <- ggplot(mtcars, aes(mpg, wt)) +
@@ -30,17 +38,30 @@ p
theme_set(old)
p
+#theme_replace NULLs out the fill attribute of panel.background,
+#resulting in a white background:
+theme_get()$panel.background
+old <- theme_replace(panel.background = element_rect(colour = "pink"))
+theme_get()$panel.background
+p
+theme_set(old)
+
+#theme_update only changes the colour attribute, leaving the others intact:
old <- theme_update(panel.background = element_rect(colour = "pink"))
+theme_get()$panel.background
p
theme_set(old)
+
theme_get()
+
ggplot(mtcars, aes(mpg, wt)) +
geom_point(aes(color = mpg)) +
theme(legend.position = c(0.95, 0.95),
legend.justification = c(1, 1))
last_plot() +
theme(legend.background = element_rect(fill = "white", colour = "white", size = 3))
+
}
\seealso{
\code{\link{\%+replace\%}} and \code{\link{+.gg}}
diff --git a/man/translate_qplot_base.Rd b/man/translate_qplot_base.Rd
deleted file mode 100644
index 7a3328d..0000000
--- a/man/translate_qplot_base.Rd
+++ /dev/null
@@ -1,150 +0,0 @@
-% Generated by roxygen2: do not edit by hand
-% Please edit documentation in R/translate-qplot-base.r
-\name{translate_qplot_base}
-\alias{translate_qplot_base}
-\title{Translating between qplot and base graphics}
-\description{
-There are two types of graphics functions in base graphics, those that draw
-complete graphics and those that add to existing graphics.
-}
-\details{
-qplot() has been designed to mimic plot(), and can do the job of all other
-high-level plotting commands. There are only two graph types from base
-graphics that cannot be replicated with ggplot2: filled.contour() and
-persp()
-}
-\examples{
-\donttest{
-
-# High-level plotting commands
-
-x <- runif(10)
-y <- 1:10
-plot(x, y); dotchart(x, y)
-qplot(x, y)
-
-plot(x, y, type = "l")
-qplot(x, y, geom = "line")
-
-plot(x, y, type = "s")
-qplot(x, y, geom = "step")
-
-plot(x, y, type = "b")
-qplot(x, y, geom = c("point", "line"))
-
-boxplot(x, y)
-qplot(x, y, geom = "boxplot")
-
-hist(x)
-qplot(x, geom = "histogram")
-
-# cdplot(factor(x), y)
-# qplot(x, fill = y, geom = "density", position = "fill")
-
-# coplot(y ~ x | a + b)
-# qplot(x, y, facets = a ~ b)
-
-# Many of the geoms are parameterised differently than base graphics. For
-# example, hist() is parameterised in terms of the number of bins, while
-# geom_histogram() is parameterised in terms of the width of each bin.
-hist(x, bins = 10)
-qplot(x, geom = "histogram", binwidth = .1)
-
-# qplot() often requires data in a slightly different format to the base
-# graphics functions. For example, the bar geom works with untabulated data,
-# not tabulated data like barplot(); the tile and contour geoms expect data
-# in a data frame, not a matrix like image() and contour().
-barplot(table(x))
-qplot(x, geom = "bar")
-
-barplot(x)
-qplot(seq_along(x), x, geom = "bar", stat = "identity")
-
-# image(x)
-# qplot(X1, X2, data = melt(x), geom = "tile", fill = value)
-
-# contour(x)
-# qplot(X1, X2, data = melt(x), geom = "contour", fill = value)
-
-# Generally, the base graphics functions work with individual vectors, not
-# data frames like ggplot2. qplot() will try to construct a data frame if one
-# is not specified, but it is not always possible. If you get strange errors,
-# you may need to create the data frame yourself.
-df <- data.frame(x = x, y = y)
-with(df, plot(x, y))
-qplot(x, y, data = df)
-
-# By default, qplot() maps values to aesthetics with a scale. To override
-# this behaviour and set aesthetics, overriding the defaults, you need to use I().
-plot(x, y, col = "red", cex = 1)
-qplot(x, y, colour = I("red"), size = I(1))
-
-# Low-level drawing
-
-# The low-level drawing functions which add to an existing plot are equivalent
-# to adding a new layer in ggplot2.
-
-# Base function ggplot2 layer
-# curve() geom_curve()
-# hline() geom_hline()
-# lines() geom_line()
-# points() geom_point()
-# polygon() geom_polygon()
-# rect() geom_rect()
-# rug() geom_rug()
-# segments() geom_segment()
-# text() geom_text()
-# vline() geom_vline()
-# abline(lm(y ~ x)) geom_smooth(method = "lm")
-# lines(density(x)) geom_density()
-# lines(loess(x, y)) geom_smooth()
-
-plot(x, y)
-lines(x, y)
-
-qplot(x, y) + geom_line()
-
-# Or, building up piece-meal
-qplot(x, y)
-last_plot() + geom_line()
-
-# Legends, axes and grid lines
-
-# In ggplot2, the appearance of legends and axes is controlled by the scales.
-# Axes are produced by the x and y scales, while all other scales produce legends.
-# See ?theme for help changing the appearance of axes and legends.
-# The appearance of grid lines is controlled by the grid.major and grid.minor
-# theme options, and their position by the breaks of the x and y scales.
-
-# Colour palettes
-
-# Instead of global colour palettes, ggplot2 has scales for individual plots. Much
-# of the time you can rely on the default colour scale (which has somewhat better
-# perceptual properties), but if you want to reuse an existing colour palette, you
-# can use scale_colour_manual(). You will need to make sure that the colour
-# is a factor for this to work.
-
-palette(rainbow(5))
-plot(1:5, 1:5, col = 1:5, pch = 19, cex = 4)
-
-qplot(1:5, 1:5, col = factor(1:5), size = I(4))
-last_plot() + scale_colour_manual(values = rainbow(5))
-
-# In ggplot2, you can also use palettes with continuous values,
-# with intermediate values being linearly interpolated.
-
-qplot(0:100, 0:100, col = 0:100, size = I(4)) +
- scale_colour_gradientn(colours = rainbow(7))
-last_plot() + scale_colour_gradientn(colours = terrain.colors(7))
-
-# Graphical parameters
-
-# The majority of par settings have some analogue within the theme system, or
-# in the defaults of the geoms and scales. The appearance plot border drawn
-# by box() can be controlled in a similar way by the panel.background and
-# plot.background theme elements. Instead of using title(), the plot title is
-# set with the title option. See ?theme for more theme elements.
-last_plot() + labs(title = "My Plot Title")
-}
-}
-
diff --git a/man/translate_qplot_lattice.Rd b/man/translate_qplot_lattice.Rd
index dff1ba0..4ffbeb4 100644
--- a/man/translate_qplot_lattice.Rd
+++ b/man/translate_qplot_lattice.Rd
@@ -4,12 +4,12 @@
\alias{translate_qplot_lattice}
\title{Translating between qplot and lattice}
\description{
-The major difference between lattice and ggplot2 is that lattice uses a formula based
-interface. ggplot2 does not because the formula does not generalise well
-to more complicated situations.
+The major difference between lattice and ggplot2 is that lattice uses a
+formula based interface. ggplot2 does not because the formula does not
+generalise well to more complicated situations.
}
\examples{
-\dontrun{
+\donttest{
library(lattice)
if (require("ggplot2movies")) {
@@ -32,13 +32,10 @@ histogram(~ rating, data = movies)
qplot(rating, data = movies, geom = "histogram")
bwplot(Comedy ~ rating ,data = movies)
-qplot(factor(Comedy), rating, data = movies, type = "boxplot")
+qplot(factor(Comedy), rating, data = movies, geom = "boxplot")
xyplot(wt ~ mpg, mtcars, type = c("p","smooth"))
qplot(mpg, wt, data = mtcars, geom = c("point","smooth"))
-
-xyplot(wt ~ mpg, mtcars, type = c("p","r"))
-qplot(mpg, wt, data = mtcars, geom = c("point","smooth"), method = "lm")
}
# The capabilities for scale manipulations are similar in both ggplot2 and
diff --git a/tests/testthat/Rplots.pdf b/tests/testthat/Rplots.pdf
new file mode 100644
index 0000000..bb4cfc6
Binary files /dev/null and b/tests/testthat/Rplots.pdf differ
diff --git a/tests/testthat/test-aes-setting.r b/tests/testthat/test-aes-setting.r
index 575cccb..fd4e732 100644
--- a/tests/testthat/test-aes-setting.r
+++ b/tests/testthat/test-aes-setting.r
@@ -15,3 +15,22 @@ test_that("Aesthetic parameters must match length of data", {
set_colours(rep("red", 5))
})
+
+test_that("alpha affects only fill colour of solid geoms", {
+ df <- data.frame(x = 1:2, y = 1)
+
+ poly <- ggplot(df, aes(x = x, y)) +
+ geom_polygon(fill = "red", colour = "red", alpha = 0.5)
+ rect <- ggplot(df, aes(xmin = x, xmax = x + 1, ymin = 1, ymax = y + 1)) +
+ geom_rect(fill = "red", colour = "red", alpha = 0.5)
+ ribb <- ggplot(df, aes(x = x, ymin = 1, ymax = y + 1)) +
+ geom_ribbon(fill = "red", colour = "red", alpha = 0.5)
+
+ expect_equal(layer_grob(poly)[[1]]$gp$col[[1]], "red")
+ expect_equal(layer_grob(rect)[[1]]$gp$col[[1]], "red")
+ expect_equal(layer_grob(ribb)[[1]]$children[[1]]$gp$col[[1]], "red")
+
+ expect_equal(layer_grob(poly)[[1]]$gp$fill[[1]], "#FF000080")
+ expect_equal(layer_grob(rect)[[1]]$gp$fill[[1]], "#FF000080")
+ expect_equal(layer_grob(ribb)[[1]]$children[[1]]$gp$fill[[1]], "#FF000080")
+})
diff --git a/tests/testthat/test-boxplot.r b/tests/testthat/test-boxplot.r
index f220b71..8f25116 100644
--- a/tests/testthat/test-boxplot.r
+++ b/tests/testthat/test-boxplot.r
@@ -13,28 +13,19 @@ test_that("geom_boxplot range includes all outliers", {
})
test_that("geom_boxplot for continuous x gives warning if more than one x (#992)", {
- dat <- expand.grid(x=1:2, y=c(-(1:20)^3, (1:20)^3) )
- expect_that(ggplot_build(ggplot(dat, aes(x,y)) + geom_boxplot()),
- gives_warning("Continuous x aesthetic"))
+ dat <- expand.grid(x = 1:2, y = c(-(1:5) ^ 3, (1:5) ^ 3) )
- expect_that(ggplot_build(ggplot(dat, aes(x=as.Date(x,origin=Sys.Date()),y)) + geom_boxplot()),
- gives_warning("Continuous x aesthetic"))
+ bplot <- function(aes = NULL, extra = list()) {
+ ggplot_build(ggplot(dat, aes) + geom_boxplot(aes) + extra)
+ }
- expect_that(ggplot_build(ggplot(dat, aes(x,y,group=x)) + geom_boxplot()),
- not(gives_warning("Continuous x aesthetic")))
+ expect_warning(bplot(aes(x, y)), "Continuous x aesthetic")
+ expect_warning(bplot(aes(x, y), facet_wrap(~x)), "Continuous x aesthetic")
+ expect_warning(bplot(aes(Sys.Date() + x, y)), "Continuous x aesthetic")
- expect_that(ggplot_build(ggplot(dat, aes(x=1,y)) + geom_boxplot()),
- not(gives_warning("Continuous x aesthetic")))
-
- expect_that(ggplot_build(ggplot(dat, aes(x=factor(x),y)) + geom_boxplot()),
- not(gives_warning("Continuous x aesthetic")))
-
- expect_that(ggplot_build(ggplot(dat, aes(x=(x == 1),y)) + geom_boxplot()),
- not(gives_warning("Continuous x aesthetic")))
-
- expect_that(ggplot_build(ggplot(dat, aes(x=as.character(x),y)) + geom_boxplot()),
- not(gives_warning("Continuous x aesthetic")))
-
- expect_that(ggplot_build(ggplot(dat, aes(x,y)) + geom_boxplot() + facet_wrap(~y)),
- gives_warning("Continuous x aesthetic"))
+ expect_warning(bplot(aes(x, group = x, y)), NA)
+ expect_warning(bplot(aes(1, y)), NA)
+ expect_warning(bplot(aes(factor(x), y)), NA)
+ expect_warning(bplot(aes(x == 1, y)), NA)
+ expect_warning(bplot(aes(as.character(x), y)), NA)
})
diff --git a/tests/testthat/test-empty-data.r b/tests/testthat/test-empty-data.r
index 666b056..4555442 100644
--- a/tests/testthat/test-empty-data.r
+++ b/tests/testthat/test-empty-data.r
@@ -95,3 +95,11 @@ test_that("empty layers still generate one grob per panel", {
expect_equal(length(layer_grob(d)), 3)
})
+
+test_that("missing layers generate one grob per panel", {
+ df <- data.frame(x = 1:4, y = 1:2, g = 1:2)
+ base <- ggplot(df, aes(x, y)) + geom_point(shape = NA, na.rm = TRUE)
+
+ expect_equal(length(layer_grob(base)), 1)
+ expect_equal(length(layer_grob(base + facet_wrap(~ g))), 2)
+})
diff --git a/tests/testthat/test-facet-strips.r b/tests/testthat/test-facet-strips.r
new file mode 100644
index 0000000..c3f4e7e
--- /dev/null
+++ b/tests/testthat/test-facet-strips.r
@@ -0,0 +1,112 @@
+context("Facet Strips")
+
+strip_layout <- function(p) {
+ data <- ggplot_build(p)
+ plot <- data$plot
+ panel <- data$panel
+ data <- data$data
+ theme <- plot_theme(plot)
+
+ geom_grobs <- Map(function(l, d) l$draw_geom(d, panel, plot$coordinates),
+ plot$layers, data)
+
+ facet <- facet_render(plot$facet, panel, plot$coordinates, theme, geom_grobs)
+ layout <- facet$layout
+ strip_layout <- layout[grepl("^strip", layout$name), 1:4]
+ as.list(strip_layout)
+}
+
+p <- ggplot(mtcars, aes(disp, drat)) + geom_point()
+
+
+test_that("facet_wrap() builds correct output", {
+ wrap <- p + facet_wrap(~cyl)
+
+ wrap_expected <- list(
+ t = c(1, 1, 1),
+ l = c(2, 5, 8),
+ b = c(1, 1, 1),
+ r = c(2, 5, 8)
+ )
+
+ expect_equal(strip_layout(wrap), wrap_expected)
+})
+
+test_that("facet_wrap() switches to 'x'", {
+ wrap_x <- p + facet_wrap(~cyl, switch = "x")
+
+ wrap_x_expected <- list(
+ t = c(3, 3, 3),
+ l = c(2, 5, 8),
+ b = c(3, 3, 3),
+ r = c(2, 5, 8)
+ )
+
+ expect_equal(strip_layout(wrap_x), wrap_x_expected)
+})
+
+test_that("facet_wrap() switches to 'y'", {
+ wrap_y <- p + facet_wrap(~cyl, switch = "y")
+
+ wrap_y_expected <- list(
+ t = c(1, 1, 1),
+ l = c(1, 5, 9),
+ b = c(1, 1, 1),
+ r = c(1, 5, 9)
+ )
+
+ expect_equal(strip_layout(wrap_y), wrap_y_expected)
+})
+
+
+test_that("facet_grid() builds correct output", {
+ grid <- p + facet_grid(~cyl)
+
+ grid_expected <- list(
+ t = c(1, 1, 1),
+ l = c(2, 4, 6),
+ b = c(1, 1, 1),
+ r = c(2, 4, 6)
+ )
+
+ expect_equal(strip_layout(grid), grid_expected)
+})
+
+test_that("facet_grid() switches to 'x'", {
+ grid_x <- p + facet_grid(am ~ cyl, switch = "x")
+
+ grid_x_expected <- list(
+ t = c(1, 3, 5),
+ l = c(7, 7, 2),
+ b = c(1, 3, 6),
+ r = c(7, 7, 6)
+ )
+
+ expect_equal(strip_layout(grid_x), grid_x_expected)
+})
+
+test_that("facet_grid() switches to 'y'", {
+ grid_y <- p + facet_grid(am ~ cyl, switch = "y")
+
+ grid_y_expected <- list(
+ t = c(1, 1, 1, 2),
+ l = c(4, 6, 8, 1),
+ b = c(1, 1, 1, 4),
+ r = c(4, 6, 8, 2)
+ )
+
+ expect_equal(strip_layout(grid_y), grid_y_expected)
+})
+
+test_that("facet_grid() switches to both 'x' and 'y'", {
+ grid_xy <- p + facet_grid(am ~ cyl, switch = "both")
+
+ grid_xy_expected <- list(
+ t = c(1, 5),
+ l = c(1, 4),
+ b = c(3, 6),
+ r = c(2, 8)
+ )
+
+ expect_equal(strip_layout(grid_xy), grid_xy_expected)
+})
diff --git a/tests/testthat/test-geom-boxplot.R b/tests/testthat/test-geom-boxplot.R
new file mode 100644
index 0000000..b4a4a58
--- /dev/null
+++ b/tests/testthat/test-geom-boxplot.R
@@ -0,0 +1,9 @@
+context("geom_boxplot")
+
+test_that("can use US spelling of colour", {
+ df <- data.frame(x = 1, y = c(1:5, 100))
+ plot <- ggplot(df, aes(x, y)) + geom_boxplot(outlier.color = "red")
+
+ gpar <- layer_grob(plot)[[1]]$children[[1]]$children[[1]]$gp
+ expect_equal(gpar$col, "#FF0000FF")
+})
diff --git a/tests/testthat/test-geom-freqpoly.R b/tests/testthat/test-geom-freqpoly.R
new file mode 100644
index 0000000..7793fcb
--- /dev/null
+++ b/tests/testthat/test-geom-freqpoly.R
@@ -0,0 +1,12 @@
+context("freqpoly")
+
+test_that("can do frequency polygon with categorical x", {
+ df <- data.frame(x = rep(letters[1:3], 3:1))
+
+ p <- ggplot(df, aes(x)) + geom_freqpoly(stat = "count")
+ d <- layer_data(p)
+
+ expect_is(d$x, "integer")
+ expect_equal(d$x, 1:3)
+ expect_equal(d$y, 3:1)
+})
diff --git a/tests/testthat/test-geom-ribbon.R b/tests/testthat/test-geom-ribbon.R
new file mode 100644
index 0000000..13dade7
--- /dev/null
+++ b/tests/testthat/test-geom-ribbon.R
@@ -0,0 +1,10 @@
+context("geom_ribbon")
+
+test_that("NAs are not dropped from the data", {
+ df <- data.frame(x = 1:5, y = c(1, 1, NA, 1, 1))
+
+ p <- ggplot(df, aes(x))+
+ geom_ribbon(aes(ymin = y - 1, ymax = y + 1))
+
+ expect_equal(layer_data(p)$ymin, c(0, 0, NA, 0, 0))
+})
diff --git a/tests/testthat/test-geom-tile.R b/tests/testthat/test-geom-tile.R
new file mode 100644
index 0000000..d40754e
--- /dev/null
+++ b/tests/testthat/test-geom-tile.R
@@ -0,0 +1,13 @@
+context("geom_tile")
+
+test_that("accepts width and height params", {
+ df <- data.frame(x = c("a", "b"), y = c("a", "b"))
+
+ out1 <- layer_data(ggplot(df, aes(x, y)) + geom_tile())
+ expect_equal(out1$xmin, c(0.5, 1.5))
+ expect_equal(out1$xmax, c(1.5, 2.5))
+
+ out2 <- layer_data(ggplot(df, aes(x, y)) + geom_tile(width = 0.5, height = 0.5))
+ expect_equal(out2$xmin, c(0.75, 1.75))
+ expect_equal(out2$xmax, c(1.25, 2.25))
+})
diff --git a/tests/testthat/test-grid-utils.R b/tests/testthat/test-grid-utils.R
new file mode 100644
index 0000000..2b8944b
--- /dev/null
+++ b/tests/testthat/test-grid-utils.R
@@ -0,0 +1,8 @@
+context("Grid utilites")
+
+test_that("width_cm and height_cm work with unit arithmetic", {
+ x <- 2 * unit(1, "cm")
+
+ expect_equal(width_cm(x), 2)
+ expect_equal(height_cm(x), 2)
+})
diff --git a/tests/testthat/test-layer.r b/tests/testthat/test-layer.r
index 80887ce..7e4e9f5 100644
--- a/tests/testthat/test-layer.r
+++ b/tests/testthat/test-layer.r
@@ -32,3 +32,16 @@ test_that("strip_dots remove dots around calculated aesthetics", {
expect_equal(strip_dots(aes(sapply(..density.., function(x) mean(x)))$x),
quote(sapply(density, function(x) mean(x))))
})
+
+# Data extraction ---------------------------------------------------------
+
+test_that("layer_data returns a data.frame", {
+ l <- geom_point()
+ expect_equal(l$layer_data(mtcars), mtcars)
+ l <- geom_point(data = head(mtcars))
+ expect_equal(l$layer_data(mtcars), head(mtcars))
+ l <- geom_point(data = head)
+ expect_equal(l$layer_data(mtcars), head(mtcars))
+ l <- geom_point(data = nrow)
+ expect_error(l$layer_data(mtcars), "Data function must return a data.frame")
+})
diff --git a/tests/testthat/test-scale-discrete.R b/tests/testthat/test-scale-discrete.R
new file mode 100644
index 0000000..3485576
--- /dev/null
+++ b/tests/testthat/test-scale-discrete.R
@@ -0,0 +1,18 @@
+context("scale_discrete")
+
+# Ranges ------------------------------------------------------------------
+
+test_that("discrete ranges also encompas continuous values", {
+ df <- data.frame(x1 = c("a", "b", "c"), x2 = c(0, 2, 4), y = 1:3)
+
+ base <- ggplot(df, aes(y = y)) + scale_x_discrete()
+
+ x_range <- function(x) {
+ layer_scales(x)$x$dimension()
+ }
+
+ expect_equal(x_range(base + geom_point(aes(x1))), c(1, 3))
+ expect_equal(x_range(base + geom_point(aes(x2))), c(0, 4))
+ expect_equal(x_range(base + geom_point(aes(x1)) + geom_point(aes(x2))), c(0, 4))
+})
+
diff --git a/tests/testthat/test-stat-bin.R b/tests/testthat/test-stat-bin.R
index 7990101..395d369 100644
--- a/tests/testthat/test-stat-bin.R
+++ b/tests/testthat/test-stat-bin.R
@@ -10,6 +10,90 @@ test_that("stat_bin throws error when y aesthetic present", {
"Unknown parameters: y")
})
+test_that("bins specifies the number of bins", {
+ df <- data.frame(x = 1:10)
+ out <- function(x, ...) {
+ layer_data(ggplot(df, aes(x)) + geom_histogram(...))
+ }
+
+ expect_equal(nrow(out(bins = 2)), 2)
+ expect_equal(nrow(out(bins = 100)), 100)
+})
+
+test_that("geom_histogram defaults to pad = FALSE", {
+ df <- data.frame(x = 1:3)
+ out <- layer_data(ggplot(df, aes(x)) + geom_histogram(binwidth = 1))
+
+ expect_equal(out$count, c(1, 1, 1))
+})
+
+test_that("geom_freqpoly defaults to pad = TRUE", {
+ df <- data.frame(x = 1:3)
+ out <- layer_data(ggplot(df, aes(x)) + geom_freqpoly(binwidth = 1))
+
+ expect_equal(out$count, c(0, 1, 1, 1, 0))
+})
+
+
+# Underlying binning algorithm --------------------------------------------
+
+comp_bin <- function(df, ...) {
+ plot <- ggplot(df, aes(x = x)) + stat_bin(...)
+ layer_data(plot)
+}
+
+test_that("Closed left or right", {
+ dat <- data.frame(x = c(0, 10))
+
+ res <- comp_bin(dat, binwidth = 10, pad = FALSE)
+ expect_identical(res$count, c(1, 1))
+ res <- comp_bin(dat, binwidth = 10, boundary = 5, pad = FALSE)
+ expect_identical(res$count, c(1, 1))
+ res <- comp_bin(dat, binwidth = 10, boundary = 0, pad = FALSE)
+ expect_identical(res$count, 2)
+ res <- comp_bin(dat, binwidth = 5, boundary = 0, pad = FALSE)
+ expect_identical(res$count, c(1, 1))
+
+ res <- comp_bin(dat, binwidth = 10, pad = FALSE, closed = "left")
+ expect_identical(res$count, c(1, 1))
+ res <- comp_bin(dat, binwidth = 10, boundary = 5, pad = FALSE, closed = "left")
+ expect_identical(res$count, c(1, 1))
+ res <- comp_bin(dat, binwidth = 10, boundary = 0, pad = FALSE, closed = "left")
+ expect_identical(res$count, c(2))
+ res <- comp_bin(dat, binwidth = 5, boundary = 0, pad = FALSE, closed = "left")
+ expect_identical(res$count, c(1, 1))
+})
+
+
+test_that("Setting boundary and center", {
+ # numeric
+ df <- data.frame(x = c(0, 30))
+
+ # Error if both boundary and center are specified
+ expect_error(comp_bin(df, boundary = 5, center = 0), "one of `boundary` and `center`")
+
+ res <- comp_bin(df, binwidth = 10, boundary = 0, pad = FALSE)
+ expect_identical(res$count, c(1, 0, 1))
+ expect_identical(res$xmin[1], 0)
+ expect_identical(res$xmax[3], 30)
+
+ res <- comp_bin(df, binwidth = 10, center = 0, pad = FALSE)
+ expect_identical(res$count, c(1, 0, 0, 1))
+ expect_identical(res$xmin[1], df$x[1] - 5)
+ expect_identical(res$xmax[4], df$x[2] + 5)
+})
+
+test_that("weights are added", {
+ df <- data.frame(x = 1:10, y = 1:10)
+ p <- ggplot(df, aes(x = x, weight = y)) + geom_histogram(binwidth = 1)
+ out <- layer_data(p)
+
+ expect_equal(out$count, df$y)
+})
+
+
+# stat_count --------------------------------------------------------------
+
test_that("stat_count throws error when y aesthetic present", {
dat <- data.frame(x = c("a", "b", "c"), y = c(1, 5, 10))
diff --git a/tests/testthat/test-stat-bin2d.R b/tests/testthat/test-stat-bin2d.R
index 7c80974..c1a1453 100644
--- a/tests/testthat/test-stat-bin2d.R
+++ b/tests/testthat/test-stat-bin2d.R
@@ -8,8 +8,8 @@ test_that("binwidth is respected", {
out <- layer_data(base)
expect_equal(nrow(out), 2)
# Adjust tolerance to account for fuzzy breaks adjustment
- expect_equal(out$xmin, c(1, 1.75), tol = 1e-7)
- expect_equal(out$xmax, c(1.25, 2), tol = 1e-7)
+ expect_equal(out$xmin, c(1, 1.75), tolerance = 1e-7)
+ expect_equal(out$xmax, c(1.25, 2), tolerance = 1e-7)
})
test_that("breaks override binwidth", {
diff --git a/tests/testthat/test-stats-function.r b/tests/testthat/test-stats-function.r
index 47cb02a..a97f94f 100644
--- a/tests/testthat/test-stats-function.r
+++ b/tests/testthat/test-stats-function.r
@@ -23,3 +23,14 @@ test_that("uses scale limits, not data limits", {
expect_false(any(is.na(ret$y)))
expect_false(any(is.na(ret_log$y)))
})
+
+test_that("works with discrete x", {
+ dat <- data.frame(x = c("a", "b"))
+
+ base <- ggplot(dat, aes(x, group = 1)) +
+ stat_function(fun = as.numeric, geom = "point", n = 2)
+ ret <- layer_data(base)
+
+ expect_equal(ret$x, 1:2)
+ expect_equal(ret$y, 1:2)
+})
diff --git a/vignettes/extending-ggplot2.Rmd b/vignettes/extending-ggplot2.Rmd
index 5040814..921c095 100644
--- a/vignettes/extending-ggplot2.Rmd
+++ b/vignettes/extending-ggplot2.Rmd
@@ -14,15 +14,15 @@ knitr::opts_chunk$set(collapse = TRUE, comment = "#>")
library(ggplot2)
```
-This vignette documents the official extension mechanism provided in ggplot2 1.1.0. This vignette is a high-level adjunct to the low-level details found in `?Stat`, `?Geom` and `?theme`. You'll learn how to extend ggplot2 by creating a new stat, geom, or theme.
+This vignette documents the official extension mechanism provided in ggplot2 2.0.0. This vignette is a high-level adjunct to the low-level details found in `?Stat`, `?Geom` and `?theme`. You'll learn how to extend ggplot2 by creating a new stat, geom, or theme.
-As you read this document, you'll see many things that will make you scratch your head and wonder why on earth is it designed this way? Mostly it's historical accident - I wasn't a terribly good R programmer when I started writing ggplot2 and I made a lot of questionable decisions. We cleaned up as many of those issues as possible in the 1.1.0 release, but some fixes simply weren't worth the effort.
+As you read this document, you'll see many things that will make you scratch your head and wonder why on earth is it designed this way? Mostly it's historical accident - I wasn't a terribly good R programmer when I started writing ggplot2 and I made a lot of questionable decisions. We cleaned up as many of those issues as possible in the 2.0.0 release, but some fixes simply weren't worth the effort.
## ggproto
All ggplot2 objects are built using the ggproto system of object oriented programming. This OO system is used only in one place: ggplot2. This is mostly historical accident: ggplot2 started off using [proto]( https://cran.r-project.org/package=proto) because I needed mutable objects. This was well before the creation of (the briefly lived) [mutatr](http://vita.had.co.nz/papers/mutatr.html), reference classes and R6: proto was the only game in town.
-But why ggproto? Well when we turned to add an official extension mechanism to ggplot2, we found a major problem that caused problems when proto objects were extended in a different package (methods were evaluated in ggplot2, not the package where the extension was added). We tried converting to R6, but it was a poor fit for the needs of ggplot2. We could've modified proto, but that would've first involved understand exactly how proto worked, and secondly making sure that the changes did [...]
+But why ggproto? Well when we turned to add an official extension mechanism to ggplot2, we found a major problem that caused problems when proto objects were extended in a different package (methods were evaluated in ggplot2, not the package where the extension was added). We tried converting to R6, but it was a poor fit for the needs of ggplot2. We could've modified proto, but that would've first involved understanding exactly how proto worked, and secondly making sure that the changes [...]
It's strange to say, but this is a case where inventing a new OO system was actually the right answer to the problem! Fortunately Winston is now very good at creating OO systems, so it only took him a day to come up with ggproto: it maintains all the features of proto that ggplot2 needs, while allowing cross package inheritance to work.
@@ -51,7 +51,7 @@ To create a new geom or stat, you will just create a new ggproto that inherits f
### The simplest stat
-We'll start by creating a very simple stat: one that gives the complex hull (the _c_ hull) of a set of points. First we create a new ggproto object that inherits from `Stat`:
+We'll start by creating a very simple stat: one that gives the convex hull (the _c_ hull) of a set of points. First we create a new ggproto object that inherits from `Stat`:
```{r chull}
StatChull <- ggproto("StatChull", Stat,
@@ -177,7 +177,7 @@ ggplot(mpg, aes(displ, hwy)) +
stat_lm(formula = y ~ poly(x, 10), geom = "point", colour = "red", n = 20)
```
-Note that don't _have_ to explicitly include the new parameters in the arguments for the layer, `...` will get passed to the right place anyway. But you'll need to document them somewhere so the user knows about them. Here's a brief example. Note `@inheritParams ggplot2::stat_identity`: that will automatically inherit documentation for all the parameters also defined for `stat_identity()`.
+Note that we don't _have_ to explicitly include the new parameters in the arguments for the layer, `...` will get passed to the right place anyway. But you'll need to document them somewhere so the user knows about them. Here's a brief example. Note `@inheritParams ggplot2::stat_identity`: that will automatically inherit documentation for all the parameters also defined for `stat_identity()`.
```{r}
#' @inheritParams ggplot2::stat_identity
@@ -199,7 +199,7 @@ stat_lm <- function(mapping = NULL, data = NULL, geom = "line",
### Picking defaults
-Sometimes you have calculations that should performed once for the complete dataset, not once for each group. This is useful for picking sensible default values. For example, if we want to do a density estimate, it's reasonable to pick one bandwidth for the whole plot. The following Stat creates a variation of the `stat_density()` that picks one bandwidth for all groups by choosing the mean of the "best" bandwidth for each group (I have no theoretical justification for this, but it doesn [...]
+Sometimes you have calculations that should be performed once for the complete dataset, not once for each group. This is useful for picking sensible default values. For example, if we want to do a density estimate, it's reasonable to pick one bandwidth for the whole plot. The following Stat creates a variation of the `stat_density()` that picks one bandwidth for all groups by choosing the mean of the "best" bandwidth for each group (I have no theoretical justification for this, but it do [...]
To do this we override the `setup_params()` method. It's passed the data and a list of params, and returns an updated list.
diff --git a/vignettes/ggplot2-specs.Rmd b/vignettes/ggplot2-specs.Rmd
index 5c2cf0b..4a78e6b 100644
--- a/vignettes/ggplot2-specs.Rmd
+++ b/vignettes/ggplot2-specs.Rmd
@@ -30,11 +30,11 @@ Colours can be specified with:
in the range `00` to `FF`
You can optionally make the colour transparent by using the form
- `"#RRGGBBAA".
+ `"#RRGGBBAA"`.
* An __NA__, for a completely transparent colour.
-* The [munsell](https://github.com/cwickham/munsell) package, Charlotte
+* The [munsell](https://github.com/cwickham/munsell) package, by Charlotte
Wickham, provides a wrapper around the colour system designed by Alfred
Munsell.
@@ -61,7 +61,7 @@ Line types can be specified with:
```
* The lengths of on/off stretches of line. This is done with a string
- containing 2, 4, 6, or 8 hexadecimal digits which give the lengths of c
+ containing 2, 4, 6, or 8 hexadecimal digits which give the lengths of
consecutive lengths. For example, 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.
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-med/r-cran-ggplot2.git
More information about the debian-med-commit
mailing list