Skip to content

Commit 63a225c

Browse files
authored
Merge pull request #2 from tidyverse/master
Sync with tidyverse/ggplot2
2 parents 59850ac + 5274088 commit 63a225c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+2502
-233
lines changed

.Rbuildignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,4 @@ visual_test
2626
^vignettes/profiling.Rmd$
2727
^cran-comments\.md$
2828
^LICENSE\.md$
29+
^vignettes/articles$

.github/workflows/R-CMD-check.yaml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ name: R-CMD-check
1010

1111
# Increment this version when we want to clear cache
1212
env:
13-
cache-version: v4
13+
cache-version: v6
1414

1515
jobs:
1616
R-CMD-check:
@@ -24,12 +24,12 @@ jobs:
2424
config:
2525
- {os: windows-latest, r: '4.0', vdiffr: true, xref: true}
2626
- {os: macOS-latest, r: '4.0', vdiffr: true, xref: true}
27-
- {os: ubuntu-16.04, r: 'devel', vdiffr: false, xref: true}
28-
- {os: ubuntu-16.04, r: '4.0', vdiffr: true, xref: true, rspm: "https://packagemanager.rstudio.com/cran/__linux__/xenial/latest"}
29-
- {os: ubuntu-16.04, r: '3.6', vdiffr: false, xref: true, rspm: "https://packagemanager.rstudio.com/cran/__linux__/xenial/latest"}
30-
- {os: ubuntu-16.04, r: '3.5', vdiffr: false, xref: true, rspm: "https://packagemanager.rstudio.com/cran/__linux__/xenial/latest"}
31-
- {os: ubuntu-16.04, r: '3.4', vdiffr: false, xref: true, rspm: "https://packagemanager.rstudio.com/cran/__linux__/xenial/latest"}
32-
- {os: ubuntu-16.04, r: '3.3', vdiffr: false, xref: true, rspm: "https://packagemanager.rstudio.com/cran/__linux__/xenial/latest"}
27+
- {os: ubuntu-18.04, r: 'devel', vdiffr: false, xref: true}
28+
- {os: ubuntu-18.04, r: '4.0', vdiffr: true, xref: true, rspm: "https://packagemanager.rstudio.com/cran/__linux__/bionic/latest"}
29+
- {os: ubuntu-18.04, r: '3.6', vdiffr: false, xref: true, rspm: "https://packagemanager.rstudio.com/cran/__linux__/bionic/latest"}
30+
- {os: ubuntu-18.04, r: '3.5', vdiffr: false, xref: true, rspm: "https://packagemanager.rstudio.com/cran/__linux__/bionic/latest"}
31+
- {os: ubuntu-18.04, r: '3.4', vdiffr: false, xref: true, rspm: "https://packagemanager.rstudio.com/cran/__linux__/bionic/latest"}
32+
- {os: ubuntu-18.04, r: '3.3', vdiffr: false, xref: true, rspm: "https://packagemanager.rstudio.com/cran/__linux__/bionic/latest"}
3333

3434
env:
3535
R_REMOTES_NO_ERRORS_FROM_WARNINGS: true
@@ -72,13 +72,13 @@ jobs:
7272
while read -r cmd
7373
do
7474
eval sudo $cmd
75-
done < <(Rscript -e 'writeLines(remotes::system_requirements("ubuntu", "16.04"))')
75+
done < <(Rscript -e 'writeLines(remotes::system_requirements("ubuntu", "18.04"))')
7676
7777
- name: Install system dependencies on macOS
7878
if: runner.os == 'macOS'
7979
run: |
8080
# XQuartz is needed by vdiffr
81-
brew cask install xquartz
81+
brew install xquartz
8282
8383
# Use only binary packages
8484
echo 'options(pkgType = "binary")' >> ~/.Rprofile

