Skip to content

Commit 7625aa2

Browse files
committed
resolve merge conflict
Merge branch 'main' into boilerplates # Conflicts: # man/is_tests.Rd
2 parents f7652fe + 295f5cb commit 7625aa2

Some content is hidden

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

78 files changed

+1727
-23968
lines changed

DESCRIPTION

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: ggplot2
22
Title: Create Elegant Data Visualisations Using the Grammar of Graphics
3-
Version: 3.5.1.9000
3+
Version: 3.5.2.9000
44
Authors@R: c(
55
person("Hadley", "Wickham", , "[email protected]", role = "aut",
66
comment = c(ORCID = "0000-0003-4757-117X")),
@@ -31,15 +31,15 @@ URL: https://ggplot2.tidyverse.org, https://github.com/tidyverse/ggplot2
3131
BugReports: https://github.com/tidyverse/ggplot2/issues
3232
Depends:
3333
R (>= 4.0)
34-
Imports:
34+
Imports:
3535
cli,
3636
grDevices,
3737
grid,
3838
gtable (>= 0.3.6),
3939
isoband,
4040
lifecycle (> 1.0.1),
4141
rlang (>= 1.1.0),
42-
scales (>= 1.3.0),
42+
scales (>= 1.4.0),
4343
stats,
4444
vctrs (>= 0.6.0),
4545
withr (>= 2.5.0)
@@ -70,9 +70,9 @@ Suggests:
7070
tibble,
7171
vdiffr (>= 1.0.6),
7272
xml2
73-
Enhances:
73+
Enhances:
7474
sp
75-
VignetteBuilder:
75+
VignetteBuilder:
7676
knitr
7777
Config/Needs/website: ggtext, tidyr, forcats, tidyverse/tidytemplate
7878
Config/testthat/edition: 3
@@ -81,7 +81,7 @@ Encoding: UTF-8
8181
LazyData: true
8282
Roxygen: list(markdown = TRUE)
8383
RoxygenNote: 7.3.2
84-
Collate:
84+
Collate:
8585
'ggproto.R'
8686
'ggplot-global.R'
8787
'aaa-.R'

NAMESPACE

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -472,22 +472,26 @@ export(guide_transform)
472472
export(guides)
473473
export(has_flipped_aes)
474474
export(is.Coord)
475-
export(is.coord)
476475
export(is.facet)
477-
export(is.geom)
478476
export(is.ggplot)
479477
export(is.ggproto)
480-
export(is.guide)
481-
export(is.guides)
482-
export(is.layer)
483-
export(is.mapping)
484-
export(is.margin)
485-
export(is.position)
486-
export(is.scale)
487-
export(is.stat)
488478
export(is.theme)
489-
export(is.theme_element)
490479
export(is.waiver)
480+
export(is_coord)
481+
export(is_facet)
482+
export(is_geom)
483+
export(is_ggplot)
484+
export(is_ggproto)
485+
export(is_guide)
486+
export(is_guides)
487+
export(is_layer)
488+
export(is_mapping)
489+
export(is_margin)
490+
export(is_position)
491+
export(is_scale)
492+
export(is_stat)
493+
export(is_theme)
494+
export(is_theme_element)
491495
export(label_both)
492496
export(label_bquote)
493497
export(label_context)

NEWS.md

Lines changed: 845 additions & 824 deletions
Large diffs are not rendered by default.

R/aes.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ aes <- function(x, y, ...) {
111111

112112
#' @export
113113
#' @rdname is_tests
114-
is.mapping <- function(x) inherits(x, "uneval")
114+
is_mapping <- function(x) inherits(x, "uneval")
115115

116116
# Wrap symbolic objects in quosures but pull out constants out of
117117
# quosures for backward-compatibility

R/bin.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,15 +120,15 @@ compute_bins <- function(x, scale = NULL, breaks = NULL, binwidth = NULL, bins =
120120
center = NULL, boundary = NULL,
121121
closed = c("right", "left")) {
122122

123-
range <- if (is.scale(scale)) scale$dimension() else range(x)
123+
range <- if (is_scale(scale)) scale$dimension() else range(x)
124124
check_length(range, 2L)
125125

126126
if (!is.null(breaks)) {
127127
breaks <- allow_lambda(breaks)
128128
if (is.function(breaks)) {
129129
breaks <- breaks(x)
130130
}
131-
if (is.scale(scale) && !scale$is_discrete()) {
131+
if (is_scale(scale) && !scale$is_discrete()) {
132132
breaks <- scale$transform(breaks)
133133
}
134134
check_numeric(breaks)

R/coord-.R

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -225,17 +225,16 @@ Coord <- ggproto("Coord",
225225
}
226226
)
227227

228-
229228
#' @export
230229
#' @rdname is_tests
231-
is.coord <- function(x) inherits(x, "Coord")
230+
is_coord <- function(x) inherits(x, "Coord")
232231

233232
#' @export
234233
#' @rdname is_tests
235234
#' @usage is.Coord(x) # Deprecated
236235
is.Coord <- function(x) {
237-
deprecate_soft0("3.5.2", "is.Coord()", "is.coord()")
238-
is.coord(x)
236+
deprecate_soft0("3.5.2", "is.Coord()", "is_coord()")
237+
is_coord(x)
239238
}
240239

241240
# Renders an axis with the correct orientation or zeroGrob if no axis should be

R/coord-cartesian-.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ view_scales_from_scale <- function(scale, coord_limits = NULL, expand = TRUE) {
165165
}
166166

167167
panel_guides_grob <- function(guides, position, theme, labels = NULL) {
168-
if (!is.guides(guides)) {
168+
if (!is_guides(guides)) {
169169
return(zeroGrob())
170170
}
171171
pair <- guides$get_position(position)

R/coord-radial.R

Lines changed: 49 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#' @param end Position from 12 o'clock in radians where plot ends, to allow
55
#' for partial polar coordinates. The default, `NULL`, is set to
66
#' `start + 2 * pi`.
7+
#' @param thetalim,rlim Limits for the theta and r axes.
78
#' @param expand If `TRUE`, the default, adds a small expansion factor to
89
#' the limits to prevent overlap between data and axes. If `FALSE`, limits
910
#' are taken directly from the scale.
@@ -40,9 +41,19 @@
4041
#' ggplot(mtcars, aes(disp, mpg)) +
4142
#' geom_point() +
4243
#' coord_radial(start = -0.4 * pi, end = 0.4 * pi, inner.radius = 0.3)
44+
#'
45+
#' # Similar with coord_cartesian(), you can set limits.
46+
#' ggplot(mtcars, aes(disp, mpg)) +
47+
#' geom_point() +
48+
#' coord_radial(
49+
#' start = -0.4 * pi,
50+
#' end = 0.4 * pi, inner.radius = 0.3,
51+
#' thetalim = c(200, 300),
52+
#' rlim = c(15, 30),
53+
#' )
4354
coord_radial <- function(theta = "x",
4455
start = 0, end = NULL,
45-
expand = TRUE,
56+
thetalim = NULL, rlim = NULL, expand = TRUE,
4657
direction = deprecated(),
4758
clip = "off",
4859
r.axis.inside = NULL,
@@ -91,11 +102,22 @@ coord_radial <- function(theta = "x",
91102
arc <- switch(reverse, thetar = , theta = rev(arc), arc)
92103

93104
r.axis.inside <- r.axis.inside %||% !(abs(arc[2] - arc[1]) >= 1.999 * pi)
105+
if (isFALSE(r.axis.inside)) {
106+
place <- in_arc(c(0, 0.5, 1, 1.5) * pi, arc)
107+
if (!any(place)) {
108+
cli::cli_warn(c(
109+
"No appropriate placement found for outside {.field r.axis}.",
110+
i = "Will use {.code r.axis.inside = TRUE} instead"
111+
))
112+
r.axis.inside <- TRUE
113+
}
114+
}
94115

95116
inner.radius <- c(inner.radius, 1) * 0.4
96117
inner.radius <- switch(reverse, thetar = , r = rev, identity)(inner.radius)
97118

98119
ggproto(NULL, CoordRadial,
120+
limits = list(theta = thetalim, r = rlim),
99121
theta = theta,
100122
r = r,
101123
arc = arc,
@@ -147,10 +169,20 @@ CoordRadial <- ggproto("CoordRadial", Coord,
147169
},
148170

149171
setup_panel_params = function(self, scale_x, scale_y, params = list()) {
150-
172+
if (self$theta == "x") {
173+
xlimits <- self$limits$theta
174+
ylimits <- self$limits$r
175+
} else {
176+
xlimits <- self$limits$r
177+
ylimits <- self$limits$theta
178+
}
151179
params <- c(
152-
view_scales_polar(scale_x, self$theta, expand = params$expand[c(4, 2)]),
153-
view_scales_polar(scale_y, self$theta, expand = params$expand[c(3, 1)]),
180+
view_scales_polar(scale_x, self$theta, xlimits,
181+
expand = params$expand[c(4, 2)]
182+
),
183+
view_scales_polar(scale_y, self$theta, ylimits,
184+
expand = params$expand[c(3, 1)]
185+
),
154186
list(bbox = polar_bbox(self$arc, inner_radius = self$inner_radius),
155187
arc = self$arc, inner_radius = self$inner_radius)
156188
)
@@ -431,38 +463,31 @@ CoordRadial <- ggproto("CoordRadial", Coord,
431463

432464
setup_params = function(self, data) {
433465
params <- ggproto_parent(Coord, self)$setup_params(data)
434-
if (!isFALSE(self$r_axis_inside)) {
435-
return(params)
436-
}
437-
438-
place <- in_arc(c(0, 0.5, 1, 1.5) * pi, self$arc)
439-
if (!any(place)) {
440-
cli::cli_warn(c(
441-
"No appropriate placement found for {.arg r_axis_inside}.",
442-
i = "Axis will be placed at panel edge."
443-
))
444-
params$r_axis_inside <- TRUE
445-
return(params)
466+
if (isFALSE(self$r_axis_inside)) {
467+
place <- in_arc(c(0, 0.5, 1, 1.5) * pi, self$arc)
468+
params$r_axis <- if (any(place[c(1, 3)])) "left" else "bottom"
469+
params$fake_arc <- switch(
470+
which(place[c(1, 3, 2, 4)])[1],
471+
c(0, 2), c(1, 3), c(0.5, 2.5), c(1.5, 3.5)
472+
) * pi
446473
}
447-
448-
params$r_axis <- if (any(place[c(1, 3)])) "left" else "bottom"
449-
params$fake_arc <- switch(
450-
which(place[c(1, 3, 2, 4)])[1],
451-
c(0, 2), c(1, 3), c(0.5, 2.5), c(1.5, 3.5)
452-
) * pi
453474
params
454475
}
455476
)
456477

457-
view_scales_polar <- function(scale, theta = "x", expand = TRUE) {
478+
view_scales_polar <- function(scale, theta = "x", coord_limits = NULL,
479+
expand = TRUE) {
458480

459481
aesthetic <- scale$aesthetics[1]
460482
is_theta <- theta == aesthetic
461483
name <- if (is_theta) "theta" else "r"
462484

463485
expansion <- default_expansion(scale, expand = expand)
464486
limits <- scale$get_limits()
465-
continuous_range <- expand_limits_scale(scale, expansion, limits)
487+
continuous_range <- expand_limits_scale(
488+
scale, expansion, limits,
489+
coord_limits
490+
)
466491

467492
primary <- view_scale_primary(scale, limits, continuous_range)
468493
view_scales <- list(

R/facet-.R

Lines changed: 52 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ NULL
99
#' rendered.
1010
#'
1111
#' Extending facets can range from the simple modifications of current facets,
12-
#' to very laborious rewrites with a lot of [gtable()] manipulation.
13-
#' For some examples of both, please see the extension vignette.
12+
#' to very laborious rewrites with a lot of [`gtable()`][gtable::gtable()]
13+
#' manipulation. For some examples of both, please see the extension vignette.
1414
#'
1515
#' `Facet` subclasses, like other extendible ggproto classes, have a range
1616
#' of methods that can be modified. Some of these are required for all new
@@ -46,6 +46,10 @@ NULL
4646
#' the default behaviour of one or more of the following methods:
4747
#'
4848
#' - `setup_params`:
49+
#'
50+
#' - `setup_panel_params`: modifies the x and y ranges for each panel. This is
51+
#' used to allow the `Facet` to interact with the `panel_params`.
52+
#'
4953
#' - `init_scales`: Given a master scale for x and y, create panel
5054
#' specific scales for each panel defined in the layout. The default is to
5155
#' simply clone the master scale.
@@ -64,6 +68,10 @@ NULL
6468
#' between the layer stack and the foreground defined by the Coord object
6569
#' (usually empty). The default is, as above, to return an empty grob.
6670
#'
71+
#' - `draw_panel_content`: Draws each panel for the facet. Should return a list
72+
#' of grobs, one for each panel. The output is used by the `draw_panels`
73+
#' method.
74+
#'
6775
#' - `draw_labels`: Given the gtable returned by `draw_panels`,
6876
#' add axis titles to the gtable. The default is to add one title at each side
6977
#' depending on the position and existence of axes.
@@ -90,6 +98,7 @@ Facet <- ggproto("Facet", NULL,
9098
map_data = function(data, layout, params) {
9199
cli::cli_abort("Not implemented.")
92100
},
101+
setup_panel_params = function(self, panel_params, coord, ...) panel_params,
93102
init_scales = function(layout, x_scale = NULL, y_scale = NULL, params) {
94103
scales <- list()
95104
if (!is.null(x_scale)) {
@@ -133,6 +142,34 @@ Facet <- ggproto("Facet", NULL,
133142
draw_front = function(data, layout, x_scales, y_scales, theme, params) {
134143
rep(list(zeroGrob()), vec_unique_count(layout$PANEL))
135144
},
145+
draw_panel_content = function(self, panels, layout, x_scales, y_scales,
146+
ranges, coord, data, theme, params, ...) {
147+
facet_bg <- self$draw_back(
148+
data,
149+
layout,
150+
x_scales,
151+
y_scales,
152+
theme,
153+
params
154+
)
155+
facet_fg <- self$draw_front(
156+
data,
157+
layout,
158+
x_scales,
159+
y_scales,
160+
theme,
161+
params
162+
)
163+
164+
# Draw individual panels, then call `$draw_panels()` method to
165+
# assemble into gtable
166+
lapply(seq_along(panels[[1]]), function(i) {
167+
panel <- lapply(panels, `[[`, i)
168+
panel <- c(facet_bg[i], panel, facet_fg[i])
169+
panel <- coord$draw_panel(panel, ranges[[i]], theme)
170+
ggname(paste("panel", i, sep = "-"), panel)
171+
})
172+
},
136173
draw_panels = function(self, panels, layout, x_scales = NULL, y_scales = NULL,
137174
ranges, coord, data = NULL, theme, params) {
138175

@@ -313,10 +350,6 @@ Facet <- ggproto("Facet", NULL,
313350
}
314351
)
315352

316-
#' @export
317-
#' @rdname is_tests
318-
is.facet <- function(x) inherits(x, "Facet")
319-
320353
# Helpers -----------------------------------------------------------------
321354

322355
#' Quote faceting variables
@@ -378,6 +411,18 @@ vars <- function(...) {
378411
quos(...)
379412
}
380413

414+
#' @export
415+
#' @rdname is_tests
416+
is_facet <- function(x) inherits(x, "Facet")
417+
418+
#' @export
419+
#' @rdname is_tests
420+
#' @usage is.facet(x) # Deprecated
421+
is.facet <- function(x) {
422+
deprecate_soft0("3.5.2", "is.facet()", "is_facet()")
423+
is_facet(x)
424+
}
425+
381426
#' Accessing a plot's facet strip labels
382427
#'
383428
#' This functions retrieves labels from facet strips with the labeller applied.
@@ -488,7 +533,7 @@ as_facets_list <- function(x) {
488533
}
489534

490535
check_vars <- function(x) {
491-
if (is.mapping(x)) {
536+
if (is_mapping(x)) {
492537
cli::cli_abort("Please use {.fn vars} to supply facet variables.")
493538
}
494539
# Native pipe have higher precedence than + so any type of gg object can be

R/fortify.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ fortify.default <- function(model, data, ...) {
9494
"or an object coercible by {.fn fortify}, or a valid ",
9595
"{.cls data.frame}-like object coercible by {.fn as.data.frame}"
9696
)
97-
if (is.mapping(model)) {
97+
if (is_mapping(model)) {
9898
msg <- c(
9999
paste0(msg, ", not ", obj_type_friendly(model), "."),
100100
"i" = "Did you accidentally pass {.fn aes} to the {.arg data} argument?"

0 commit comments

Comments
 (0)