Skip to content

Commit a3c6ad5

Browse files
committed
Merge branch 'main' into topepo-main
2 parents fbe4a5e + 4193a50 commit a3c6ad5

26 files changed

+388
-290
lines changed

DESCRIPTION

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

NAMESPACE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ export(GeomAbline)
172172
export(GeomAnnotationMap)
173173
export(GeomArea)
174174
export(GeomBar)
175+
export(GeomBin2d)
175176
export(GeomBlank)
176177
export(GeomBoxplot)
177178
export(GeomCol)

NEWS.md

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

3+
* In non-orthogonal coordinate systems (`coord_sf()`, `coord_polar()` and
4+
`coord_radial()`), using 'AsIs' variables escape transformation when
5+
both `x` and `y` is an 'AsIs' variable (@teunbrand, #6205).
6+
* The following methods have been deprecated: `fortify.lm()`, `fortify.glht()`,
7+
`fortify.confint.glht()`, `fortify.summary.glht()` and `fortify.cld()`. It
8+
is recommend to use `broom::augment()` and `broom::tidy()` instead
9+
(@teunbrand, #3816).
10+
* Custom and raster annotation now respond to scale transformations, and can
11+
use AsIs variables for relative placement (@teunbrand based on
12+
@yutannihilation's prior work, #3120)
313
* When discrete breaks have names, they'll be used as labels by default
414
(@teunbrand, #6147).
515
* The helper function `is.waiver()` is now exported to help extensions to work

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/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: 4 additions & 0 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

R/fortify-lm.R

Lines changed: 0 additions & 87 deletions
This file was deleted.

0 commit comments

Comments
 (0)