Skip to content

Commit 012bfaf

Browse files
authored
Merge branch 'main' into guide_bins_reverse
2 parents efe61b3 + 8efc700 commit 012bfaf

File tree

181 files changed

+3610
-1401
lines changed

Some content is hidden

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

181 files changed

+3610
-1401
lines changed

DESCRIPTION

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ Imports:
4444
vctrs (>= 0.6.0),
4545
withr (>= 2.5.0)
4646
Suggests:
47+
broom,
4748
covr,
4849
dplyr,
4950
ggplot2movies,
@@ -126,15 +127,15 @@ Collate:
126127
'facet-grid-.R'
127128
'facet-null.R'
128129
'facet-wrap.R'
129-
'fortify-lm.R'
130130
'fortify-map.R'
131-
'fortify-multcomp.R'
131+
'fortify-models.R'
132132
'fortify-spatial.R'
133133
'fortify.R'
134134
'stat-.R'
135135
'geom-abline.R'
136136
'geom-rect.R'
137137
'geom-bar.R'
138+
'geom-tile.R'
138139
'geom-bin2d.R'
139140
'geom-blank.R'
140141
'geom-boxplot.R'
@@ -167,7 +168,6 @@ Collate:
167168
'geom-smooth.R'
168169
'geom-spoke.R'
169170
'geom-text.R'
170-
'geom-tile.R'
171171
'geom-violin.R'
172172
'geom-vline.R'
173173
'ggplot2-package.R'
@@ -254,6 +254,7 @@ Collate:
254254
'stat-ellipse.R'
255255
'stat-function.R'
256256
'stat-identity.R'
257+
'stat-manual.R'
257258
'stat-qq-line.R'
258259
'stat-qq.R'
259260
'stat-quantilemethods.R'
@@ -273,6 +274,7 @@ Collate:
273274
'theme.R'
274275
'theme-defaults.R'
275276
'theme-current.R'
277+
'theme-sub.R'
276278
'utilities-break.R'
277279
'utilities-grid.R'
278280
'utilities-help.R'

NAMESPACE

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ S3method(makeContext,dotstackGrob)
9494
S3method(merge_element,default)
9595
S3method(merge_element,element)
9696
S3method(merge_element,element_blank)
97+
S3method(merge_element,margin)
9798
S3method(pattern_alpha,GridPattern)
9899
S3method(pattern_alpha,GridTilingPattern)
99100
S3method(pattern_alpha,default)
@@ -172,6 +173,7 @@ export(GeomAbline)
172173
export(GeomAnnotationMap)
173174
export(GeomArea)
174175
export(GeomBar)
176+
export(GeomBin2d)
175177
export(GeomBlank)
176178
export(GeomBoxplot)
177179
export(GeomCol)
@@ -263,6 +265,7 @@ export(StatEcdf)
263265
export(StatEllipse)
264266
export(StatFunction)
265267
export(StatIdentity)
268+
export(StatManual)
266269
export(StatQq)
267270
export(StatQqLine)
268271
export(StatQuantile)
@@ -493,6 +496,8 @@ export(layer_sf)
493496
export(lims)
494497
export(map_data)
495498
export(margin)
499+
export(margin_auto)
500+
export(margin_part)
496501
export(max_height)
497502
export(max_width)
498503
export(mean_cl_boot)
@@ -687,6 +692,7 @@ export(stat_ecdf)
687692
export(stat_ellipse)
688693
export(stat_function)
689694
export(stat_identity)
695+
export(stat_manual)
690696
export(stat_qq)
691697
export(stat_qq_line)
692698
export(stat_quantile)
@@ -719,7 +725,19 @@ export(theme_linedraw)
719725
export(theme_minimal)
720726
export(theme_replace)
721727
export(theme_set)
728+
export(theme_sub_axis)
729+
export(theme_sub_axis_bottom)
730+
export(theme_sub_axis_left)
731+
export(theme_sub_axis_right)
732+
export(theme_sub_axis_top)
733+
export(theme_sub_axis_x)
734+
export(theme_sub_axis_y)
735+
export(theme_sub_legend)
736+
export(theme_sub_panel)
737+
export(theme_sub_plot)
738+
export(theme_sub_strip)
722739
export(theme_test)
740+
export(theme_transparent)
723741
export(theme_update)
724742
export(theme_void)
725743
export(transform_position)

