Skip to content

Commit 4fbf5cf

Browse files
committed
resolve merge conflict
Merge branch 'main' into S7_elements # Conflicts: # R/geom-label.R # R/guide-.R # R/margins.R # R/theme-elements.R # R/theme.R # man/is_tests.Rd # tests/testthat/test-theme.R
2 parents b2f143e + 89b8f4d commit 4fbf5cf

Some content is hidden

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

60 files changed

+1379
-23655
lines changed

DESCRIPTION

Lines changed: 5 additions & 5 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,7 +31,7 @@ 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,
@@ -71,9 +71,9 @@ Suggests:
7171
tibble,
7272
vdiffr (>= 1.0.6),
7373
xml2
74-
Enhances:
74+
Enhances:
7575
sp
76-
VignetteBuilder:
76+
VignetteBuilder:
7777
knitr
7878
Config/Needs/website: ggtext, tidyr, forcats, tidyverse/tidytemplate
7979
Config/testthat/edition: 3
@@ -82,7 +82,7 @@ Encoding: UTF-8
8282
LazyData: true
8383
Roxygen: list(markdown = TRUE)
8484
RoxygenNote: 7.3.2
85-
Collate:
85+
Collate:
8686
'ggproto.R'
8787
'ggplot-global.R'
8888
'aaa-.R'

NAMESPACE

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ S3method(predictdf,default)
9898
S3method(predictdf,glm)
9999
S3method(predictdf,locfit)
100100
S3method(predictdf,loess)
101+
S3method(print,element)
101102
S3method(print,ggplot)
102103
S3method(print,ggplot2_bins)
103104
S3method(print,ggproto)
@@ -460,22 +461,26 @@ export(guide_transform)
460461
export(guides)
461462
export(has_flipped_aes)
462463
export(is.Coord)
463-
export(is.coord)
464464
export(is.facet)
465-
export(is.geom)
466465
export(is.ggplot)
467466
export(is.ggproto)
468-
export(is.guide)
469-
export(is.guides)
470-
export(is.layer)
471-
export(is.mapping)
472-
export(is.margin)
473-
export(is.position)
474-
export(is.scale)
475-
export(is.stat)
476467
export(is.theme)
477-
export(is.theme_element)
478468
export(is.waiver)
469+
export(is_coord)
470+
export(is_facet)
471+
export(is_geom)
472+
export(is_ggplot)
473+
export(is_ggproto)
474+
export(is_guide)
475+
export(is_guides)
476+
export(is_layer)
477+
export(is_mapping)
478+
export(is_margin)
479+
export(is_position)
480+
export(is_scale)
481+
export(is_stat)
482+
export(is_theme)
483+
export(is_theme_element)
479484
export(label_both)
480485
export(label_bquote)
481486
export(label_context)

NEWS.md

Lines changed: 841 additions & 826 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: 20 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.
@@ -90,6 +94,7 @@ Facet <- ggproto("Facet", NULL,
9094
map_data = function(data, layout, params) {
9195
cli::cli_abort("Not implemented.")
9296
},
97+
setup_panel_params = function(self, panel_params, coord, ...) panel_params,
9398
init_scales = function(layout, x_scale = NULL, y_scale = NULL, params) {
9499
scales <- list()
95100
if (!is.null(x_scale)) {
@@ -313,10 +318,6 @@ Facet <- ggproto("Facet", NULL,
313318
}
314319
)
315320

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

322323
#' Quote faceting variables
@@ -378,6 +379,18 @@ vars <- function(...) {
378379
quos(...)
379380
}
380381

382+
#' @export
383+
#' @rdname is_tests
384+
is_facet <- function(x) inherits(x, "Facet")
385+
386+
#' @export
387+
#' @rdname is_tests
388+
#' @usage is.facet(x) # Deprecated
389+
is.facet <- function(x) {
390+
deprecate_soft0("3.5.2", "is.facet()", "is_facet()")
391+
is_facet(x)
392+
}
393+
381394
#' Accessing a plot's facet strip labels
382395
#'
383396
#' This functions retrieves labels from facet strips with the labeller applied.
@@ -488,7 +501,7 @@ as_facets_list <- function(x) {
488501
}
489502

490503
check_vars <- function(x) {
491-
if (is.mapping(x)) {
504+
if (is_mapping(x)) {
492505
cli::cli_abort("Please use {.fn vars} to supply facet variables.")
493506
}
494507
# 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?"

R/geom-.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ Geom <- ggproto("Geom",
237237

238238
#' @export
239239
#' @rdname is_tests
240-
is.geom <- function(x) inherits(x, "Geom")
240+
is_geom <- function(x) inherits(x, "Geom")
241241

242242
eval_from_theme <- function(aesthetics, theme, class = NULL) {
243243
themed <- is_themed_aes(aesthetics)

R/geom-defaults.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ get_geom_defaults <- function(geom, theme = theme_get()) {
9999
if (is.function(geom)) {
100100
geom <- geom()
101101
}
102-
if (is.layer(geom)) {
102+
if (is_layer(geom)) {
103103
data <- data_frame0(.id = 1L)
104104
data <- geom$compute_geom_2(data = data, theme = theme)
105105
data$.id <- NULL
@@ -108,7 +108,7 @@ get_geom_defaults <- function(geom, theme = theme_get()) {
108108
if (is.character(geom)) {
109109
geom <- validate_subclass(geom, "Geom")
110110
}
111-
if (is.geom(geom)) {
111+
if (is_geom(geom)) {
112112
out <- geom$use_defaults(data = NULL, theme = theme)
113113
return(out)
114114
}

R/geom-label.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ GeomLabel <- ggproto("GeomLabel", Geom,
8888
data <- coord$transform(data, panel_params)
8989
data$vjust <- compute_just(data$vjust, data$y, data$x, data$angle)
9090
data$hjust <- compute_just(data$hjust, data$x, data$y, data$angle)
91-
if (!is.margin(label.padding)) {
91+
if (!is_margin(label.padding)) {
9292
label.padding <- rep(label.padding, length.out = 4)
9393
}
9494

0 commit comments

Comments
 (0)