Skip to content

Commit 154c7e6

Browse files
committed
Merge branch 'main' into restore_old_guide
2 parents 958cfc3 + b35cf63 commit 154c7e6

File tree

159 files changed

+3187
-1227
lines changed

Some content is hidden

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

159 files changed

+3187
-1227
lines changed

DESCRIPTION

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,13 @@ Imports:
3838
gtable (>= 0.1.1),
3939
isoband,
4040
lifecycle (> 1.0.1),
41-
MASS,
4241
rlang (>= 1.1.0),
4342
scales (>= 1.3.0),
4443
stats,
4544
vctrs (>= 0.6.0),
4645
withr (>= 2.5.0)
4746
Suggests:
47+
broom,
4848
covr,
4949
dplyr,
5050
ggplot2movies,
@@ -53,6 +53,7 @@ Suggests:
5353
knitr,
5454
mapproj,
5555
maps,
56+
MASS,
5657
mgcv,
5758
multcomp,
5859
munsell,
@@ -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'
@@ -151,7 +152,6 @@ Collate:
151152
'geom-density2d.R'
152153
'geom-dotplot.R'
153154
'geom-errorbar.R'
154-
'geom-errorbarh.R'
155155
'geom-freqpoly.R'
156156
'geom-function.R'
157157
'geom-hex.R'
@@ -168,7 +168,6 @@ Collate:
168168
'geom-smooth.R'
169169
'geom-spoke.R'
170170
'geom-text.R'
171-
'geom-tile.R'
172171
'geom-violin.R'
173172
'geom-vline.R'
174173
'ggplot2-package.R'
@@ -255,6 +254,7 @@ Collate:
255254
'stat-ellipse.R'
256255
'stat-function.R'
257256
'stat-identity.R'
257+
'stat-manual.R'
258258
'stat-qq-line.R'
259259
'stat-qq.R'
260260
'stat-quantilemethods.R'

NAMESPACE

Lines changed: 8 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)
@@ -475,6 +478,7 @@ export(is.scale)
475478
export(is.stat)
476479
export(is.theme)
477480
export(is.theme_element)
481+
export(is.waiver)
478482
export(label_both)
479483
export(label_bquote)
480484
export(label_context)
@@ -492,6 +496,8 @@ export(layer_sf)
492496
export(lims)
493497
export(map_data)
494498
export(margin)
499+
export(margin_auto)
500+
export(margin_part)
495501
export(max_height)
496502
export(max_width)
497503
export(mean_cl_boot)
@@ -686,6 +692,7 @@ export(stat_ecdf)
686692
export(stat_ellipse)
687693
export(stat_function)
688694
export(stat_identity)
695+
export(stat_manual)
689696
export(stat_qq)
690697
export(stat_qq_line)
691698
export(stat_quantile)
@@ -719,6 +726,7 @@ export(theme_minimal)
719726
export(theme_replace)
720727
export(theme_set)
721728
export(theme_test)
729+
export(theme_transparent)
722730
export(theme_update)
723731
export(theme_void)
724732
export(transform_position)

NEWS.md

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

