Skip to content

Commit 8d23e6c

Browse files
authored
Merge branch 'main' into v3.4.2-rc
2 parents a211bdb + d7f2241 commit 8d23e6c

File tree

93 files changed

+969
-335
lines changed

Some content is hidden

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

93 files changed

+969
-335
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=3.6.0,
66+
Hmisc=?ignore-before-r=4.1.0,
6767
quantreg=?ignore-before-r=3.6.0,
6868
needs: check
6969

DESCRIPTION

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ Suggests:
5252
hexbin,
5353
Hmisc,
5454
knitr,
55-
lattice,
5655
mapproj,
5756
maps,
5857
maptools,
@@ -63,7 +62,6 @@ Suggests:
6362
quantreg,
6463
ragg,
6564
RColorBrewer,
66-
rgeos,
6765
rmarkdown,
6866
rpart,
6967
sf (>= 0.7-3),

NEWS.md

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

3+
* To improve `width` calculation in bar plots with empty factor levels,
4+
`resolution()` considers `mapped_discrete` values as having resolution 1
5+
(@teunbrand, #5211)
6+
* When `geom_path()` has aesthetics varying within groups, the `arrow()` is
7+
applied to groups instead of individual segments (@teunbrand, #4935).
8+
* The default width of `geom_bar()` is now based on panel-wise resolution of
9+
the data, rather than global resolution (@teunbrand, #4336).
10+
* To apply dodging more consistently in violin plots, `stat_ydensity()` now
11+
has a `drop` argument to keep or discard groups with 1 observation.
12+
* Aesthetics listed in `geom_*()` and `stat_*()` layers now point to relevant
13+
documentation (@teunbrand, #5123).
14+
* `coord_flip()` has been marked as superseded. The recommended alternative is
15+
to swap the `x` and `y` aesthetic and/or using the `orientation` argument in
16+
a layer (@teunbrand, #5130).
17+
* `stat_align()` is now applied per panel instead of globally, preventing issues
18+
when facets have different ranges (@teunbrand, #5227).
19+
* A stacking bug in `stat_align()` was fixed (@teunbrand, #5176).
20+
* `stat_contour()` and `stat_contour_filled()` now warn about and remove
21+
duplicated coordinates (@teunbrand, #5215).
22+
323
# ggplot2 3.4.2
424
This is a hotfix release anticipating changes in r-devel, but folds in upkeep
525
changes and a few bug fixes as well.

R/aes-colour-fill-alpha.R

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@
88
#'
99
#' @section Colour and fill:
1010
#'
11+
#' The `colour` aesthetic is used to draw lines and strokes, such as in
12+
#' [`geom_point()`] and [`geom_line()`], but also the line contours of
13+
#' [`geom_rect()`] and [`geom_polygon()`]. The `fill` aesthetic is used to
14+
#' colour the inside areas of geoms, such as [`geom_rect()`] and
15+
#' [`geom_polygon()`], but also the insides of shapes 21-25 of [`geom_point()`].
16+
#'
1117
#' Colours and fills can be specified in the following ways:
1218
#' * A name, e.g., `"red"`. R has 657 built-in named colours, which can be
1319
#' listed with [grDevices::colors()].
@@ -38,9 +44,11 @@
3844
#' [scale_fill_gradient()], [scale_fill_grey()],
3945
#' [scale_fill_hue()], [scale_fill_identity()],
4046
#' [scale_fill_manual()], [scale_fill_viridis_d()]
41-
#' * Other options for modifying alpha: [scale_alpha()]
42-
#' * Run `vignette("ggplot2-specs")` to see an overview of other aesthestics that
47+
#' * Other options for modifying alpha:
48+
#' [scale_alpha()], [scale_alpha_manual()], [scale_alpha_identity()]
49+
#' * Run `vignette("ggplot2-specs")` to see an overview of other aesthetics that
4350
#' can be modified.
51+
#' @family aesthetics documentation
4452
#'
4553
#' @name aes_colour_fill_alpha
4654
#' @aliases colour color fill

R/aes-group-order.R

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,23 @@
1616
#' and/or `linetype`. This is demonstrated in the examples below.
1717
#'
1818
#' There are three common cases where the default does not display the data correctly.
19+
#' 1. `geom_line()` where there are multiple individuals and the plot tries to
20+
#' connect every observation, even across individuals, with a line.
21+
#' 1. `geom_line()` where a discrete x-position implies groups, whereas observations
22+
#' span the discrete x-positions.
23+
#' 1. When the grouping needs to be different over different layers, for example
24+
#' when computing a statistic on all observations when another layer shows
25+
#' individuals.
26+
#'
1927
#' The examples below use a longitudinal dataset, `Oxboys`, from the nlme package to demonstrate
2028
#' these cases. `Oxboys` records the heights (height) and centered ages (age) of 26 boys (Subject),
2129
#' measured on nine occasions (Occasion).
2230
#'
2331
#' @seealso
2432
#' * Geoms commonly used with groups: [geom_bar()], [geom_histogram()], [geom_line()]
25-
#' * Run `vignette("ggplot2-specs")` to see an overview of other aesthestics that
33+
#' * Run `vignette("ggplot2-specs")` to see an overview of other aesthetics that
2634
#' can be modified.
35+
#' @family aesthetics documentation
2736
#'
2837
#' @examples
2938
#' \donttest{

R/aes-linetype-size-shape.R

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,48 @@
11
#' Differentiation related aesthetics: linetype, size, shape
22
#'
33
#' @description
4-
#' The `linetype`, `size`, and `shape` aesthetics modify the appearance of
5-
#' lines and/or points. They also apply to the outlines of polygons (`linetype`
6-
#' and `size`) or to text (`size`).
4+
#' The `linetype`, `linewidth`, `size`, and `shape` aesthetics modify the
5+
#' appearance of lines and/or points. They also apply to the outlines of
6+
#' polygons (`linetype` and `linewidth`) or to text (`size`).
77
#'
8+
#' @section Linetype:
89
#' The `linetype` aesthetic can be specified with either an integer (0-6), a
910
#' name (0 = blank, 1 = solid, 2 = dashed, 3 = dotted, 4 = dotdash, 5 = longdash,
1011
#' 6 = twodash), a mapping to a discrete variable, or a string of an even number
1112
#' (up to eight) of hexadecimal digits which give the lengths in consecutive
1213
#' positions in the string. See examples for a hex string demonstration.
1314
#'
14-
#' The `size` aesthetic can be specified with a numerical value (in millimetres)
15-
#' or via a mapping to a continuous variable.
15+
#' @section Linewidth and stroke:
16+
#' The `linewidth` aesthetic sets the widths of lines, and can be specified
17+
#' with a numeric value (for historical reasons, these units are about 0.75
18+
#' millimetres). Alternatively, they can also be set via mapping to a continuous
19+
#' variable. The `stroke` aesthetic serves the same role for points, but is
20+
#' distinct for discriminating points from lines in geoms such as
21+
#' [`geom_pointrange()`].
1622
#'
17-
#' The `shape` aesthetic can be specified with an integer (between 0 and 25),
18-
#' a single character (which uses that character as the plotting symbol),
19-
#' a `.` to draw the smallest rectangle that is visible (i.e., about one pixel),
20-
#' an `NA` to draw nothing, or a mapping to a discrete variable. Symbols and
21-
#' filled shapes are described in the examples below.
23+
#' @section Size:
24+
#' The `size` aesthetic control the size of points and text, and can be
25+
#' specified with a numerical value (in millimetres) or via a mapping to a
26+
#' continuous variable.
27+
#'
28+
#' @section Shape:
29+
#' The `shape` aesthetic controls the symbols of points, and can be specified
30+
#' with an integer (between 0 and 25), a single character (which uses that
31+
#' character as the plotting symbol), a `.` to draw the smallest rectangle that
32+
#' is visible (i.e., about one pixel), an `NA` to draw nothing, or a mapping to
33+
#' a discrete variable. Symbols and filled shapes are described in the examples
34+
#' below.
2235
#'
2336
#' @seealso
2437
#' * [geom_line()] and [geom_point()] for geoms commonly used
2538
#' with these aesthetics.
2639
#' * [aes_group_order()] for using `linetype`, `size`, or
2740
#' `shape` for grouping.
28-
#' * Run `vignette("ggplot2-specs")` to see an overview of other aesthestics that
41+
#' * Scales that can be used to modify these aesthetics: [`scale_linetype()`],
42+
#' [`scale_linewidth()`], [`scale_size()`], and [`scale_shape()`].
43+
#' * Run `vignette("ggplot2-specs")` to see an overview of other aesthetics that
2944
#' can be modified.
45+
#' @family aesthetics documentation
3046
#' @name aes_linetype_size_shape
3147
#' @aliases linetype size shape
3248
#' @examples
@@ -45,6 +61,12 @@
4561
#' ggplot(economics_long, aes(date, value01)) +
4662
#' geom_line(aes(linetype = variable))
4763
#'
64+
#' # Linewidth examples
65+
#' ggplot(economics, aes(date, unemploy)) +
66+
#' geom_line(linewidth = 2, lineend = "round")
67+
#' ggplot(economics, aes(date, unemploy)) +
68+
#' geom_line(aes(linewidth = uempmed), lineend = "round")
69+
#'
4870
#' # Size examples
4971
#' p <- ggplot(mtcars, aes(wt, mpg))
5072
#' p + geom_point(size = 4)

R/aes-position.R

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@
1212
#' `xmin`, `xmax`, `ymin` and `ymax` can be used to specify the position of
1313
#' annotations and to represent rectangular areas.
1414
#'
15+
#' In addition, there are position aesthetics that are contextual to the
16+
#' geometry that they're used in. These are `xintercept`, `yintercept`,
17+
#' `xmin_final`, `ymin_final`, `xmax_final`, `ymax_final`, `xlower`, `lower`,
18+
#' `xmiddle`, `middle`, `xupper`, `upper`, `x0` and `y0`. Many of these are used
19+
#' and automatically computed in [`geom_boxplot()`].
20+
#'
1521
#' @name aes_position
1622
#' @aliases x y xmin xmax ymin ymax xend yend
1723
#'
@@ -20,7 +26,13 @@
2026
#' [geom_curve()], [geom_errorbar()], [geom_line()], [geom_linerange()],
2127
#' [geom_path()], [geom_point()], [geom_pointrange()], [geom_rect()],
2228
#' [geom_segment()]
29+
#' * Scales that can be used to modify positions:
30+
#' [`scale_continuous()`][scale_x_continuous()],
31+
#' [`scale_discrete()`][scale_x_discrete()],
32+
#' [`scale_binned()`][scale_x_binned()],
33+
#' [`scale_date()`][scale_x_date()].
2334
#' * See also [annotate()] for placing annotations.
35+
#' @family aesthetics documentation
2436
#' @examples
2537
#'
2638
#' # Generate data: means and standard errors of means for prices

R/aes.R

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,12 @@ NULL
3333
#' @seealso [vars()] for another quoting function designed for
3434
#' faceting specifications.
3535
#'
36+
#' Run `vignette("ggplot2-specs")` to see an overview of other aesthetics
37+
#' that can be modified.
38+
#'
3639
#' [Delayed evaluation][aes_eval] for working with computed variables.
40+
#'
41+
#' @family aesthetics documentation
3742
#' @return A list with class `uneval`. Components of the list are either
3843
#' quosures or constants.
3944
#' @export

R/coord-flip.R

Lines changed: 33 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,48 @@
11
#' Cartesian coordinates with x and y flipped
22
#'
3-
#' Flip cartesian coordinates so that horizontal becomes vertical, and
4-
#' vertical, horizontal. This is primarily useful for converting geoms and
5-
#' statistics which display y conditional on x, to x conditional on y.
3+
#' @description
4+
#' `r lifecycle::badge("superseded")`
5+
#'
6+
#' This function is superseded because in many cases, `coord_flip()` can easily
7+
#' be replaced by swapping the x and y aesthetics, or optionally setting the
8+
#' `orientation` argument in geom and stat layers.
9+
#'
10+
#' `coord_flip()` is useful for geoms and statistics that do not support
11+
#' the `orientation` setting, and converting the display of y conditional on x,
12+
#' to x conditional on y.
613
#'
714
#' @export
815
#' @inheritParams coord_cartesian
916
#' @examples
10-
#' # Very useful for creating boxplots, and other interval
11-
#' # geoms in the horizontal instead of vertical position.
17+
#' # The preferred method of creating horizontal instead of vertical boxplots
18+
#' ggplot(diamonds, aes(price, cut)) +
19+
#' geom_boxplot()
1220
#'
21+
#' # Using `coord_flip()` to make the same plot
1322
#' ggplot(diamonds, aes(cut, price)) +
1423
#' geom_boxplot() +
1524
#' coord_flip()
1625
#'
17-
#' h <- ggplot(diamonds, aes(carat)) +
18-
#' geom_histogram()
19-
#' h
20-
#' h + coord_flip()
21-
#' h + coord_flip() + scale_x_reverse()
26+
#' # With swapped aesthetics, the y-scale controls the left axis
27+
#' ggplot(diamonds, aes(y = carat)) +
28+
#' geom_histogram() +
29+
#' scale_y_reverse()
30+
#'
31+
#' # In `coord_flip()`, the x-scale controls the left axis
32+
#' ggplot(diamonds, aes(carat)) +
33+
#' geom_histogram() +
34+
#' coord_flip() +
35+
#' scale_x_reverse()
2236
#'
23-
#' # You can also use it to flip line and area plots:
24-
#' df <- data.frame(x = 1:5, y = (1:5) ^ 2)
25-
#' ggplot(df, aes(x, y)) +
26-
#' geom_area()
27-
#' last_plot() + coord_flip()
37+
#' # In line and area plots, swapped aesthetics require an explicit orientation
38+
#' df <- data.frame(a = 1:5, b = (1:5) ^ 2)
39+
#' ggplot(df, aes(b, a)) +
40+
#' geom_area(orientation = "y")
41+
#'
42+
#' # The same plot with `coord_flip()`
43+
#' ggplot(df, aes(a, b)) +
44+
#' geom_area() +
45+
#' coord_flip()
2846
coord_flip <- function(xlim = NULL, ylim = NULL, expand = TRUE, clip = "on") {
2947
ggproto(NULL, CoordFlip,
3048
limits = list(x = xlim, y = ylim),

R/geom-bar.R

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,10 @@ GeomBar <- ggproto("GeomBar", GeomRect,
144144
data$flipped_aes <- params$flipped_aes
145145
data <- flip_data(data, params$flipped_aes)
146146
data$width <- data$width %||%
147-
params$width %||% (resolution(data$x, FALSE) * 0.9)
147+
params$width %||% (min(vapply(
148+
split(data$x, data$PANEL),
149+
resolution, numeric(1), zero = FALSE
150+
)) * 0.9)
148151
data$just <- params$just %||% 0.5
149152
data <- transform(data,
150153
ymin = pmin(y, 0), ymax = pmax(y, 0),

0 commit comments

Comments
 (0)