Skip to content

Commit 6016834

Browse files
authored
Merge branch 'main' into partial_margins
2 parents b4a085e + 4af509e commit 6016834

File tree

107 files changed

+1989
-936
lines changed

Some content is hidden

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

107 files changed

+1989
-936
lines changed

DESCRIPTION

Lines changed: 4 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'

NAMESPACE

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ export(GeomAbline)
173173
export(GeomAnnotationMap)
174174
export(GeomArea)
175175
export(GeomBar)
176+
export(GeomBin2d)
176177
export(GeomBlank)
177178
export(GeomBoxplot)
178179
export(GeomCol)
@@ -476,6 +477,7 @@ export(is.scale)
476477
export(is.stat)
477478
export(is.theme)
478479
export(is.theme_element)
480+
export(is.waiver)
479481
export(label_both)
480482
export(label_bquote)
481483
export(label_context)
@@ -722,6 +724,7 @@ export(theme_minimal)
722724
export(theme_replace)
723725
export(theme_set)
724726
export(theme_test)
727+
export(theme_transparent)
725728
export(theme_update)
726729
export(theme_void)
727730
export(transform_position)

NEWS.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,33 @@
33
* Theme margins can have NA-units to inherit from parent elements. The new
44
function `margin_part()` has NA-units as default (@teunbrand, #6115)
55
* New `margin_auto()` specification for theme margins.
6+
* New argument `labs(dictionary)` to label based on variable name rather than
7+
based on aesthetic (@teunbrand, #5178)
8+
* Fixed bug in out-of-bounds binned breaks (@teunbrand, #6054)
9+
* Binned guides now accept expressions as labels (@teunbrand, #6005)
10+
* (internal) `Scale$get_labels()` format expressions as lists.
11+
* In non-orthogonal coordinate systems (`coord_sf()`, `coord_polar()` and
12+
`coord_radial()`), using 'AsIs' variables escape transformation when
13+
both `x` and `y` is an 'AsIs' variable (@teunbrand, #6205).
14+
* The following methods have been deprecated: `fortify.lm()`, `fortify.glht()`,
15+
`fortify.confint.glht()`, `fortify.summary.glht()` and `fortify.cld()`. It
16+
is recommend to use `broom::augment()` and `broom::tidy()` instead
17+
(@teunbrand, #3816).
18+
* Custom and raster annotation now respond to scale transformations, and can
19+
use AsIs variables for relative placement (@teunbrand based on
20+
@yutannihilation's prior work, #3120)
21+
* When discrete breaks have names, they'll be used as labels by default
22+
(@teunbrand, #6147).
23+
* The helper function `is.waiver()` is now exported to help extensions to work
24+
with `waiver()` objects (@arcresu, #6173).
25+
* Date(time) scales now throw appropriate errors when `date_breaks`,
26+
`date_minor_breaks` or `date_labels` are not strings (@RodDalBen, #5880)
27+
* `geom_errorbarh()` is deprecated in favour of
28+
`geom_errorbar(orientation = "y")` (@teunbrand, #5961).
29+
* `geom_contour()` should be able to recognise a rotated grid of points
30+
(@teunbrand, #4320)
31+
* `geom_boxplot()` gains additional arguments to style the colour, linetype and
32+
linewidths of the box, whiskers, median line and staples (@teunbrand, #5126)
633
* (internal) Using `after_scale()` in the `Geom*$default_aes()` field is now
734
evaluated in the context of data (@teunbrand, #6135)
835
* Fixed bug where binned scales wouldn't simultaneously accept transformations
@@ -192,6 +219,13 @@
192219
`labs()` and several guides (@teunbrand, #3196).
193220
* `stat_summary_bin()` no longer ignores `width` parameter (@teunbrand, #4647).
194221
* Added `keep.zeroes` argument to `stat_bin()` (@teunbrand, #3449)
222+
* `coord_sf()` no longer errors when dealing with empty graticules (@teunbrand, #6052)
223+
* Added `theme_transparent()` with transparent backgrounds (@topepo).
224+
* New theme elements `palette.{aes}.discrete` and `palette.{aes}.continuous`.
225+
Theme palettes replace palettes in scales where `palette = NULL`, which is
226+
the new default in many scales (@teunbrand, #4696).
227+
* `guide_axis()` no longer reserves space for blank ticks
228+
(@teunbrand, #4722, #6069).
195229

196230
# ggplot2 3.5.1
197231

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: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,3 +284,24 @@ check_coord_limits <- function(
284284
check_object(limits, is_vector, "a vector", arg = arg, call = call)
285285
check_length(limits, 2L, arg = arg, call = call)
286286
}
287+
288+
is_transform_immune <- function(data, coord_name) {
289+
x <- inherits(data$x, "AsIs")
290+
y <- inherits(data$y, "AsIs")
291+
if (!(x || y)) {
292+
# Neither variable is AsIs, so we need to transform
293+
return(FALSE)
294+
}
295+
if (x && y) {
296+
# Both variables are AsIs, so no need to transform
297+
return(TRUE)
298+
}
299+
# We're now in the `xor(x, y)` case
300+
var <- if (x) "x" else "y"
301+
alt <- if (x) "y" else "x"
302+
cli::cli_warn(
303+
"{.fn {coord_name}} cannot respect the {.cls AsIs} class of {.var {var}} \\
304+
when {.var {alt}} is not also {.cls AsIs}."
305+
)
306+
return(FALSE)
307+
}

R/coord-polar.R

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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)

R/coord-radial.R

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,10 @@ CoordRadial <- ggproto("CoordRadial", Coord,
275275
},
276276

277277
transform = function(self, data, panel_params) {
278+
if (is_transform_immune(data, snake_class(self))) {
279+
return(data)
280+
}
281+
278282
data <- rename_data(self, data)
279283
bbox <- panel_params$bbox %||% list(x = c(0, 1), y = c(0, 1))
280284
arc <- panel_params$arc %||% c(0, 2 * pi)

R/coord-sf.R

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,10 @@ CoordSf <- ggproto("CoordSf", CoordCartesian,
7777
},
7878

7979
transform = function(self, data, panel_params) {
80+
if (is_transform_immune(data, snake_class(self))) {
81+
return(data)
82+
}
83+
8084
# we need to transform all non-sf data into the correct coordinate system
8185
source_crs <- panel_params$default_crs
8286
target_crs <- panel_params$crs
@@ -108,7 +112,7 @@ CoordSf <- ggproto("CoordSf", CoordCartesian,
108112
x_breaks <- graticule$degree[graticule$type == "E"]
109113
if (is.null(scale_x$labels)) {
110114
x_labels <- rep(NA, length(x_breaks))
111-
} else if (is.waive(scale_x$labels)) {
115+
} else if (is.waiver(scale_x$labels)) {
112116
x_labels <- graticule$degree_label[graticule$type == "E"]
113117
needs_autoparsing[graticule$type == "E"] <- TRUE
114118
} else {
@@ -133,7 +137,7 @@ CoordSf <- ggproto("CoordSf", CoordCartesian,
133137
y_breaks <- graticule$degree[graticule$type == "N"]
134138
if (is.null(scale_y$labels)) {
135139
y_labels <- rep(NA, length(y_breaks))
136-
} else if (is.waive(scale_y$labels)) {
140+
} else if (is.waiver(scale_y$labels)) {
137141
y_labels <- graticule$degree_label[graticule$type == "N"]
138142
needs_autoparsing[graticule$type == "N"] <- TRUE
139143
} else {
@@ -534,7 +538,7 @@ coord_sf <- function(xlim = NULL, ylim = NULL, expand = TRUE,
534538
label_axes = waiver(), lims_method = "cross",
535539
ndiscr = 100, default = FALSE, clip = "on") {
536540

537-
if (is.waive(label_graticule) && is.waive(label_axes)) {
541+
if (is.waiver(label_graticule) && is.waiver(label_axes)) {
538542
# if both `label_graticule` and `label_axes` are set to waive then we
539543
# use the default of labels on the left and at the bottom
540544
label_graticule <- ""
@@ -620,13 +624,13 @@ sf_breaks <- function(scale_x, scale_y, bbox, crs) {
620624
bbox[is.na(bbox)] <- c(-180, -90, 180, 90)[is.na(bbox)]
621625
}
622626

623-
if (!(is.waive(scale_x$breaks) && is.null(scale_x$n.breaks))) {
627+
if (!(is.waiver(scale_x$breaks) && is.null(scale_x$n.breaks))) {
624628
x_breaks <- scale_x$get_breaks(limits = bbox[c(1, 3)])
625629
finite <- is.finite(x_breaks)
626630
x_breaks <- if (any(finite)) x_breaks[finite] else NULL
627631
}
628632

629-
if (!(is.waive(scale_y$breaks) && is.null(scale_y$n.breaks))) {
633+
if (!(is.waiver(scale_y$breaks) && is.null(scale_y$n.breaks))) {
630634
y_breaks <- scale_y$get_breaks(limits = bbox[c(2, 4)])
631635
finite <- is.finite(y_breaks)
632636
y_breaks <- if (any(finite)) y_breaks[finite] else NULL
@@ -657,6 +661,9 @@ sf_breaks <- function(scale_x, scale_y, bbox, crs) {
657661
#' @keywords internal
658662
view_scales_from_graticule <- function(graticule, scale, aesthetic,
659663
label, label_graticule, bbox) {
664+
if (empty(graticule)) {
665+
return(ggproto(NULL, ViewScale))
666+
}
660667

661668
# Setup position specific parameters
662669
# Note that top/bottom doesn't necessarily mean to label the meridians and

0 commit comments

Comments
 (0)