NEWS.md

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

33
* Fixed regression in `guide_bins(reverse = TRUE)` (@teunbrand, #6183).
4+
* New function family for setting parts of a theme. For example, you can now use
5+
`theme_sub_axis(line, text, ticks, ticks.length, line)` as a substitute for
6+
`theme(axis.line, axis.text, axis.ticks, axis.ticks.length, axis.line)`. This
7+
should allow slightly terser and more organised theme declarations
8+
(@teunbrand, #5301).
9+
* `scale_{x/y}_discrete(continuous.limits)` is a new argument to control the
10+
display range of discrete scales (@teunbrand, #4174, #6259).
11+
* `geom_ribbon()` now appropriately warns about, and removes, missing values
12+
(@teunbrand, #6243).
13+
* `guide_*()` can now accept two inside legend theme elements:
14+
`legend.position.inside` and `legend.justification.inside`, allowing inside
15+
legends to be placed at different positions. Only inside legends with the same
16+
position and justification will be merged (@Yunuuuu, #6210).
17+
* New stat: `stat_manual()` for arbitrary computations (@teunbrand, #3501)
18+
* Reversal of a dimension, typically 'x' or 'y', is now controlled by the
19+
`reverse` argument in `coord_cartesian()`, `coord_fixed()`, `coord_radial()`
20+
and `coord_sf()`. In `coord_radial()`, this replaces the older `direction`
21+
argument (#4021, @teunbrand).
22+
* `coord_radial()` displays minor gridlines now (@teunbrand).
23+
* (internal) `continuous_scale()` and `binned_scale()` sort the `limits`
24+
argument internally (@teunbrand).
25+
* Theme margins can have NA-units to inherit from parent elements. The new
26+
function `margin_part()` has NA-units as default (@teunbrand, #6115)
27+
* New `margin_auto()` specification for theme margins.
28+
* New argument `labs(dictionary)` to label based on variable name rather than
29+
based on aesthetic (@teunbrand, #5178)
30+
* Fixed bug in out-of-bounds binned breaks (@teunbrand, #6054)
31+
* Binned guides now accept expressions as labels (@teunbrand, #6005)
32+
* (internal) `Scale$get_labels()` format expressions as lists.
33+
* In non-orthogonal coordinate systems (`coord_sf()`, `coord_polar()` and
34+
`coord_radial()`), using 'AsIs' variables escape transformation when
35+
both `x` and `y` is an 'AsIs' variable (@teunbrand, #6205).
36+
* The following methods have been deprecated: `fortify.lm()`, `fortify.glht()`,
37+
`fortify.confint.glht()`, `fortify.summary.glht()` and `fortify.cld()`. It
38+
is recommend to use `broom::augment()` and `broom::tidy()` instead
39+
(@teunbrand, #3816).
440
* Custom and raster annotation now respond to scale transformations, and can
541
use AsIs variables for relative placement (@teunbrand based on
642
@yutannihilation's prior work, #3120)
@@ -16,6 +52,13 @@
1652
(@teunbrand, #4320)
1753
* `geom_boxplot()` gains additional arguments to style the colour, linetype and
1854
linewidths of the box, whiskers, median line and staples (@teunbrand, #5126)
55+
* `geom_violin()` gains additional arguments to style the colour, linetype and
56+
linewidths of the quantiles, which replace the now-deprecated `draw_quantiles`
57+
argument (#5912).
58+
* (breaking) `geom_violin(quantiles)` now has actual quantiles based on
59+
the data, rather than inferred quantiles based on the computed density. The
60+
`quantiles` parameter that replaces `draw_quantiles` now belongs to
61+
`stat_ydensity()` instead of `geom_violin()` (@teunbrand, #4120).
1962
* (internal) Using `after_scale()` in the `Geom*$default_aes()` field is now
2063
evaluated in the context of data (@teunbrand, #6135)
2164
* Fixed bug where binned scales wouldn't simultaneously accept transformations
@@ -205,7 +248,20 @@
205248
`labs()` and several guides (@teunbrand, #3196).
206249
* `stat_summary_bin()` no longer ignores `width` parameter (@teunbrand, #4647).
207250
* Added `keep.zeroes` argument to `stat_bin()` (@teunbrand, #3449)
251+
* (internal) removed barriers for using 2D structures as aesthetics
252+
(@teunbrand, #4189).
208253
* `coord_sf()` no longer errors when dealing with empty graticules (@teunbrand, #6052)
254+
* Added `theme_transparent()` with transparent backgrounds (@topepo).
255+
* New theme elements `palette.{aes}.discrete` and `palette.{aes}.continuous`.
256+
Theme palettes replace palettes in scales where `palette = NULL`, which is
257+
the new default in many scales (@teunbrand, #4696).
258+
* `guide_axis()` no longer reserves space for blank ticks
259+
(@teunbrand, #4722, #6069).
260+
* `geom_abline()` clips to the panel range in the vertical direction too
261+
(@teunbrand, #6086).
262+
* Added `panel.widths` and `panel.heights` to `theme()` (#5338, @teunbrand).
263+
* Standardised the calculation of `width`, which are now implemented as
264+
aesthetics (@teunbrand, #2800).
209265

210266
# ggplot2 3.5.1
211267

R/aes.R

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,13 @@ NULL
3838
#'
3939
#' [Delayed evaluation][aes_eval] for working with computed variables.
4040
#'
41+
#' @note
42+
#' Using `I()` to create objects of class 'AsIs' causes scales to ignore the
43+
#' variable and assumes the wrapped variable is direct input for the grid
44+
#' package. Please be aware that variables are sometimes combined, like in
45+
#' some stats or position adjustments, that may yield unexpected results with
46+
#' 'AsIs' variables.
47+
#'
4148
#' @family aesthetics documentation
4249
#' @return A list with class `uneval`. Components of the list are either
4350
#' quosures or constants.

R/coord-.R

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ Coord <- ggproto("Coord",
5959
# "on" = yes, "off" = no
6060
clip = "on",
6161

62+
# Should any of the scales be reversed?
63+
reverse = "none",
64+
6265
aspect = function(ranges) NULL,
6366

6467
labels = function(self, labels, panel_params) {
@@ -185,11 +188,7 @@ Coord <- ggproto("Coord",
185188
is_free = function() FALSE,
186189

187190
setup_params = function(self, data) {
188-
list(
189-
guide_default = guide_axis(),
190-
guide_missing = guide_none(),
191-
expand = parse_coord_expand(self$expand %||% TRUE)
192-
)
191+
list(expand = parse_coord_expand(self$expand %||% TRUE))
193192
},
194193

195194
setup_data = function(data, params = list()) {
@@ -284,3 +283,24 @@ check_coord_limits <- function(
284283
check_object(limits, is_vector, "a vector", arg = arg, call = call)
285284
check_length(limits, 2L, arg = arg, call = call)
286285
}
286+
287+
is_transform_immune <- function(data, coord_name) {
288+
x <- inherits(data$x, "AsIs")
289+
y <- inherits(data$y, "AsIs")
290+
if (!(x || y)) {
291+
# Neither variable is AsIs, so we need to transform
292+
return(FALSE)
293+
}
294+
if (x && y) {
295+
# Both variables are AsIs, so no need to transform
296+
return(TRUE)
297+
}
298+
# We're now in the `xor(x, y)` case
299+
var <- if (x) "x" else "y"
300+
alt <- if (x) "y" else "x"
301+
cli::cli_warn(
302+
"{.fn {coord_name}} cannot respect the {.cls AsIs} class of {.var {var}} \\
303+
when {.var {alt}} is not also {.cls AsIs}."
304+
)
305+
return(FALSE)
306+
}

R/coord-cartesian-.R

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@
2525
#' limits are set via `xlim` and `ylim` and some data points fall outside those
2626
#' limits, then those data points may show up in places such as the axes, the
2727
#' legend, the plot title, or the plot margins.
28+
#' @param reverse A string giving which directions to reverse. `"none"`
29+
#' (default) keeps directions as is. `"x"` and `"y"` can be used to reverse
30+
#' their respective directions. `"xy"` can be used to reverse both
31+
#' directions.
2832
#' @export
2933
#' @examples
3034
#' # There are two ways of zooming the plot display: with scales or
@@ -64,11 +68,12 @@
6468
#' # displayed bigger
6569
#' d + coord_cartesian(xlim = c(0, 1))
6670
coord_cartesian <- function(xlim = NULL, ylim = NULL, expand = TRUE,
67-
default = FALSE, clip = "on") {
71+
default = FALSE, clip = "on", reverse = "none") {
6872
check_coord_limits(xlim)
6973
check_coord_limits(ylim)
7074
ggproto(NULL, CoordCartesian,
7175
limits = list(x = xlim, y = ylim),
76+
reverse = reverse,
7277
expand = expand,
7378
default = default,
7479
clip = clip
@@ -97,8 +102,11 @@ CoordCartesian <- ggproto("CoordCartesian", Coord,
97102
self$range(panel_params)
98103
},
99104

100-
transform = function(data, panel_params) {
101-
data <- transform_position(data, panel_params$x$rescale, panel_params$y$rescale)
105+
transform = function(self, data, panel_params) {
106+
reverse <- self$reverse %||% "none"
107+
x <- panel_params$x[[switch(reverse, xy = , x = "reverse", "rescale")]]
108+
y <- panel_params$y[[switch(reverse, xy = , y = "reverse", "rescale")]]
109+
data <- transform_position(data, x, y)
102110
transform_position(data, squish_infinite, squish_infinite)
103111
},
104112

@@ -109,14 +117,8 @@ CoordCartesian <- ggproto("CoordCartesian", Coord,
109117
)
110118
},
111119

112-
render_bg = function(panel_params, theme) {
113-
guide_grid(
114-
theme,
115-
panel_params$x$break_positions_minor(),
116-
panel_params$x$break_positions(),
117-
panel_params$y$break_positions_minor(),
118-
panel_params$y$break_positions()
119-
)
120+
render_bg = function(self, panel_params, theme) {
121+
guide_grid(theme, panel_params, self)
120122
},
121123

122124
render_axis_h = function(panel_params, theme) {

R/coord-fixed.R

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,15 @@
2222
#' p + coord_fixed(xlim = c(15, 30))
2323
#'
2424
#' # Resize the plot to see that the specified aspect ratio is maintained
25-
coord_fixed <- function(ratio = 1, xlim = NULL, ylim = NULL, expand = TRUE, clip = "on") {
25+
coord_fixed <- function(ratio = 1, xlim = NULL, ylim = NULL, expand = TRUE,
26+
clip = "on", reverse = "none") {
2627
check_coord_limits(xlim)
2728
check_coord_limits(ylim)
2829
ggproto(NULL, CoordFixed,
2930
limits = list(x = xlim, y = ylim),
3031
ratio = ratio,
3132
expand = expand,
33+
reverse = reverse,
3234
clip = clip
3335
)
3436
}

R/coord-polar.R

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
#' # to demonstrate how these common plots can be described in the
2121
#' # grammar. Use with EXTREME caution.
2222
#'
23-
#' #' # A pie chart = stacked bar chart + polar coordinates
23+
#' # A pie chart = stacked bar chart + polar coordinates
2424
#' pie <- ggplot(mtcars, aes(x = factor(1), fill = factor(cyl))) +
2525
#' geom_bar(width = 1)
2626
#' pie + coord_polar(theta = "y")
@@ -180,6 +180,10 @@ CoordPolar <- ggproto("CoordPolar", Coord,
180180
},
181181

182182
transform = function(self, data, panel_params) {
183+
if (is_transform_immune(data, snake_class(self))) {
184+
return(data)
185+
}
186+
183187
arc <- self$start + c(0, 2 * pi)
184188
dir <- self$direction
185189
data <- rename_data(self, data)

0 commit comments

Comments
 (0)