Skip to content

Commit ec299fc

Browse files
authored
Merge branch 'main' into ordered_vec_rbind0
2 parents ad40491 + 020c9eb commit ec299fc

20 files changed

+179
-59
lines changed

NAMESPACE

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -582,6 +582,8 @@ export(scale_linewidth_continuous)
582582
export(scale_linewidth_date)
583583
export(scale_linewidth_datetime)
584584
export(scale_linewidth_discrete)
585+
export(scale_linewidth_identity)
586+
export(scale_linewidth_manual)
585587
export(scale_linewidth_ordinal)
586588
export(scale_radius)
587589
export(scale_shape)

NEWS.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,20 @@
33
* Using two ordered factors as facetting variables in
44
`facet_grid(..., as.table = FALSE)` now throws a warning instead of an
55
error (@teunbrand, #5109).
6+
* Added `scale_linewidth_manual()` and `scale_linewidth_identity()` to support
7+
the `linewidth` aesthetic (@teunbrand, #5050).
8+
* Automatic breaks in `scale_*_binned()` should no longer be out-of-bounds,
9+
and automatic limits expand to include these (@teunbrand, #5095, #5100).
10+
* Renamed computed aesthetic in `stat_ecdf()` to `ecdf`, to prevent incorrect
11+
scale transformations (@teunbrand, #5113 and #5112).
12+
* Fixed misbehaviour of `draw_key_boxplot()` and `draw_key_crossbar()` with
13+
skewed key aspect ratio (@teunbrand, #5082).
614
* `scale_*_binned()` handles zero-range limits more gracefully (@teunbrand,
715
#5066)
816
* Binned scales are now compatible with `trans = "date"` and `trans = "time"`
917
(@teunbrand, #4217).
1018
* `ggsave()` warns when multiple `filename`s are given, and only writes to the
11-
first file (@teunbrand, #5114).
19+
first file (@teunbrand, #5114)
1220
* Fixed a regression in `geom_hex()` where aesthetics were replicated across
1321
bins (@thomasp85, #5037 and #5044)
1422
* Fixed spurious warning when `weight` aesthetic was used in `stat_smooth()`

R/geom-ribbon.r

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@
1010
#' whole varies over the range of x. Choosing the order in which different
1111
#' components is stacked is very important, as it becomes increasing hard to
1212
#' see the individual pattern as you move up the stack. See
13-
#' [position_stack()] for the details of stacking algorithm.
13+
#' [position_stack()] for the details of stacking algorithm. To facilitate
14+
#' stacking, the default `stat = "align"` interpolates groups to a common set
15+
#' of x-coordinates. To turn off this interpolation, `stat = "identity"` can
16+
#' be used instead.
1417
#'
1518
#' @eval rd_orientation()
1619
#'
@@ -57,6 +60,10 @@
5760
#' # stat_align() interpolates and aligns the value so that the areas can stack
5861
#' # properly.
5962
#' a + geom_point(stat = "align", position = "stack", size = 8)
63+
#'
64+
#' # To turn off the alignment, the stat can be set to "identity"
65+
#' ggplot(df, aes(x, y, fill = g)) +
66+
#' geom_area(stat = "identity")
6067
geom_ribbon <- function(mapping = NULL, data = NULL,
6168
stat = "identity", position = "identity",
6269
...,

R/legend-draw.r

Lines changed: 45 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -98,39 +98,58 @@ draw_key_blank <- function(data, params, size) {
9898
#' @export
9999
#' @rdname draw_key
100100
draw_key_boxplot <- function(data, params, size) {
101-
grobTree(
102-
linesGrob(0.5, c(0.1, 0.25)),
103-
linesGrob(0.5, c(0.75, 0.9)),
104-
rectGrob(height = 0.5, width = 0.75),
105-
linesGrob(c(0.125, 0.875), 0.5),
106-
gp = gpar(
107-
col = data$colour %||% "grey20",
108-
fill = alpha(data$fill %||% "white", data$alpha),
109-
lwd = (data$linewidth %||% 0.5) * .pt,
110-
lty = data$linetype %||% 1,
111-
lineend = params$lineend %||% "butt",
112-
linejoin = params$linejoin %||% "mitre"
113-
),
114-
vp = if (isTRUE(params$flipped_aes)) viewport(angle = -90)
101+
gp <- gpar(
102+
col = data$colour %||% "grey20",
103+
fill = alpha(data$fill %||% "white", data$alpha),
104+
lwd = (data$linewidth %||% 0.5) * .pt,
105+
lty = data$linetype %||% 1,
106+
lineend = params$lineend %||% "butt",
107+
linejoin = params$linejoin %||% "mitre"
115108
)
109+
110+
if (isTRUE(params$flipped_aes)) {
111+
grobTree(
112+
linesGrob(c(0.1, 0.25), 0.5),
113+
linesGrob(c(0.75, 0.9), 0.5),
114+
rectGrob(width = 0.5, height = 0.75),
115+
linesGrob(0.5, c(0.125, 0.875)),
116+
gp = gp
117+
)
118+
} else {
119+
grobTree(
120+
linesGrob(0.5, c(0.1, 0.25)),
121+
linesGrob(0.5, c(0.75, 0.9)),
122+
rectGrob(height = 0.5, width = 0.75),
123+
linesGrob(c(0.125, 0.875), 0.5),
124+
gp = gp
125+
)
126+
}
116127
}
117128

118129
#' @export
119130
#' @rdname draw_key
120131
draw_key_crossbar <- function(data, params, size) {
121-
grobTree(
122-
rectGrob(height = 0.5, width = 0.75),
123-
linesGrob(c(0.125, 0.875), 0.5),
124-
gp = gpar(
125-
col = data$colour %||% "grey20",
126-
fill = alpha(data$fill %||% "white", data$alpha),
127-
lwd = (data$linewidth %||% 0.5) * .pt,
128-
lty = data$linetype %||% 1,
129-
lineend = params$lineend %||% "butt",
130-
linejoin = params$linejoin %||% "mitre"
131-
),
132-
vp = if (isTRUE(params$flipped_aes)) viewport(angle = -90)
132+
gp <- gpar(
133+
col = data$colour %||% "grey20",
134+
fill = alpha(data$fill %||% "white", data$alpha),
135+
lwd = (data$linewidth %||% 0.5) * .pt,
136+
lty = data$linetype %||% 1,
137+
lineend = params$lineend %||% "butt",
138+
linejoin = params$linejoin %||% "mitre"
133139
)
140+
if (isTRUE(params$flipped_aes)) {
141+
grobTree(
142+
rectGrob(height = 0.75, width = 0.5),
143+
linesGrob(0.5, c(0.125, 0.875)),
144+
gp = gp
145+
)
146+
} else {
147+
grobTree(
148+
rectGrob(height = 0.5, width = 0.75),
149+
linesGrob(c(0.125, 0.875), 0.5),
150+
gp = gp
151+
)
152+
}
134153
}
135154

136155
#' @export

R/scale-.r

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,8 +237,11 @@ discrete_scale <- function(aesthetics, scale_name, palette, name = waiver(),
237237
#' the scale will ask the transformation object to create breaks, and this
238238
#' may result in a different number of breaks than requested. Ignored if
239239
#' breaks are given explicitly.
240-
#' @param right Should values on the border between bins be part of the right
241-
#' (upper) bin?
240+
#' @param right Should the intervals be closed on the right (`TRUE`, default) or
241+
#' should the intervals be closed on the left (`FALSE`)? 'Closed on the right'
242+
#' means that values at break positions are part of the lower bin (open on the
243+
#' left), whereas they are part of the upper bin when intervals are closed on
244+
#' the left (open on the right).
242245
#' @param show.limits should the limits of the scale appear as ticks
243246
#' @keywords internal
244247
binned_scale <- function(aesthetics, scale_name, palette, name = waiver(),
@@ -1077,6 +1080,7 @@ ScaleBinned <- ggproto("ScaleBinned", Scale,
10771080
breaks <- seq(limits[1], limits[2], length.out = n.breaks + 2)
10781081
breaks <- breaks[-c(1, length(breaks))]
10791082
}
1083+
breaks <- oob_discard(breaks, limits)
10801084

10811085
# Ensure terminal bins are same width if limits not set
10821086
if (is.null(self$limits)) {

R/scale-binned.R

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ ScaleBinnedPosition <- ggproto("ScaleBinnedPosition", ScaleBinned,
7070

7171
map = function(self, x, limits = self$get_limits()) {
7272
breaks <- self$get_breaks(limits)
73+
limits <- self$get_limits() # get_breaks() may have updated this
7374
all_breaks <- unique0(sort(c(limits[1], breaks, limits[2])))
7475

7576
if (self$after.stat) {

R/scale-identity.r

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,15 @@ scale_linetype_identity <- function(..., guide = "none") {
9595
sc
9696
}
9797

98+
#' @rdname scale_identity
99+
#' @export
100+
scale_linewidth_identity <- function(..., guide = "none") {
101+
sc <- continuous_scale("linewidth", "identity", identity_pal(), ...,
102+
guide = guide, super = ScaleContinuousIdentity)
103+
104+
sc
105+
}
106+
98107
#' @rdname scale_identity
99108
#' @export
100109
scale_alpha_identity <- function(..., guide = "none") {

R/scale-manual.r

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,12 @@ scale_linetype_manual <- function(..., values, breaks = waiver(), na.value = "bl
110110
manual_scale("linetype", values, breaks, ..., na.value = na.value)
111111
}
112112

113+
#' @rdname scale_manual
114+
#' @export
115+
scale_linewidth_manual <- function(..., values, breaks = waiver(), na.value = NA) {
116+
manual_scale("linewidth", values, breaks, ..., na.value = na.value)
117+
}
118+
113119
#' @rdname scale_manual
114120
#' @export
115121
scale_alpha_manual <- function(..., values, breaks = waiver(), na.value = NA) {
@@ -122,7 +128,6 @@ scale_discrete_manual <- function(aesthetics, ..., values, breaks = waiver()) {
122128
manual_scale(aesthetics, values, breaks, ...)
123129
}
124130

125-
126131
manual_scale <- function(aesthetic, values = NULL, breaks = waiver(), ..., limits = NULL) {
127132
# check for missing `values` parameter, in lieu of providing
128133
# a default to all the different scale_*_manual() functions

R/stat-bin.r

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -123,9 +123,6 @@ StatBin <- ggproto("StatBin", Stat,
123123
params$closed <- if (params$right) "right" else "left"
124124
params$right <- NULL
125125
}
126-
if (!is.null(params$width)) {
127-
deprecate_warn0("2.1.0", "stat_bin(width)", "geom_bar()")
128-
}
129126
if (!is.null(params$boundary) && !is.null(params$center)) {
130127
cli::cli_abort("Only one of {.arg boundary} and {.arg center} may be specified in {.fn {snake_class(self)}}.")
131128
}
@@ -146,8 +143,7 @@ StatBin <- ggproto("StatBin", Stat,
146143
breaks = NULL, flipped_aes = FALSE,
147144
# The following arguments are not used, but must
148145
# be listed so parameters are computed correctly
149-
origin = NULL, right = NULL, drop = NULL,
150-
width = NULL) {
146+
origin = NULL, right = NULL, drop = NULL) {
151147
x <- flipped_names(flipped_aes)$x
152148
if (!is.null(breaks)) {
153149
if (!scales[[x]]$is_discrete()) {

R/stat-ecdf.r

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
#' @param pad If `TRUE`, pad the ecdf with additional points (-Inf, 0)
2222
#' and (Inf, 1)
2323
#' @eval rd_computed_vars(
24-
#' y = "Cumulative density corresponding to `x`."
24+
#' ecdf = "Cumulative density corresponding to `x`."
2525
#' )
2626
#' @export
2727
#' @examples
@@ -73,7 +73,7 @@ stat_ecdf <- function(mapping = NULL, data = NULL,
7373
StatEcdf <- ggproto("StatEcdf", Stat,
7474
required_aes = c("x|y"),
7575

76-
default_aes = aes(y = after_stat(y)),
76+
default_aes = aes(x = after_stat(ecdf), y = after_stat(ecdf)),
7777

7878
setup_params = function(self, data, params) {
7979
params$flipped_aes <- has_flipped_aes(data, params, main_is_orthogonal = FALSE, main_is_continuous = TRUE)
@@ -103,7 +103,7 @@ StatEcdf <- ggproto("StatEcdf", Stat,
103103

104104
df_ecdf <- data_frame0(
105105
x = x,
106-
y = data_ecdf,
106+
ecdf = data_ecdf,
107107
.size = length(x)
108108
)
109109
df_ecdf$flipped_aes <- flipped_aes

0 commit comments

Comments
 (0)