3+
* `guide_*()` can now accept two inside legend theme elements:
4+
`legend.position.inside` and `legend.justification.inside`, allowing inside
5+
legends to be placed at different positions. Only inside legends with the same
6+
position and justification will be merged (@Yunuuuu, #6210).
7+
* New stat: `stat_manual()` for arbitrary computations (@teunbrand, #3501)
8+
* Reversal of a dimension, typically 'x' or 'y', is now controlled by the
9+
`reverse` argument in `coord_cartesian()`, `coord_fixed()`, `coord_radial()`
10+
and `coord_sf()`. In `coord_radial()`, this replaces the older `direction`
11+
argument (#4021, @teunbrand).
12+
* `coord_radial()` displays minor gridlines now (@teunbrand).
13+
* (internal) `continuous_scale()` and `binned_scale()` sort the `limits`
14+
argument internally (@teunbrand).
15+
* Theme margins can have NA-units to inherit from parent elements. The new
16+
function `margin_part()` has NA-units as default (@teunbrand, #6115)
17+
* New `margin_auto()` specification for theme margins.
18+
* New argument `labs(dictionary)` to label based on variable name rather than
19+
based on aesthetic (@teunbrand, #5178)
20+
* Fixed bug in out-of-bounds binned breaks (@teunbrand, #6054)
21+
* Binned guides now accept expressions as labels (@teunbrand, #6005)
22+
* (internal) `Scale$get_labels()` format expressions as lists.
23+
* In non-orthogonal coordinate systems (`coord_sf()`, `coord_polar()` and
24+
`coord_radial()`), using 'AsIs' variables escape transformation when
25+
both `x` and `y` is an 'AsIs' variable (@teunbrand, #6205).
26+
* The following methods have been deprecated: `fortify.lm()`, `fortify.glht()`,
27+
`fortify.confint.glht()`, `fortify.summary.glht()` and `fortify.cld()`. It
28+
is recommend to use `broom::augment()` and `broom::tidy()` instead
29+
(@teunbrand, #3816).
30+
* Custom and raster annotation now respond to scale transformations, and can
31+
use AsIs variables for relative placement (@teunbrand based on
32+
@yutannihilation's prior work, #3120)
33+
* When discrete breaks have names, they'll be used as labels by default
34+
(@teunbrand, #6147).
35+
* The helper function `is.waiver()` is now exported to help extensions to work
36+
with `waiver()` objects (@arcresu, #6173).
37+
* Date(time) scales now throw appropriate errors when `date_breaks`,
38+
`date_minor_breaks` or `date_labels` are not strings (@RodDalBen, #5880)
39+
* `geom_errorbarh()` is deprecated in favour of
40+
`geom_errorbar(orientation = "y")` (@teunbrand, #5961).
41+
* `geom_contour()` should be able to recognise a rotated grid of points
42+
(@teunbrand, #4320)
43+
* `geom_boxplot()` gains additional arguments to style the colour, linetype and
44+
linewidths of the box, whiskers, median line and staples (@teunbrand, #5126)
345
* (internal) Using `after_scale()` in the `Geom*$default_aes()` field is now
446
evaluated in the context of data (@teunbrand, #6135)
547
* Fixed bug where binned scales wouldn't simultaneously accept transformations
@@ -189,6 +231,18 @@
189231
`labs()` and several guides (@teunbrand, #3196).
190232
* `stat_summary_bin()` no longer ignores `width` parameter (@teunbrand, #4647).
191233
* Added `keep.zeroes` argument to `stat_bin()` (@teunbrand, #3449)
234+
* (internal) removed barriers for using 2D structures as aesthetics
235+
(@teunbrand, #4189).
236+
* `coord_sf()` no longer errors when dealing with empty graticules (@teunbrand, #6052)
237+
* Added `theme_transparent()` with transparent backgrounds (@topepo).
238+
* New theme elements `palette.{aes}.discrete` and `palette.{aes}.continuous`.
239+
Theme palettes replace palettes in scales where `palette = NULL`, which is
240+
the new default in many scales (@teunbrand, #4696).
241+
* `guide_axis()` no longer reserves space for blank ticks
242+
(@teunbrand, #4722, #6069).
243+
* `geom_abline()` clips to the panel range in the vertical direction too
244+
(@teunbrand, #6086).
245+
* Added `panel.widths` and `panel.heights` to `theme()` (#5338, @teunbrand).
192246

193247
# ggplot2 3.5.1
194248

R/annotation-custom.R

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -70,21 +70,12 @@ GeomCustomAnn <- ggproto("GeomCustomAnn", Geom,
7070

7171
draw_panel = function(data, panel_params, coord, grob, xmin, xmax,
7272
ymin, ymax) {
73-
if (!inherits(coord, "CoordCartesian")) {
74-
cli::cli_abort("{.fn annotation_custom} only works with {.fn coord_cartesian}.")
75-
}
76-
corners <- data_frame0(
77-
x = c(xmin, xmax),
78-
y = c(ymin, ymax),
79-
.size = 2
73+
range <- ranges_annotation(
74+
coord, panel_params, xmin, xmax, ymin, ymax,
75+
fun = "annotation_custom"
8076
)
81-
data <- coord$transform(corners, panel_params)
82-
83-
x_rng <- range(data$x, na.rm = TRUE)
84-
y_rng <- range(data$y, na.rm = TRUE)
85-
86-
vp <- viewport(x = mean(x_rng), y = mean(y_rng),
87-
width = diff(x_rng), height = diff(y_rng),
77+
vp <- viewport(x = mean(range$x), y = mean(range$y),
78+
width = diff(range$x), height = diff(range$y),
8879
just = c("center","center"))
8980
editGrob(grob, vp = vp, name = paste(grob$name, annotation_id()))
9081
},
@@ -99,3 +90,21 @@ annotation_id <- local({
9990
i
10091
}
10192
})
93+
94+
ranges_annotation <- function(coord, panel_params, xmin, xmax, ymin, ymax, fun) {
95+
if (!inherits(coord, "CoordCartesian")) {
96+
cli::cli_abort("{.fn {fun}} only works with {.fn coord_cartesian}.")
97+
}
98+
data <- data_frame0(xmin = xmin, xmax = xmax, ymin = ymin, ymax = ymax)
99+
data <- .ignore_data(data)[[1]]
100+
x <- panel_params$x$scale$transform_df(data)
101+
data[names(x)] <- x
102+
y <- panel_params$y$scale$transform_df(data)
103+
data[names(y)] <- y
104+
data <- .expose_data(data)[[1]]
105+
data <- coord$transform(data, panel_params)
106+
list(
107+
x = range(data$xmin, data$xmax, na.rm = TRUE),
108+
y = range(data$ymin, data$ymax, na.rm = TRUE)
109+
)
110+
}

R/annotation-raster.R

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -73,21 +73,13 @@ GeomRasterAnn <- ggproto("GeomRasterAnn", Geom,
7373

7474
draw_panel = function(data, panel_params, coord, raster, xmin, xmax,
7575
ymin, ymax, interpolate = FALSE) {
76-
if (!inherits(coord, "CoordCartesian")) {
77-
cli::cli_abort("{.fn annotation_raster} only works with {.fn coord_cartesian}.")
78-
}
79-
corners <- data_frame0(
80-
x = c(xmin, xmax),
81-
y = c(ymin, ymax),
82-
.size = 2
76+
range <- ranges_annotation(
77+
coord, panel_params, xmin, xmax, ymin, ymax,
78+
fun = "annotation_raster"
79+
)
80+
rasterGrob(raster, range$x[1], range$y[1],
81+
diff(range$x), diff(range$y), default.units = "native",
82+
just = c("left","bottom"), interpolate = interpolate
8383
)
84-
data <- coord$transform(corners, panel_params)
85-
86-
x_rng <- range(data$x, na.rm = TRUE)
87-
y_rng <- range(data$y, na.rm = TRUE)
88-
89-
rasterGrob(raster, x_rng[1], y_rng[1],
90-
diff(x_rng), diff(y_rng), default.units = "native",
91-
just = c("left","bottom"), interpolate = interpolate)
9284
}
9385
)

R/axis-secondary.R

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ is.sec_axis <- function(x) {
129129
}
130130

131131
set_sec_axis <- function(sec.axis, scale) {
132-
if (!is.waive(sec.axis)) {
132+
if (!is.waiver(sec.axis)) {
133133
if (scale$is_discrete()) {
134134
if (!identical(.subset2(sec.axis, "trans"), identity)) {
135135
cli::cli_abort("Discrete secondary axes must have the {.fn identity} transformation.")
@@ -182,11 +182,11 @@ AxisSecondary <- ggproto("AxisSecondary", NULL,
182182
if (!is.function(transform)) {
183183
cli::cli_abort("Transformation for secondary axes must be a function.")
184184
}
185-
if (is.derived(self$name) && !is.waive(scale$name)) self$name <- scale$name
185+
if (is.derived(self$name) && !is.waiver(scale$name)) self$name <- scale$name
186186
if (is.derived(self$breaks)) self$breaks <- scale$breaks
187-
if (is.waive(self$breaks)) {
187+
if (is.waiver(self$breaks)) {
188188
if (scale$is_discrete()) {
189-
self$breaks <- scale$get_breaks()
189+
self$breaks <- setNames(nm = scale$get_breaks())
190190
} else {
191191
breaks <- scale$get_transformation()$breaks
192192
n_breaks <- scale$n.breaks
@@ -235,7 +235,7 @@ AxisSecondary <- ggproto("AxisSecondary", NULL,
235235
self$mono_test(scale)
236236
breaks <- self$breaks
237237
} else {
238-
breaks <- scale$map(self$breaks)
238+
breaks <- setNames(scale$map(self$breaks), names(self$breaks))
239239
}
240240

241241
# Get scale's original range before transformation

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+
}

0 commit comments

Comments
 (0)