.github/workflows/pkgdown.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ jobs:
3636
- name: Install dependencies
3737
run: |
3838
remotes::install_deps(dependencies = TRUE, type = "binary")
39-
remotes::install_github("tidyverse/tidytemplate")
40-
remotes::install_dev("pkgdown")
39+
remotes::install_github("tidyverse/tidytemplate", type = "binary")
40+
remotes::install_dev("pkgdown", type = "binary")
4141
shell: Rscript {0}
4242

4343
- name: Install package

.github/workflows/test-coverage.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ jobs:
4141
- name: Install system dependencies on macOS
4242
run: |
4343
# XQuartz is needed by vdiffr
44-
brew cask install xquartz
44+
brew install xquartz
4545
4646
- name: Install dependencies
4747
run: |

DESCRIPTION

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,19 @@ Imports:
3535
isoband,
3636
MASS,
3737
mgcv,
38-
rlang (>= 0.3.0),
38+
rlang (>= 0.4.10),
3939
scales (>= 0.5.0),
4040
stats,
4141
tibble,
4242
withr (>= 2.0.0)
4343
Suggests:
4444
covr,
45+
ragg,
4546
dplyr,
4647
ggplot2movies,
4748
hexbin,
4849
Hmisc,
50+
interp,
4951
knitr,
5052
lattice,
5153
mapproj,
@@ -267,3 +269,7 @@ VignetteBuilder: knitr
267269
RoxygenNote: 7.1.1
268270
Roxygen: list(markdown = TRUE)
269271
Encoding: UTF-8
272+
Config/Needs/website:
273+
ggtext,
274+
tidyr,
275+
forcats

NEWS.md

Lines changed: 56 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,43 @@
11
# ggplot2 (development version)
22

