Skip to content

Commit b9f6ebc

Browse files
committed
Fix all size warnings calls to ggplot2 (deprecated at 3.4.0). Deprecated arg size and added linewidth as new preferred arg where it made sense.
1 parent 5a5b1e5 commit b9f6ebc

File tree

8 files changed

+49
-22
lines changed

8 files changed

+49
-22
lines changed

DESCRIPTION

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ Imports:
3434
ggplot2 (>= 3.4.0),
3535
ggridges (>= 0.5.5),
3636
glue,
37+
lifecycle,
3738
posterior,
3839
reshape2,
3940
rlang (>= 0.3.0),

NAMESPACE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,3 +224,4 @@ importFrom(dplyr,top_n)
224224
importFrom(dplyr,ungroup)
225225
importFrom(dplyr,vars)
226226
importFrom(ggplot2,"%+replace%")
227+
importFrom(lifecycle,deprecated)

R/mcmc-traces.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ mcmc_rank_overlay <- function(x,
337337
geom_hline(
338338
yintercept = (right_edge / n_bins) / n_chains,
339339
color = get_color("dark_highlight"),
340-
size = 1,
340+
linewidth = 1,
341341
linetype = "dashed"
342342
)
343343
} else {
@@ -417,7 +417,7 @@ mcmc_rank_hist <- function(x,
417417
geom_hline(
418418
yintercept = (right_edge / n_bins) / n_chains,
419419
color = get_color("dark_highlight"),
420-
size = .5,
420+
linewidth = .5,
421421
linetype = "dashed"
422422
)
423423
} else {

R/ppc-censoring.R

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@
1515
#' @family PPCs
1616
#'
1717
#' @template args-y-yrep
18-
#' @param size,alpha Passed to the appropriate geom to control the appearance of
18+
#' @param linewidth,alpha Passed to the appropriate geom to control the appearance of
1919
#' the `yrep` distributions.
20+
#' @param size `r lifecycle::badge("deprecated")` Please use `linewidth` instead of `size`.
2021
#' @param ... Currently only used internally.
2122
#'
2223
#' @template return-ggplot
@@ -96,17 +97,27 @@ NULL
9697
#' posterior predictive draws may not be shown by default because of the
9798
#' controlled extrapolation. To display all posterior predictive draws, set
9899
#' `extrapolation_factor = Inf`.
99-
#'
100+
#' @importFrom lifecycle deprecated
100101
ppc_km_overlay <- function(
101102
y,
102103
yrep,
103104
...,
104105
status_y,
105106
left_truncation_y = NULL,
106107
extrapolation_factor = 1.2,
107-
size = 0.25,
108+
linewidth = 0.25,
109+
size = deprecated(),
108110
alpha = 0.7
109111
) {
112+
if (lifecycle::is_present(size)) {
113+
lifecycle::deprecate_warn(
114+
"1.16.0",
115+
"ppc_km_overlay(size)",
116+
details = "Please use `linewidth` instead of `size`."
117+
)
118+
linewidth <- size
119+
}
120+
110121
check_ignored_arguments(..., ok_args = "add_group")
111122
add_group <- list(...)$add_group
112123

@@ -173,7 +184,7 @@ ppc_km_overlay <- function(
173184
}
174185

175186
fsf$is_y_color <- as.factor(sub("\\[rep\\] \\(.*$", "rep", sub("^italic\\(y\\)", "y", fsf$strata)))
176-
fsf$is_y_size <- ifelse(fsf$is_y_color == "yrep", size, 1)
187+
fsf$is_y_linewidth <- ifelse(fsf$is_y_color == "yrep", linewidth, 1)
177188
fsf$is_y_alpha <- ifelse(fsf$is_y_color == "yrep", alpha, 1)
178189

179190
max_time_y <- max(y, na.rm = TRUE)
@@ -189,7 +200,7 @@ ppc_km_overlay <- function(
189200
y = .data$surv,
190201
color = .data$is_y_color,
191202
group = .data$strata,
192-
size = .data$is_y_size,
203+
linewidth = .data$is_y_linewidth,
193204
alpha = .data$is_y_alpha)) +
194205
geom_step() +
195206
hline_at(
@@ -204,7 +215,7 @@ ppc_km_overlay <- function(
204215
linetype = 2,
205216
color = get_color("dh")
206217
) +
207-
scale_size_identity() +
218+
scale_linewidth_identity() +
208219
scale_alpha_identity() +
209220
scale_color_ppc() +
210221
scale_y_continuous(breaks = c(0, 0.5, 1)) +
@@ -218,6 +229,7 @@ ppc_km_overlay <- function(
218229
#' @export
219230
#' @rdname PPC-censoring
220231
#' @template args-group
232+
#' @importFrom lifecycle deprecated
221233
ppc_km_overlay_grouped <- function(
222234
y,
223235
yrep,
@@ -226,9 +238,18 @@ ppc_km_overlay_grouped <- function(
226238
status_y,
227239
left_truncation_y = NULL,
228240
extrapolation_factor = 1.2,
229-
size = 0.25,
241+
linewidth = 0.25,
242+
size = deprecated(),
230243
alpha = 0.7
231244
) {
245+
if (lifecycle::is_present(size)) {
246+
lifecycle::deprecate_warn(
247+
"1.16.0",
248+
"ppc_km_overlay_grouped(size)",
249+
details = "Please use `linewidth` instead of `size`."
250+
)
251+
linewidth <- size
252+
}
232253
check_ignored_arguments(...)
233254

234255
p_overlay <- ppc_km_overlay(
@@ -238,7 +259,7 @@ ppc_km_overlay_grouped <- function(
238259
...,
239260
status_y = status_y,
240261
left_truncation_y = left_truncation_y,
241-
size = size,
262+
linewidth = linewidth,
242263
alpha = alpha,
243264
extrapolation_factor = extrapolation_factor
244265
)

R/ppc-discrete.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ ppc_rootogram <- function(y,
359359
if (style == "standing") {
360360
graph <- graph + dont_expand_y_axis()
361361
} else {
362-
graph <- graph + hline_0(size = 0.4)
362+
graph <- graph + hline_0(linewidth = 0.4)
363363
}
364364
}
365365

R/ppd-intervals.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ ppd_ribbon <-
162162
linewidth = 0.2 * size,
163163
alpha = 1
164164
) +
165-
geom_ribbon(size = 0.5 * size) +
165+
geom_ribbon(linewidth = 0.5 * size) +
166166
geom_line(
167167
mapping = aes(y = .data$m),
168168
color = get_color("d"),

man/PPC-censoring.Rd

Lines changed: 7 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testthat/test-ppc-censoring.R

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ source(test_path("data-for-ppc-tests.R"))
22

33
test_that("ppc_km_overlay returns a ggplot object", {
44
skip_if_not_installed("ggfortify")
5-
expect_gg(ppc_km_overlay(y, yrep, status_y = status_y, left_truncation_y = left_truncation_y, size = 0.5, alpha = 0.2, extrapolation_factor = Inf))
6-
expect_gg(ppc_km_overlay(y, yrep, status_y = status_y, left_truncation_y = left_truncation_y, size = 0.5, alpha = 0.2, extrapolation_factor = 1))
5+
expect_gg(ppc_km_overlay(y, yrep, status_y = status_y, left_truncation_y = left_truncation_y, linewidth = 0.5, alpha = 0.2, extrapolation_factor = Inf))
6+
expect_gg(ppc_km_overlay(y, yrep, status_y = status_y, left_truncation_y = left_truncation_y, linewidth = 0.5, alpha = 0.2, extrapolation_factor = 1))
77
expect_gg(ppc_km_overlay(y2, yrep2, status_y = status_y2))
88
})
99

@@ -12,15 +12,15 @@ test_that("ppc_km_overlay_grouped returns a ggplot object", {
1212
expect_gg(ppc_km_overlay_grouped(y, yrep, group,
1313
status_y = status_y,
1414
left_truncation_y = left_truncation_y,
15-
size = 0.5, alpha = 0.2))
15+
linewidth = 0.5, alpha = 0.2))
1616
expect_gg(ppc_km_overlay_grouped(y, yrep, as.numeric(group),
1717
status_y = status_y,
1818
left_truncation_y = left_truncation_y,
19-
size = 0.5, alpha = 0.2))
19+
linewidth = 0.5, alpha = 0.2))
2020
expect_gg(ppc_km_overlay_grouped(y, yrep, as.integer(group),
2121
status_y = status_y,
2222
left_truncation_y = left_truncation_y,
23-
size = 0.5, alpha = 0.2))
23+
linewidth = 0.5, alpha = 0.2))
2424

2525
expect_gg(ppc_km_overlay_grouped(y2, yrep2, group2,
2626
status_y = status_y2))
@@ -89,7 +89,7 @@ test_that("ppc_km_overlay renders correctly", {
8989
vdiff_y2,
9090
vdiff_yrep2,
9191
status_y = vdiff_status_y2,
92-
size = 2,
92+
linewidth = 2,
9393
alpha = .2)
9494
vdiffr::expect_doppelganger("ppc_km_overlay (size, alpha)", p_custom)
9595

@@ -138,7 +138,7 @@ test_that("ppc_km_overlay_grouped renders correctly", {
138138
vdiff_yrep2,
139139
vdiff_group2,
140140
status_y = vdiff_status_y2,
141-
size = 2,
141+
linewidth = 2,
142142
alpha = .2
143143
)
144144

0 commit comments

Comments
 (0)