Skip to content

Commit 18e38a9

Browse files
authored
Merge branch 'main' into delayed_geom_defaults
2 parents 60f1516 + b174986 commit 18e38a9

15 files changed

+81
-13
lines changed

NAMESPACE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,6 @@ export(guides)
461461
export(has_flipped_aes)
462462
export(is.Coord)
463463
export(is.coord)
464-
export(is.element)
465464
export(is.facet)
466465
export(is.geom)
467466
export(is.ggplot)
@@ -475,6 +474,7 @@ export(is.position)
475474
export(is.scale)
476475
export(is.stat)
477476
export(is.theme)
477+
export(is.theme_element)
478478
export(label_both)
479479
export(label_bquote)
480480
export(label_context)

NEWS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
* (internal) Using `after_scale()` in the `Geom*$default_aes()` field is now
44
evaluated in the context of data (@teunbrand, #6135)
5+
* Fixed bug where binned scales wouldn't simultaneously accept transformations
6+
and function-limits (@teunbrand, #6144).
57
* Fixed bug where the `ggplot2::`-prefix did not work with `stage()`
68
(@teunbrand, #6104).
79
* New `get_labs()` function for retrieving completed plot labels

R/backports.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,6 @@ on_load({
6767
as.mask <- grid::as.mask
6868
}
6969
if ("linearGradient" %in% getNamespaceExports("grid")) {
70-
linearGradient <- grid::linearGradient()
70+
linearGradient <- grid::linearGradient
7171
}
7272
})

R/facet-.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,8 +237,8 @@ Facet <- ggproto("Facet", NULL,
237237
# Set panel names
238238
table$layout$name <- paste(
239239
"panel",
240-
rep(seq_len(dim[2]), dim[1]),
241-
rep(seq_len(dim[1]), each = dim[2]),
240+
rep(seq_len(dim[2]), each = dim[1]),
241+
rep(seq_len(dim[1]), dim[2]),
242242
sep = "-"
243243
)
244244

R/geom-defaults.R

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,17 @@
1111
#' @keywords internal
1212
#' @note
1313
#' Please note that geom defaults can be set *en masse* via the `theme(geom)`
14-
#' argument.
14+
#' argument. The guidelines for when to use which function are as follows:
15+
#'
16+
#' * If you want to change defaults for all geoms in all plots, use
17+
#' `theme_update(geom = element_geom(...))`.
18+
#' * If you want to change defaults for all geoms in a single plot, use
19+
#' `+ theme(geom = element_geom(...))`.
20+
#' * If you want to change defaults for one geom in all plots, use
21+
#' `update_geom_defaults()`.
22+
#' * If you want to change settings for one geom in a single plot, use fixed
23+
#' aesthetic parameters in a layer, like so: `geom_point(colour = "red")`.
24+
#'
1525
#' @export
1626
#' @examples
1727
#'

R/geom-histogram.R

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@
1717
#' one change at a time. You may need to look at a few options to uncover
1818
#' the full story behind your data.
1919
#'
20+
#' By default, the _height_ of the bars represent the counts within each bin.
21+
#' However, there are situations where this behavior might produce misleading
22+
#' plots (e.g., when non-equal-width bins are used), in which case it might be
23+
#' preferable to have the _area_ of the bars represent the counts (by setting
24+
#' `aes(y = after_stat(count / width))`). See example below.
25+
#'
2026
#' In addition to `geom_histogram()`, you can create a histogram plot by using
2127
#' `scale_x_binned()` with [geom_bar()]. This method by default plots tick marks
2228
#' in between each bar.
@@ -63,6 +69,18 @@
6369
#' ggplot(diamonds, aes(price, after_stat(density), colour = cut)) +
6470
#' geom_freqpoly(binwidth = 500)
6571
#'
72+
#'
73+
#' # When using the non-equal-width bins, we should set the area of the bars to
74+
#' # represent the counts (not the height).
75+
#' # Here we're using 10 equi-probable bins:
76+
#' price_bins <- quantile(diamonds$price, probs = seq(0, 1, length = 11))
77+
#'
78+
#' ggplot(diamonds, aes(price)) +
79+
#' geom_histogram(breaks = price_bins, color = "black") # misleading (height = count)
80+
#'
81+
#' ggplot(diamonds, aes(price, after_stat(count / width))) +
82+
#' geom_histogram(breaks = price_bins, color = "black") # area = count
83+
#'
6684
#' if (require("ggplot2movies")) {
6785
#' # Often we don't want the height of the bar to represent the
6886
#' # count of observations, but the sum of some other variable.

R/guide-.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ Guide <- ggproto(
381381
# Renders tickmarks
382382
build_ticks = function(key, elements, params, position = params$position,
383383
length = elements$ticks_length) {
384-
if (!is.element(elements)) {
384+
if (!is.theme_element(elements)) {
385385
elements <- elements$ticks
386386
}
387387
if (!inherits(elements, "element_line")) {

R/plot-build.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ ggplot_gtable.ggplot_built <- function(data) {
288288
plot_margin <- calc_element("plot.margin", theme)
289289
plot_table <- gtable_add_padding(plot_table, plot_margin)
290290

291-
if (is.element(theme$plot.background)) {
291+
if (is.theme_element(theme$plot.background)) {
292292
plot_table <- gtable_add_grob(plot_table,
293293
element_render(theme, "plot.background"),
294294
t = 1, l = 1, b = -1, r = -1, name = "background", z = -Inf)

R/scale-.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ binned_scale <- function(aesthetics, scale_name = deprecated(), palette, name =
319319
}
320320

321321
transform <- as.transform(transform)
322-
if (!is.null(limits)) {
322+
if (!is.null(limits) && !is.function(limits)) {
323323
limits <- transform$transform(limits)
324324
}
325325

R/theme-elements.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ element_geom <- function(
204204

205205
#' @export
206206
#' @rdname is_tests
207-
is.element <- function(x) inherits(x, "element")
207+
is.theme_element <- function(x) inherits(x, "element")
208208

209209
#' @export
210210
print.element <- function(x, ...) utils::str(x)

0 commit comments

Comments
 (0)