3+
4+
* Make sure that default labels from default mappings doesn't overwrite default
5+
labels from explicit mappings (@thomasp85, #2406)
6+
7+
* `stat_count()` now computes width based on the full dataset instead of per
8+
group (@thomasp85, #2047)
9+
10+
* Fix bug in `labeller()` where parsing was turned off if `.multiline = FALSE`
11+
(@thomasp85, #4084)
12+
13+
* Fix a bug in `qplot()` when supplying `c(NA, NA)` as axis limits
14+
(@thomasp85, #4027)
15+
16+
* Fix bug in `geom_dotplot()` where dots would be positioned wrong with
17+
`stackgroups = TRUE` (@thomasp85, #1745)
18+
19+
* Make sure position_jitter creates the same jittering independent of whether it
20+
is called by name or with constructor (@thomasp85, #2507)
21+
22+
* Fix a bug in `position_dodge2()` where `NA` values in thee data would cause an
23+
error (@thomasp85, #2905)
24+
25+
* Fix a bug in `position_jitter()` where different jitters would be applied to
26+
different position aesthetics of the same axis (@thomasp85, #2941)
27+
28+
* `ggsave()` now uses ragg to render raster output if ragg is available
29+
(@thomasp85, #4388)
30+
31+
* `coord_sf()` now has an argument `default_crs` that specifies the coordinate
32+
reference system (CRS) for non-sf layers and scale/coord limits. This argument
33+
defaults to the World Geodetic System 1984 (WGS84), which means x and y positions
34+
are interpreted as longitude and latitude. This is a potentially breaking change
35+
for users who use projected coordinates in non-sf layers or in limits. Setting
36+
`default_crs = NULL` recovers the old behavior. Further, authors of extension
37+
packages implementing `stat_sf()`-like functionality are encouraged to look at the
38+
source code of `stat_sf()`'s `compute_group()` function to see how to provide
39+
scale-limit hints to `coord_sf()` (@clauswilke, #3659).
40+
341
* `ggsave()` now sets the default background to match the fill value of the
442
`plot.background` theme element (@karawoo, #4057)
543

@@ -22,8 +60,23 @@
2260

2361
* `stat_bin()`'s computed variable `width` is now documented (#3522).
2462

63+
* Fixed a bug in strip assembly when theme has `strip.text = element_blank()`
64+
and plots are faceted with multi-layered strips (@teunbrand, #4384).
65+
2566
* ggplot2 now requires R >= 3.3 (#4247).
2667

68+
* ggplot2 now uses `rlang::check_installed()` to check if a suggested package is
69+
installed, which will offer to install the package before continuing (#4375,
70+
@malcolmbarrett)
71+
72+
* Improved error with hint when piping a `ggplot` object into a facet function
73+
(#4379, @mitchelloharawild).
74+
75+
* Fix a bug that `after_stat()` and `after_scale()` cannot refer to aesthetics
76+
if it's specified in the plot-global mapping (@yutannihilation, #4260).
77+
78+
* `ggsave()` now returns the saved file location invisibly (#3379, @eliocamp).
79+
2780
# ggplot2 3.3.3
2881
This is a small patch release mainly intended to address changes in R and CRAN.
2982
It further changes the licensing model of ggplot2 to an MIT license.
@@ -34,6 +87,9 @@ It further changes the licensing model of ggplot2 to an MIT license.
3487

3588
* Update tests to work with the new `all.equal()` defaults in R >4.0.3
3689

90+
* Fixed a bug that `guide_bins()` mistakenly ignore `override.aes` argument
91+
(@yutannihilation, #4085).
92+
3793
# ggplot2 3.3.2
3894
This is a small release focusing on fixing regressions introduced in 3.3.1.
3995

@@ -42,16 +98,6 @@ This is a small release focusing on fixing regressions introduced in 3.3.1.
4298

4399
* `annotation_raster()` adds support for native rasters. For large rasters,
44100
native rasters render significantly faster than arrays (@kent37, #3388)
45-
46-
* `coord_sf()` now has an argument `default_crs` that specifies the coordinate
47-
reference system (CRS) for non-sf layers and scale/coord limits. This argument
48-
defaults to the World Geodetic System 1984 (WGS84), which means x and y positions
49-
are interpreted as longitude and latitude. This is a potentially breaking change
50-
for users who use projected coordinates in non-sf layers or in limits. Setting
51-
`default_crs = NULL` recovers the old behavior. Further, authors of extension
52-
packages implementing `stat_sf()`-like functionality are encouraged to look at the
53-
source code of `stat_sf()`'s `compute_group()` function to see how to provide
54-
scale-limit hints to `coord_sf()` (@clauswilke, #3659).
55101

56102
* Facet strips now have dedicated position-dependent theme elements
57103
(`strip.text.x.top`, `strip.text.x.bottom`, `strip.text.y.left`,

R/coord-map.r

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,7 @@ CoordMap <- ggproto("CoordMap", Coord,
318318

319319

320320
mproject <- function(coord, x, y, orientation) {
321+
check_installed("mapproj", reason = "for `coord_map()`")
321322
suppressWarnings(mapproj::mapproject(x, y,
322323
projection = coord$projection,
323324
parameters = coord$params,

R/coord-sf.R

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,9 @@ CoordSf <- ggproto("CoordSf", CoordCartesian,
6262
return(layer_data)
6363
}
6464

65-
sf::st_transform(layer_data, params$crs)
65+
idx <- vapply(layer_data, inherits, what = "sfc", FUN.VALUE = logical(1L))
66+
layer_data[idx] <- lapply(layer_data[idx], sf::st_transform, crs = params$crs)
67+
layer_data
6668
})
6769
},
6870

R/facet-.r

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -276,9 +276,7 @@ df.grid <- function(a, b) {
276276
# facetting variables.
277277

278278
as_facets_list <- function(x) {
279-
if (inherits(x, "uneval")) {
280-
abort("Please use `vars()` to supply facet variables")
281-
}
279+
x <- validate_facets(x)
282280
if (is_quosures(x)) {
283281
x <- quos_auto_name(x)
284282
return(list(x))
@@ -315,11 +313,24 @@ as_facets_list <- function(x) {
315313
x
316314
}
317315

316+
validate_facets <- function(x) {
317+
if (inherits(x, "uneval")) {
318+
abort("Please use `vars()` to supply facet variables")
319+
}
320+
if (inherits(x, "ggplot")) {
321+
abort(
322+
"Please use `vars()` to supply facet variables\nDid you use %>% instead of +?"
323+
)
324+
}
325+
x
326+
}
327+
328+
318329
# Flatten a list of quosures objects to a quosures object, and compact it
319330
compact_facets <- function(x) {
320331
x <- flatten_if(x, is_list)
321-
null <- vapply(x, quo_is_null, logical(1))
322-
new_quosures(x[!null])
332+
null_or_missing <- vapply(x, function(x) quo_is_null(x) || quo_is_missing(x), logical(1))
333+
new_quosures(x[!null_or_missing])
323334
}
324335

325336
# Compatibility with plyr::as.quoted()

R/facet-grid-.r

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,14 @@ grid_as_facets_list <- function(rows, cols) {
157157
is_rows_vars <- is.null(rows) || is_quosures(rows)
158158
if (!is_rows_vars) {
159159
if (!is.null(cols)) {
160-
abort("`rows` must be `NULL` or a `vars()` list if `cols` is a `vars()` list")
160+
msg <- "`rows` must be `NULL` or a `vars()` list if `cols` is a `vars()` list"
161+
if(inherits(rows, "ggplot")) {
162+
msg <- paste0(
163+
msg, "\n",
164+
"Did you use %>% instead of +?"
165+
)
166+
}
167+
abort(msg)
161168
}
162169
# For backward-compatibility
163170
facets_list <- as_facets_list(rows)

R/facet-wrap.r

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,13 @@ facet_wrap <- function(facets, nrow = NULL, ncol = NULL, scales = "fixed",
8686
x = any(scales %in% c("free_x", "free")),
8787
y = any(scales %in% c("free_y", "free"))
8888
)
89+
90+
# Check for deprecated labellers
91+
labeller <- check_labeller(labeller)
92+
93+
# Flatten all facets dimensions into a single one
94+
facets <- wrap_as_facets_list(facets)
95+
8996
if (!is.null(switch)) {
9097
.Deprecated("strip.position", old = "switch")
9198
strip.position <- if (switch == "x") "bottom" else "left"
@@ -102,12 +109,6 @@ facet_wrap <- function(facets, nrow = NULL, ncol = NULL, scales = "fixed",
102109
ncol <- sanitise_dim(ncol)
103110
}
104111

105-
# Check for deprecated labellers
106-
labeller <- check_labeller(labeller)
107-
108-
# Flatten all facets dimensions into a single one
109-
facets <- wrap_as_facets_list(facets)
110-
111112
ggproto(NULL, FacetWrap,
112113
shrink = shrink,
113114
params = list(

R/fortify-map.r

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ fortify.map <- function(model, data, ...) {
7575
#' coord_map("albers", lat0 = 45.5, lat1 = 29.5)
7676
#' }
7777
map_data <- function(map, region = ".", exact = FALSE, ...) {
78-
try_require("maps", "map_data")
78+
check_installed("maps", reason = "for `map_data()`")
7979
map_obj <- maps::map(map, region, exact = exact, plot = FALSE, fill = TRUE, ...)
8080
fortify(map_obj)
8181
}

R/fortify.r

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,7 @@ fortify.data.frame <- function(model, data, ...) model
1717
fortify.tbl_df <- function(model, data, ...) model
1818
#' @export
1919
fortify.tbl <- function(model, data, ...) {
20-
if (!requireNamespace("dplyr", quietly = TRUE)) {
21-
abort("dplyr must be installed to work with tbl objects")
22-
}
20+
check_installed("dplyr", reason = "to work with `tbl` objects")
2321
dplyr::collect(model)
2422
}
2523
#' @export
@@ -31,9 +29,7 @@ fortify.function <- function(model, data, ...) model
3129
fortify.formula <- function(model, data, ...) as_function(model)
3230
#' @export
3331
fortify.grouped_df <- function(model, data, ...) {
34-
if (!requireNamespace("dplyr", quietly = TRUE)) {
35-
abort("dplyr must be installed to work with grouped_df objects")
36-
}
32+
check_installed("dplyr", reason = "to work with `grouped_df` objects")
3733
model$.group <- dplyr::group_indices(model)
3834
model
3935
}

R/geom-contour.r

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
#' 2D contours of a 3D surface
22
#'
33
#' ggplot2 can not draw true 3D surfaces, but you can use `geom_contour()`,
4-
#' `geom_contour_filled()`, and [geom_tile()] to visualise 3D surfaces in 2D.
5-
#' To specify a valid surface, the data must contain `x`, `y`, and `z` coordinates,
6-
#' and each unique combination of `x` and `y` can appear exactly once. Contouring
7-
#' tends to work best when `x` and `y` form a (roughly) evenly
8-
#' spaced grid. If your data is not evenly spaced, you may want to interpolate
9-
#' to a grid before visualising, see [geom_density_2d()].
4+
#' `geom_contour_filled()`, and [geom_tile()] to visualise 3D surfaces in 2D. To
5+
#' specify a valid surface, the data must contain `x`, `y`, and `z` coordinates,
6+
#' and each unique combination of `x` and `y` can appear at most once.
7+
#' Contouring requires that the points can be rearranged so that the `z` values
8+
#' form a matrix, with rows corresponding to unique `x` values, and columns
9+
#' corresponding to unique `y` values. Missing entries are allowed, but contouring
10+
#' will only be done on cells of the grid with all four `z` values present. If
11+
#' your data is irregular, you can interpolate to a grid before visualising
12+
#' using the [interp::interp()] function from the `interp` package
13+
#' (or one of the interpolating functions from the `akima` package.)
1014
#'
1115
#' @eval rd_aesthetics("geom", "contour")
1216
#' @eval rd_aesthetics("geom", "contour_filled")
@@ -15,9 +19,9 @@
1519
#' @inheritParams geom_path
1620
#' @param bins Number of contour bins. Overridden by `binwidth`.
1721
#' @param binwidth The width of the contour bins. Overridden by `breaks`.
18-
#' @param breaks Numeric vector to set the contour breaks.
19-
#' Overrides `binwidth` and `bins`. By default, this is a vector of
20-
#' length ten with [pretty()] breaks.
22+
#' @param breaks Numeric vector to set the contour breaks. Overrides `binwidth`
23+
#' and `bins`. By default, this is a vector of length ten with [pretty()]
24+
#' breaks.
2125
#' @seealso [geom_density_2d()]: 2d density contours
2226
#' @export
2327
#' @examples
@@ -47,6 +51,22 @@
4751
#' v + geom_contour(colour = "red")
4852
#' v + geom_raster(aes(fill = density)) +
4953
#' geom_contour(colour = "white")
54+
#'
55+
#' # Irregular data
56+
#' if (requireNamespace("interp")) {
57+
#' # Use a dataset from the interp package
58+
#' data(franke, package = "interp")
59+
#' origdata <- as.data.frame(interp::franke.data(1, 1, franke))
60+
#' grid <- with(origdata, interp::interp(x, y, z))
61+
#' griddf <- subset(data.frame(x = rep(grid$x, nrow(grid$z)),
62+
#' y = rep(grid$y, each = ncol(grid$z)),
63+
#' z = as.numeric(grid$z)),
64+
#' !is.na(z))
65+
#' ggplot(griddf, aes(x, y, z = z)) +
66+
#' geom_contour_filled() +
67+
#' geom_point(data = origdata)
68+
#' } else
69+
#' message("Irregular data requires the 'interp' package")
5070
#' }
5171
geom_contour <- function(mapping = NULL, data = NULL,
5272
stat = "contour", position = "identity",

0 commit comments

Comments
 (0)