Skip to content

Commit 80382d9

Browse files
authored
Merge branch 'main' into tile_panel_resolution
2 parents 966f89d + f8dac9d commit 80382d9

File tree

214 files changed

+3410
-4096
lines changed

Some content is hidden

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

214 files changed

+3410
-4096
lines changed

.github/workflows/R-CMD-check.yaml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@ jobs:
2525
- {os: macos-latest, r: 'release'}
2626

2727
- {os: windows-latest, r: 'release'}
28-
# Use 3.6 to trigger usage of RTools35
29-
- {os: windows-latest, r: '3.6'}
3028
# use 4.1 to check with rtools40's older compiler
3129
- {os: windows-latest, r: '4.1'}
3230

@@ -64,7 +62,7 @@ jobs:
6462
extra-packages: >
6563
any::rcmdcheck,
6664
Hmisc=?ignore-before-r=4.1.0,
67-
quantreg=?ignore-before-r=3.6.0,
65+
quantreg=?ignore-before-r=4.3.0,
6866
needs: check
6967

7068
- uses: r-lib/actions/check-r-package@v2

DESCRIPTION

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Package: ggplot2
2-
Version: 3.5.0.9000
2+
Version: 3.5.1.9000
33
Title: Create Elegant Data Visualisations Using the Grammar of Graphics
44
Authors@R: c(
55
person("Hadley", "Wickham", , "[email protected]", role = "aut",
@@ -45,7 +45,7 @@ Imports:
4545
scales (>= 1.3.0),
4646
stats,
4747
tibble,
48-
vctrs (>= 0.5.0),
48+
vctrs (>= 0.6.0),
4949
withr (>= 2.5.0)
5050
Suggests:
5151
covr,

NAMESPACE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,7 @@ export(get_alt_text)
422422
export(get_element_tree)
423423
export(get_guide_data)
424424
export(gg_dep)
425+
export(ggpar)
425426
export(ggplot)
426427
export(ggplotGrob)
427428
export(ggplot_add)

NEWS

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ NEW FEATURES
2828
`example(position_jitterdodge)` for a potential usage. (@kevinushey, #932)
2929

3030
* Allow specifying only one of the limits in a scale and use the automatic
31-
calculation of the other limit by passing NA to to the limit function,
31+
calculation of the other limit by passing NA to the limit function,
3232
`xlim()` or `ylim()` (@jimhester, #557).
3333

3434
* Allow to use brewer palettes for continuous scales, through the new

NEWS.md

Lines changed: 82 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,92 @@
1-
21
# ggplot2 (development version)
32

4-
* Fixed performance loss when the `.data` pronoun is used in `aes()` (#5730).
3+
* The bounded density option in `stat_density()` uses a wider range to
4+
prevent discontinuities (#5641).
5+
* `geom_raster()` now falls back to rendering as `geom_rect()` when coordinates
6+
are not Cartesian (#5503).
7+
* `stat_ecdf()` now has an optional `weight` aesthetic (@teunbrand, #5058).
8+
* Position scales combined with `coord_sf()` can now use functions in the
9+
`breaks` argument. In addition, `n.breaks` works as intended and
10+
`breaks = NULL` removes grid lines and axes (@teunbrand, #4622).
11+
* (Internal) Applying defaults in `geom_sf()` has moved from the internal
12+
`sf_grob()` to `GeomSf$use_defaults()` (@teunbrand).
13+
* `facet_wrap()` has new options for the `dir` argument to more precisely
14+
control panel directions (@teunbrand, #5212)
15+
* Prevented `facet_wrap(..., drop = FALSE)` from throwing spurious errors when
16+
a character facetting variable contained `NA`s (@teunbrand, #5485).
17+
* When facets coerce the faceting variables to factors, the 'ordered' class
18+
is dropped (@teunbrand, #5666).
19+
* `geom_curve()` now appropriately removes missing data instead of throwing
20+
errors (@teunbrand, #5831).
21+
* `update_geom_defaults()` and `update_stat_defaults()` have a reset mechanism
22+
when using `new = NULL` and invisible return the previous defaults (#4993).
23+
* Fixed regression in axes where `breaks = NULL` caused the axes to disappear
24+
instead of just rendering the axis line (@teunbrand, #5816).
25+
* `geom_point()` can be dodged vertically by using
26+
`position_dodge(..., orientation = "y")` (@teunbrand, #5809).
27+
* Fixed bug where `na.value` was incorrectly mapped to non-`NA` values
28+
(@teunbrand, #5756).
29+
* Fixed bug in `guide_custom()` that would throw error with `theme_void()`
30+
(@teunbrand, #5856).
31+
* New helper function `ggpar()` to translate ggplot2's interpretation of
32+
graphical parameters to {grid}'s interpretation (@teunbrand, #5866).
33+
* `scale_{x/y}_discrete()` can now accept a `sec.axis`. It is recommended to
34+
only use `dup_axis()` to set custom breaks or labels, as discrete variables
35+
cannot be transformed (@teunbrand, #3171).
36+
* `stat_density()` has the new computed variable: `wdensity`, which is
37+
calculated as the density times the sum of weights (@teunbrand, #4176).
38+
* `theme()` gets new `spacing` and `margins` arguments that all other spacings
39+
and (non-text) margins inherit from (@teunbrand, #5622).
40+
* `geom_ribbon()` can have varying `fill` or `alpha` in linear coordinate
41+
systems (@teunbrand, #4690).
42+
* `geom_tile()` computes default widths and heights per panel instead of
43+
per layer (@teunbrand, #5740).
44+
45+
# ggplot2 3.5.1
46+
47+
This is a small release focusing on fixing regressions from 3.5.0 and
48+
documentation updates.
49+
50+
## Bug fixes
51+
552
* Fixed bug where discrete scales could not map aesthetics only consisting of
653
`NA`s (#5623)
7-
* Facet evaluation is better at dealing with inherited errors
8-
(@teunbrand, #5670).
954
* Fixed spurious warnings from `sec_axis()` with `breaks = NULL` (#5713).
1055
* Patterns and gradients are now also enabled in `geom_sf()`
1156
(@teunbrand, #5716).
57+
* The default behaviour of `resolution()` has been reverted to pre-3.5.0
58+
behaviour. Whether mapped discrete vectors should be treated as having
59+
resolution of 1 is controlled by the new `discrete` argument.
60+
* Fixed bug in `guide_bins()` and `guide_coloursteps()` where discrete breaks,
61+
such as the levels produced by `cut()`, were ordered incorrectly
62+
(@teunbrand, #5757).
63+
64+
## Improvements
65+
66+
* When facets coerce the faceting variables to factors, the 'ordered' class
67+
is dropped (@teunbrand, #5666).
68+
* `coord_map()` and `coord_polar()` throw informative warnings when used
69+
with the guide system (#5707).
70+
* When passing a function to `stat_contour(breaks)`, that function is used to
71+
calculate the breaks even if `bins` and `binwidth` are missing
72+
(@teunbrand, #5686).
73+
* `geom_step()` now supports `lineend`, `linejoin` and `linemitre` parameters
74+
(@teunbrand, #5705).
75+
* Fixed performance loss when the `.data` pronoun is used in `aes()` (#5730).
76+
* Facet evaluation is better at dealing with inherited errors
77+
(@teunbrand, #5670).
1278
* `stat_bin()` deals with non-finite breaks better (@teunbrand, #5665).
13-
* `geom_tile()` computes default widths and heights per panel instead of
14-
per layer (@teunbrand, #5740).
79+
* While axes in `coord_radial()` don't neatly fit the top/right/bottom/left
80+
organisation, specifying `position = "top"` or `position = "right"`
81+
in the scale will flip the placement of the radial axis (#5735)
82+
* Theme elements that do not exist now throw warnings instead of errors (#5719).
83+
* Fixed bug in `coord_radial()` where full circles were not treated as such
84+
(@teunbrand, #5750).
85+
* When legends detect the presence of values in a layer, `NA` is now detected
86+
if the data contains values outside the given breaks (@teunbrand, #5749).
87+
* `annotate()` now warns about `stat` or `position` arguments (@teunbrand, #5151)
88+
* `guide_coloursteps(even.steps = FALSE)` now works with discrete data that has
89+
been formatted by `cut()` (@teunbrand, #3877).
1590

1691
# ggplot2 3.5.0
1792

@@ -1444,7 +1519,7 @@ accompanying issue #2890.
14441519

14451520
We recognise that this is a big change and if you're not already familiar
14461521
with rlang, there's a lot to learn. If you are stuck, or need any help,
1447-
please reach out on <https://community.rstudio.com>.
1522+
please reach out on <https://forum.posit.co/>.
14481523

14491524
* Error: Column `y` must be a 1d atomic vector or a list
14501525

R/annotation-logticks.R

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -175,14 +175,14 @@ GeomLogticks <- ggproto("GeomLogticks", Geom,
175175
ticks$x_b <- with(data, segmentsGrob(
176176
x0 = unit(xticks$x, "native"), x1 = unit(xticks$x, "native"),
177177
y0 = unit(xticks$start, "cm"), y1 = unit(xticks$end, "cm"),
178-
gp = gpar(col = alpha(colour, alpha), lty = linetype, lwd = linewidth * .pt)
178+
gp = ggpar(col = alpha(colour, alpha), lty = linetype, lwd = linewidth)
179179
))
180180
}
181181
if (grepl("t", sides) && nrow(xticks) > 0) {
182182
ticks$x_t <- with(data, segmentsGrob(
183183
x0 = unit(xticks$x, "native"), x1 = unit(xticks$x, "native"),
184184
y0 = unit(1, "npc") - unit(xticks$start, "cm"), y1 = unit(1, "npc") - unit(xticks$end, "cm"),
185-
gp = gpar(col = alpha(colour, alpha), lty = linetype, lwd = linewidth * .pt)
185+
gp = ggpar(col = alpha(colour, alpha), lty = linetype, lwd = linewidth)
186186
))
187187
}
188188
}
@@ -213,14 +213,14 @@ GeomLogticks <- ggproto("GeomLogticks", Geom,
213213
ticks$y_l <- with(data, segmentsGrob(
214214
y0 = unit(yticks$y, "native"), y1 = unit(yticks$y, "native"),
215215
x0 = unit(yticks$start, "cm"), x1 = unit(yticks$end, "cm"),
216-
gp = gpar(col = alpha(colour, alpha), lty = linetype, lwd = linewidth * .pt)
216+
gp = ggpar(col = alpha(colour, alpha), lty = linetype, lwd = linewidth)
217217
))
218218
}
219219
if (grepl("r", sides) && nrow(yticks) > 0) {
220220
ticks$y_r <- with(data, segmentsGrob(
221221
y0 = unit(yticks$y, "native"), y1 = unit(yticks$y, "native"),
222222
x0 = unit(1, "npc") - unit(yticks$start, "cm"), x1 = unit(1, "npc") - unit(yticks$end, "cm"),
223-
gp = gpar(col = alpha(colour, alpha), lty = linetype, lwd = linewidth * .pt)
223+
gp = ggpar(col = alpha(colour, alpha), lty = linetype, lwd = linewidth)
224224
))
225225
}
226226
}

R/annotation-map.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,9 @@ GeomAnnotationMap <- ggproto("GeomAnnotationMap", GeomMap,
9595

9696
polygonGrob(coords$x, coords$y, default.units = "native",
9797
id = grob_id,
98-
gp = gpar(
98+
gp = ggpar(
9999
col = data$colour, fill = alpha(data$fill, data$alpha),
100-
lwd = data$linewidth * .pt)
100+
lwd = data$linewidth)
101101
)
102102
},
103103

R/annotation.R

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,19 @@ annotate <- function(geom, x = NULL, y = NULL, xmin = NULL, xmax = NULL,
7474
}
7575

7676
data <- data_frame0(!!!position, .size = n)
77+
78+
params <- list2(na.rm = na.rm, ...)
79+
reject <- intersect(names(params), c("position", "stat"))
80+
if (length(reject) > 0) {
81+
cli::cli_warn(
82+
"{.fn annotate} can't accept {.or {.arg {reject}}} argument{?s}."
83+
)
84+
params <- params[setdiff(names(params), reject)]
85+
}
86+
7787
layer(
7888
geom = geom,
79-
params = list(
80-
na.rm = na.rm,
81-
...
82-
),
89+
params = params,
8390
stat = StatIdentity,
8491
position = PositionIdentity,
8592
data = data,

R/autolayer.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#' @param ... other arguments passed to specific methods
99
#' @return a ggplot layer
1010
#' @export
11-
#' @seealso [autoplot()], [ggplot()] and [fortify()]
11+
#' @family plotting automation topics
1212
autolayer <- function(object, ...) {
1313
UseMethod("autolayer")
1414
}

R/autoplot.R

Lines changed: 113 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,115 @@
1+
#' Tailoring plots to particular data types
2+
#'
3+
#' @description
4+
#' There are three functions to make plotting particular data types easier:
5+
#' `autoplot()`, `autolayer()` and `fortify()`. These are S3 generics for which
6+
#' other packages can write methods to display classes of data. The three
7+
#' functions are complementary and allow different levels of customisation.
8+
#' Below we'll explore implementing this series of methods to automate plotting
9+
#' of some class.
10+
#'
11+
#' Let's suppose we are writing a packages that has a class called 'my_heatmap',
12+
#' that wraps a matrix and we'd like users to easily plot this heatmap.
13+
#'
14+
#' ```r
15+
#' my_heatmap <- function(...) {
16+
#' m <- matrix(...)
17+
#' class(m) <- c("my_heatmap", class(m))
18+
#' m
19+
#' }
20+
#'
21+
#' my_data <- my_heatmap(volcano)
22+
#' ```
23+
#'
24+
#' # Automatic data shaping
25+
#'
26+
#' One of the things we have to do is ensure that the data is shaped in the long
27+
#' format so that it is compatible with ggplot2. This is the job of the
28+
#' `fortify()` function. Because 'my_heatmap' wraps a matrix, we can let the
29+
#' fortify method 'melt' the matrix to a long format. If your data is already
30+
#' based on a long-format `<data.frame>`, you can skip implementing a
31+
#' `fortify()` method.
32+
#'
33+
#' ```r
34+
#' fortify.my_heatmap <- function(model, ...) {
35+
#' data.frame(
36+
#' row = as.vector(row(model)),
37+
#' col = as.vector(col(model)),
38+
#' value = as.vector(model)
39+
#' )
40+
#' }
41+
#'
42+
#' fortify(my_data)
43+
#' ```
44+
#'
45+
#' When you have implemented the `fortify()` method, it should be easier to
46+
#' construct a plot with the data than with the matrix.
47+
#'
48+
#' ```r
49+
#' ggplot(my_data, aes(x = col, y = row, fill = value)) +
50+
#' geom_raster()
51+
#' ```
52+
#'
53+
#' # Automatic layers
54+
#'
55+
#' A next step in automating plotting of your data type is to write an
56+
#' `autolayer()` method. These are typically wrappers around geoms or stats
57+
#' that automatically set aesthetics or other parameters. If you haven't
58+
#' implemented a `fortify()` method for your data type, you might have to
59+
#' reshape the data in `autolayer()`.
60+
#'
61+
#' If you require multiple layers to display your data type, you can use an
62+
#' `autolayer()` method that constructs a list of layers, which can be added
63+
#' to a plot.
64+
#'
65+
#' ```r
66+
#' autolayer.my_heatmap <- function(object, ...) {
67+
#' geom_raster(
68+
#' mapping = aes(x = col, y = row, fill = value),
69+
#' data = object,
70+
#' ...,
71+
#' inherit.aes = FALSE
72+
#' )
73+
#' }
74+
#'
75+
#' ggplot() + autolayer(my_data)
76+
#' ```
77+
#'
78+
#' As a quick tip: if you define a mapping in `autolayer()`, you might want
79+
#' to set `inherit.aes = FALSE` to not have aesthetics set in other layers
80+
#' interfere with your layer.
81+
#'
82+
#' # Automatic plots
83+
#'
84+
#' The last step in automating plotting is to write an `autoplot()` method
85+
#' for your data type. The expectation is that these return a complete plot.
86+
#' In the example below, we're exploiting the `autolayer()` method that we
87+
#' have already written to make a complete plot.
88+
#'
89+
#' ```r
90+
#' autoplot.my_heatmap <- function(object, ..., option = "magma") {
91+
#' ggplot() +
92+
#' autolayer(my_data) +
93+
#' scale_fill_viridis_c(option = option) +
94+
#' theme_void()
95+
#' }
96+
#'
97+
#' autoplot(my_data)
98+
#' ```
99+
#'
100+
#' If you don't have a wish to implement a base R plotting method, you
101+
#' can set the plot method for your class to the autoplot method.
102+
#'
103+
#' ```r
104+
#' plot.my_heatmap <- autoplot.my_heatmap
105+
#' plot(my_data)
106+
#' ```
107+
#'
108+
#' @family plotting automation topics
109+
#'
110+
#' @name automatic_plotting
111+
NULL
112+
1113
#' Create a complete ggplot appropriate to a particular data type
2114
#'
3115
#' `autoplot()` uses ggplot2 to draw a particular plot for an object of a
@@ -8,7 +120,7 @@
8120
#' @param ... other arguments passed to specific methods
9121
#' @return a ggplot object
10122
#' @export
11-
#' @seealso [autolayer()], [ggplot()] and [fortify()]
123+
#' @family plotting automation topics
12124
autoplot <- function(object, ...) {
13125
UseMethod("autoplot")
14126
}

0 commit comments

Comments
 (0)