Skip to content

Commit d731ace

Browse files
committed
resolve merge conflict
Merge branch 'main' into scale_palettes # Conflicts: # tests/testthat/test-guides.R
2 parents c0b5734 + b29b831 commit d731ace

File tree

194 files changed

+2783
-1658
lines changed

Some content is hidden

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

194 files changed

+2783
-1658
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ jobs:
6363
cache-version: 3
6464
extra-packages: >
6565
any::rcmdcheck,
66-
Hmisc=?ignore-before-r=4.1.0,
66+
Hmisc=?ignore-before-r=4.2.0,
6767
quantreg=?ignore-before-r=4.3.0
6868
needs: check
6969

DESCRIPTION

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: ggplot2
2-
Version: 3.5.1.9000
32
Title: Create Elegant Data Visualisations Using the Grammar of Graphics
3+
Version: 3.5.1.9000
44
Authors@R: c(
55
person("Hadley", "Wickham", , "[email protected]", role = "aut",
66
comment = c(ORCID = "0000-0003-4757-117X")),
@@ -30,7 +30,7 @@ License: MIT + file LICENSE
3030
URL: https://ggplot2.tidyverse.org, https://github.com/tidyverse/ggplot2
3131
BugReports: https://github.com/tidyverse/ggplot2/issues
3232
Depends:
33-
R (>= 3.5)
33+
R (>= 4.0)
3434
Imports:
3535
cli,
3636
grDevices,
@@ -75,6 +75,7 @@ VignetteBuilder:
7575
knitr
7676
Config/Needs/website: ggtext, tidyr, forcats, tidyverse/tidytemplate
7777
Config/testthat/edition: 3
78+
Config/usethis/last-upkeep: 2024-10-24
7879
Encoding: UTF-8
7980
LazyData: true
8081
Roxygen: list(markdown = TRUE)

LICENSE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# MIT License
22

3-
Copyright (c) 2020 ggplot2 authors
3+
Copyright (c) 2024 ggplot2 core developer team
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

NAMESPACE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,6 @@ export(guides)
461461
export(has_flipped_aes)
462462
export(is.Coord)
463463
export(is.coord)
464-
export(is.element)
465464
export(is.facet)
466465
export(is.geom)
467466
export(is.ggplot)
@@ -475,6 +474,7 @@ export(is.position)
475474
export(is.scale)
476475
export(is.stat)
477476
export(is.theme)
477+
export(is.theme_element)
478478
export(label_both)
479479
export(label_bquote)
480480
export(label_context)

NEWS.md

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

3+
* (internal) Using `after_scale()` in the `Geom*$default_aes()` field is now
4+
evaluated in the context of data (@teunbrand, #6135)
5+
* Fixed bug where binned scales wouldn't simultaneously accept transformations
6+
and function-limits (@teunbrand, #6144).
7+
* Fixed bug where the `ggplot2::`-prefix did not work with `stage()`
8+
(@teunbrand, #6104).
39
* New `get_labs()` function for retrieving completed plot labels
410
(@teunbrand, #6008).
511
* Built-in `theme_*()` functions now have `ink` and `paper` arguments to control
@@ -182,6 +188,7 @@
182188
* The ellipsis argument is now checked in `fortify()`, `get_alt_text()`,
183189
`labs()` and several guides (@teunbrand, #3196).
184190
* `stat_summary_bin()` no longer ignores `width` parameter (@teunbrand, #4647).
191+
* Added `keep.zeroes` argument to `stat_bin()` (@teunbrand, #3449)
185192

186193
# ggplot2 3.5.1
187194

@@ -228,6 +235,7 @@ documentation updates.
228235
* `annotate()` now warns about `stat` or `position` arguments (@teunbrand, #5151)
229236
* `guide_coloursteps(even.steps = FALSE)` now works with discrete data that has
230237
been formatted by `cut()` (@teunbrand, #3877).
238+
* `ggsave()` now offers to install svglite if needed (@eliocamp, #6166).
231239

232240
# ggplot2 3.5.0
233241

R/aes-evaluation.R

Lines changed: 49 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
#' Below follows an overview of the three stages of evaluation and how aesthetic
3333
#' evaluation can be controlled.
3434
#'
35-
#' ## Stage 1: direct input
35+
#' ## Stage 1: direct input at the start
3636
#' The default is to map at the beginning, using the layer data provided by
3737
#' the user. If you want to map directly from the layer data you should not do
3838
#' anything special. This is the only stage where the original layer data can
@@ -87,17 +87,19 @@
8787
#' ```
8888
#'
8989
#' ## Complex staging
90-
#' If you want to map the same aesthetic multiple times, e.g. map `x` to a
91-
#' data column for the stat, but remap it for the geom, you can use the
92-
#' `stage()` function to collect multiple mappings.
90+
#' Sometimes, you may want to map the same aesthetic multiple times, e.g. map
91+
#' `x` to a data column at the start for the layer stat, but remap it later to
92+
#' a variable from the stat transformation for the layer geom. The `stage()`
93+
#' function allows you to control multiple mappings for the same aesthetic
94+
#' across all three stages of evaluation.
9395
#'
9496
#' ```r
9597
#' # Use stage to modify the scaled fill
9698
#' ggplot(mpg, aes(class, hwy)) +
9799
#' geom_boxplot(aes(fill = stage(class, after_scale = alpha(fill, 0.4))))
98100
#'
99101
#' # Using data for computing summary, but placing label elsewhere.
100-
#' # Also, we're making our own computed variable to use for the label.
102+
#' # Also, we're making our own computed variables to use for the label.
101103
#' ggplot(mpg, aes(class, displ)) +
102104
#' geom_violin() +
103105
#' stat_summary(
@@ -110,6 +112,11 @@
110112
#' )
111113
#' ```
112114
#'
115+
#' Conceptually, `aes(x)` is equivalent to `aes(stage(start = x))`, and
116+
#' `aes(after_stat(count))` is equivalent to `aes(stage(after_stat = count))`,
117+
#' and so on. `stage()` is most useful when at least two of its arguments are
118+
#' specified.
119+
#'
113120
#' ## Theme access
114121
#' The `from_theme()` function can be used to acces the [`element_geom()`]
115122
#' fields of the `theme(geom)` argument. Using `aes(colour = from_theme(ink))`
@@ -332,7 +339,7 @@ strip_stage <- function(expr) {
332339
} else if (is_call(uq_expr, "stage")) {
333340
uq_expr <- call_match(uq_expr, stage)
334341
# Prefer stat mapping if present, otherwise original mapping (fallback to
335-
# scale mapping) but there should always be two arguments to stage()
342+
# scale mapping)
336343
uq_expr$after_stat %||% uq_expr$start %||% uq_expr$after_scale
337344
} else {
338345
expr
@@ -358,3 +365,39 @@ make_labels <- function(mapping) {
358365
}
359366
Map(default_label, names(mapping), mapping)
360367
}
368+
369+
eval_aesthetics <- function(aesthetics, data, mask = NULL) {
370+
371+
env <- child_env(base_env())
372+
373+
# Here we mask functions, often to replace `stage()` with context appropriate
374+
# functions `stage_calculated()`/`stage_scaled()`.
375+
if (length(mask) > 0) {
376+
aesthetics <- substitute_aes(aesthetics, mask_function, mask = mask)
377+
}
378+
379+
evaled <- lapply(aesthetics, eval_tidy, data = data, env = env)
380+
names(evaled) <- names(aesthetics)
381+
compact(rename_aes(evaled))
382+
}
383+
384+
# `mask` is a list of functions where `names(mask)` indicate names of functions
385+
# that need to be replaced, and `mask[[i]]` is the function to replace it
386+
# with.
387+
mask_function <- function(x, mask) {
388+
if (!is.call(x)) {
389+
return(x)
390+
}
391+
nms <- names(mask)
392+
x[-1] <- lapply(x[-1], mask_function, mask = mask)
393+
if (!is_call(x, nms)) {
394+
return(x)
395+
}
396+
for (nm in nms) {
397+
if (is_call(x, nm)) {
398+
x[[1]] <- mask[[nm]]
399+
return(x)
400+
}
401+
}
402+
}
403+

R/aes.R

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,9 +198,12 @@ rename_aes <- function(x) {
198198
}
199199
x
200200
}
201-
substitute_aes <- function(x) {
201+
202+
# `x` is assumed to be a strict list of quosures;
203+
# it should have no non-quosure constants in it, even though `aes()` allows it.
204+
substitute_aes <- function(x, fun = standardise_aes_symbols, ...) {
202205
x <- lapply(x, function(aesthetic) {
203-
as_quosure(standardise_aes_symbols(quo_get_expr(aesthetic)), env = environment(aesthetic))
206+
as_quosure(fun(quo_get_expr(aesthetic), ...), env = environment(aesthetic))
204207
})
205208
class(x) <- "uneval"
206209
x

R/backports.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,6 @@ on_load({
6767
as.mask <- grid::as.mask
6868
}
6969
if ("linearGradient" %in% getNamespaceExports("grid")) {
70-
linearGradient <- grid::linearGradient()
70+
linearGradient <- grid::linearGradient
7171
}
7272
})

R/bin.R

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,7 @@ bin_breaks <- function(breaks, closed = c("right", "left")) {
5454

5555
bin_breaks_width <- function(x_range, width = NULL, center = NULL,
5656
boundary = NULL, closed = c("right", "left")) {
57-
if (length(x_range) != 2) {
58-
cli::cli_abort("{.arg x_range} must have two elements.")
59-
}
57+
check_length(x_range, 2L)
6058

6159
# binwidth seems to be the argument name supplied to width. (stat-bin and stat-bindot)
6260
check_number_decimal(width, min = 0, allow_infinite = FALSE, arg = "binwidth")
@@ -106,9 +104,7 @@ bin_breaks_width <- function(x_range, width = NULL, center = NULL,
106104

107105
bin_breaks_bins <- function(x_range, bins = 30, center = NULL,
108106
boundary = NULL, closed = c("right", "left")) {
109-
if (length(x_range) != 2) {
110-
cli::cli_abort("{.arg x_range} must have two elements.")
111-
}
107+
check_length(x_range, 2L)
112108

113109
check_number_whole(bins, min = 1)
114110
if (zero_range(x_range)) {

R/coord-.R

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -281,14 +281,6 @@ check_coord_limits <- function(
281281
if (is.null(limits)) {
282282
return(invisible(NULL))
283283
}
284-
if (!obj_is_vector(limits) || length(limits) != 2) {
285-
what <- "{.obj_type_friendly {limits}}"
286-
if (is.vector(limits)) {
287-
what <- paste0(what, " of length {length(limits)}")
288-
}
289-
cli::cli_abort(
290-
paste0("{.arg {arg}} must be a vector of length 2, not ", what, "."),
291-
call = call
292-
)
293-
}
284+
check_object(limits, is_vector, "a vector", arg = arg, call = call)
285+
check_length(limits, 2L, arg = arg, call = call)
294286
}

0 commit comments

Comments
 (0)