/
plot_moderators.R
640 lines (562 loc) · 20.6 KB
/
plot_moderators.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
#' @title Partial dependency plot of a continuous moderating variable
#' @description Plot a partial dependency plot with a continuous covariate from a 'bartCause' model. Identify treatment effect variation predicted across levels of a continuous variable.
#'
#' @param .model a model produced by `bartCause::bartc()`
#' @param moderator the moderator as a vector
#' @param n_bins number of bins to cut the moderator with. Defaults to the lesser of 15 and number of distinct levels of the moderator
#' @details Partial dependency plots are one way to evaluate heterogeneous treatment effects that vary by values of a continuous covariate. For more information on partial dependency plots from BART causal inference models see Green and Kern 2012.
#' @author George Perrett, Joseph Marlo
#'
#' @references
#' Green, D. P., & Kern, H. L. (2012).
#' Modeling heterogeneous treatment effects in survey experiments with Bayesian additive regression trees.
#' Public opinion quarterly, 76(3), 491-511.
#'
#' @return ggplot object
#' @export
#'
#' @import ggplot2 dplyr
#' @importFrom stats density median na.omit predict quantile sd
#'
#' @examples
#' \donttest{
#' data(lalonde)
#' confounders <- c('age', 'educ', 'black', 'hisp', 'married', 'nodegr')
#' model_results <- bartCause::bartc(
#' response = lalonde[['re78']],
#' treatment = lalonde[['treat']],
#' confounders = as.matrix(lalonde[, confounders]),
#' estimand = 'ate',
#' commonSuprule = 'none',
#' keepTrees = TRUE
#' )
#' plot_moderator_c_pd(model_results, lalonde$age)
#' }
plot_moderator_c_pd <- function(.model, moderator, n_bins = NULL){
validate_model_(.model)
# validate n_bins argument
n_mod_levels <- n_distinct(moderator)
if (n_mod_levels <= 1) stop('dplyr::n_distinct(moderator) must be at least 2')
if (is.null(n_bins)) n_bins <- pclamp_(15, 2, n_mod_levels)
if (!(n_bins > 1 & n_bins <= n_mod_levels)) stop("n_bins must be greater than 1 and less than or equal to dplyr::n_distinct(moderator)")
# extract data from model
new_data <- as_tibble(.model$data.rsp@x)
# create dataframe where all observations are treated
new_data_z1 <- new_data
name_trt <- .model$name.trt
new_data_z1[, name_trt] <- 1
new_data_z1 <- cbind.data.frame(y_response = .model$fit.rsp$y, new_data_z1)
# create dataframe where all observations are control
new_data_z0 <- new_data
new_data_z0[, name_trt] <- 0
new_data_z0 <- cbind.data.frame(y_response = .model$fit.rsp$y, new_data_z0)
# locate the moderator in bartc data
search_moderator <- function(x) sum(moderator - x)
index <- which(lapply(new_data_z0, search_moderator) == 0)
if (!isTRUE(index > 0)) stop('Cannot find moderator in original data. Is moderator within the original dataframe used to fit the .model?')
# get range for predictions
cut <- n_bins-1
p <- seq(min(moderator), max(moderator), (max(moderator) - min(moderator))/cut)
if (length(p) < n_distinct(moderator)) {
.range <- p
} else{
.range <- unique(moderator)[order(unique(moderator))]
}
# predict new data with overridden treatment columns
cates <- lapply(.range, fit_pd_, z1 = new_data_z1, z0 = new_data_z0, index = index, .model = .model)
names(cates) <- seq_along(cates)
cates <- bind_cols(cates)
cates.m <- apply(cates, MARGIN = 2, FUN = mean)
cates.m <- bind_cols(cates.m = cates.m, .range = .range)
# get credible intervals
ci_range <- c(0.025, 0.1, 0.9, 0.975)
cates.ci <- as_tibble(t(apply(cates, MARGIN = 2, FUN = quantile, probs = ci_range)))
cates_plot <- bind_cols(cates.m, cates.ci)
indices <- 2 + seq_along(ci_range)
colnames(cates_plot)[indices] <- paste0('ci_', as.character(ci_range * 100))
# plot it
p <- ggplot(cates_plot) +
geom_ribbon(aes(x = .range, y = cates.m, ymin = ci_2.5, ymax = ci_97.5, fill = '95% ci')) +
geom_ribbon(aes(x = .range, y = cates.m, ymin = ci_10, ymax = ci_90, fill = '80% ci')) +
scale_fill_manual(values = c('grey40', 'grey60')) +
geom_point(aes(x = .range, y = cates.m), size = 2) +
geom_line(aes(x = .range, y = cates.m)) +
labs(title = NULL,
x = NULL,
y = 'CATE') +
theme(legend.position = "bottom")
return(p)
}
#' @title LOESS plot of a continuous moderating variable
#' @description Plot the LOESS prediction of ICATEs by a continuous covariate. This is an alternative to partial dependency plots to assess treatment effect heterogeneity by a continuous covariate. See Carnegie, Dorie and Hill 2019.
#'
#' @param .model a model produced by `bartCause::bartc()`
#' @param moderator the moderator as a vector
#' @param line_color the color of the loess line
#'
#' @author George Perrett, Joseph Marlo
#'
#' @references
#' Carnegie, N., Dorie, V., & Hill, J. L. (2019).
#' Examining treatment effect heterogeneity using BART.
#' Observational Studies, 5(2), 52-70.
#'
#' @return ggplot object
#' @export
#'
#' @import ggplot2 dplyr
#' @importFrom bartCause extract
#'
#' @examples
#' \donttest{
#' data(lalonde)
#' confounders <- c('age', 'educ', 'black', 'hisp', 'married', 'nodegr')
#' model_results <- bartCause::bartc(
#' response = lalonde[['re78']],
#' treatment = lalonde[['treat']],
#' confounders = as.matrix(lalonde[, confounders]),
#' estimand = 'ate',
#' commonSuprule = 'none'
#' )
#' plot_moderator_c_loess(model_results, lalonde$age)
#' }
plot_moderator_c_loess <- function(.model, moderator, line_color = 'blue'){
validate_model_(.model)
is_numeric_vector_(moderator)
# adjust moderator to match estimand
moderator <- adjust_for_estimand_(.model, moderator)
# extract and rotate posterior
posterior <- bartCause::extract(.model, 'icate')
posterior <- posterior %>%
t() %>%
as.data.frame() %>%
as_tibble()
# split posterior into list of dfs by each level of moderator
split_posterior <- split(posterior, moderator)
posterior_means <- lapply(split_posterior, rowMeans)
# unlist into a data.frame for plotting
dat <- data.frame(value = unlist(posterior_means))
dat$moderator <- moderator[order(moderator)]
rownames(dat) <- seq_len(nrow(dat))
# plot it
p <- ggplot(dat, aes(moderator, value)) +
geom_point() +
geom_smooth(method = 'loess',
formula = y ~ x,
se = TRUE,
size = 1.5,
color = line_color) +
labs(title = NULL,
x = NULL,
y = 'icate')
return(p)
}
#' @title Auto-Bin a plot of a continuous moderating variable into a discrete moderating variable
#' @description Use a regression tree to optimally bin a continous variable
#'
#' @param .model a model produced by `bartCause::bartc()`
#' @param moderator the moderator as a vector
#' @param .alpha transparency value [0, 1]
#' @param facet TRUE/FALSE. Create panel plots of each moderator level?
#' @param .ncol number of columns to use when faceting
#' @param type string to specify if you would like to plot a histogram, density or error bar plot
#'@param .name sting representing the name of the moderating variable
#'
#' @author George Perrett
#'
#'
#' @return ggplot object
#' @export
#'
#' @import ggplot2 dplyr
#' @importFrom bartCause extract
#' @importFrom rpart rpart
#'
#' @examples
#' \donttest{
#' data(lalonde)
#' confounders <- c('age', 'educ', 'black', 'hisp', 'married', 'nodegr')
#' model_results <- bartCause::bartc(
#' response = lalonde[['re78']],
#' treatment = lalonde[['treat']],
#' confounders = as.matrix(lalonde[, confounders]),
#' estimand = 'ate',
#' commonSuprule = 'none'
#' )
#' plot_moderator_c_bin(model_results, lalonde$age, .name = 'age')
#' }
plot_moderator_c_bin <- function(.model, moderator,type = c('density', 'histogram', 'errorbar'), .alpha = 0.7, facet = FALSE, .ncol = 1, .name = 'bin'){
validate_model_(.model)
is_numeric_vector_(moderator)
type <- type[1]
# adjust moderator to match estimand
moderator <- adjust_for_estimand_(.model, moderator)
estimand <- switch (.model$estimand,
ate = 'CATE',
att = 'CATT',
atc = 'CATC'
)
# extract the posterior
posterior <- bartCause::extract(.model, 'icate')
# get icate point est
icate.m <- apply(posterior, 2, mean)
# fit regression tree
tree <- rpart::rpart(icate.m ~ moderator)
# get bins from regression tree
bins <- dplyr::tibble(splits = tree$where,
x = moderator)
subgroups <- dplyr::tibble(splits = tree$where,
x = moderator) %>%
dplyr::group_by(splits) %>%
dplyr::summarise(min = min(x), max = max(x)) %>%
dplyr::arrange(min) %>%
dplyr::mutate(subgroup = paste0(.name,':', round(min, 2) ,'-', round(max, 2)))
bins <- bins %>% dplyr::left_join(subgroups)
# roatate posterior
posterior <- posterior %>%
t() %>%
as.data.frame() %>%
as_tibble() %>%
mutate(moderator = bins$subgroup)
# marginalize
posterior <- posterior %>%
group_by(moderator) %>%
summarise_all(mean) %>%
pivot_longer(cols = 2:ncol(posterior))
# plot it
p <- ggplot(posterior, aes(value, fill = moderator))
if(type == 'density'){
p <- p + geom_density(alpha = .alpha) +
labs(title = NULL,
x = estimand,
y = NULL) +
theme(legend.position = 'bottom')
}else if(type == 'histogram'){
p <- p +
geom_histogram(
alpha = .alpha,
col = 'black',
position = 'identity') +
labs(title = NULL,
x = estimand,
y = NULL) +
theme(legend.position = 'bottom')
} else{
# tidy up the data
dat <- dat %>%
group_by(moderator) %>%
mutate(.min = quantile(value, .025),
.max = quantile(value, .975),
point = mean(value)) %>%
dplyr::select(-value) %>%
arrange(desc(point)) %>%
ungroup() %>%
distinct()
# plot it
p <- ggplot(dat, aes(x = moderator, y = point, color = moderator)) +
geom_point(size = 2) +
geom_linerange(aes(ymin = .min, ymax = .max), alpha = .alpha) +
labs(title = NULL,
x = element_blank(),
y = estimand) +
theme(legend.position = 'bottom')
}
# add faceting
if(isTRUE(facet)){
p <- p + facet_wrap(~moderator, ncol = .ncol)
}
return(p)
}
#' @title Plot the Conditional Average Treatment Effect conditional on a discrete moderator
#' @description Plot the Conditional Average Treatment Effect split by a discrete moderating variable. This plot will provide a visual test of moderation by discrete variables.
#'
#' @param .model a model produced by `bartCause::bartc()`
#' @param moderator the moderator as a vector
#' @param .alpha transparency value [0, 1]
#' @param facet TRUE/FALSE. Create panel plots of each moderator level?
#' @param .ncol number of columns to use when faceting
#' @param type string to specify if you would like to plot a histogram, density or error bar plot
#'
#' @author George Perrett
#'
#' @return ggplot object
#' @export
#'
#' @import ggplot2 dplyr
#' @importFrom bartCause extract
#'
#' @examples
#' \donttest{
#' data(lalonde)
#' confounders <- c('age', 'educ', 'black', 'hisp', 'married', 'nodegr')
#' model_results <- bartCause::bartc(
#' response = lalonde[['re78']],
#' treatment = lalonde[['treat']],
#' confounders = as.matrix(lalonde[, confounders]),
#' estimand = 'ate',
#' commonSuprule = 'none'
#' )
#' plot_moderator_d(model_results, lalonde$educ)
#' }
plot_moderator_d <- function(.model, moderator, type = c('density', 'histogram', 'errorbar'), .alpha = 0.7, facet = FALSE, .ncol = 1){
type <- type[1]
validate_model_(.model)
is_discrete_(moderator)
if(type %notin%c('density', 'histogram', 'errorbar')) stop('type must be either density, histogram errorbar')
# adjust moderator to match estimand
moderator <- adjust_for_estimand_(.model, moderator)
estimand <- switch (.model$estimand,
ate = 'CATE',
att = 'CATT',
atc = 'CATC'
)
# extract and rotate posterior
posterior <- bartCause::extract(.model, 'icate')
posterior <- posterior %>%
t() %>%
as.data.frame() %>%
as_tibble()
# split posterior into list of dfs by each level of moderator
split_posterior <- split(posterior, moderator)
posterior_means <- lapply(split_posterior, colMeans)
# unlist into a data.frame for plotting
dat <- data.frame(value = unlist(posterior_means))
dat$moderator <- sub("\\..*", '', rownames(dat))
rownames(dat) <- seq_len(nrow(dat))
# plot it
p <- ggplot(dat, aes(value, fill = moderator))
if(type == 'density'){
p <- p + geom_density(alpha = .alpha) +
labs(title = NULL,
x = estimand,
y = NULL) +
theme(legend.position = 'bottom')
}else if(type == 'histogram'){
p <- p +
geom_histogram(
alpha = .alpha,
col = 'black',
position = 'identity') +
labs(title = NULL,
x = estimand,
y = NULL) +
theme(legend.position = 'bottom')
} else{
# tidy up the data
dat <- dat %>%
group_by(moderator) %>%
mutate(.min = quantile(value, .025),
.max = quantile(value, .975),
point = mean(value)) %>%
dplyr::select(-value) %>%
arrange(desc(point)) %>%
ungroup() %>%
distinct()
# plot it
p <- ggplot(dat, aes(x = moderator, y = point, color = moderator)) +
geom_point(size = 2) +
geom_linerange(aes(ymin = .min, ymax = .max), alpha = .alpha) +
labs(title = NULL,
x = element_blank(),
y = estimand) +
theme(legend.position = 'bottom')
}
# add faceting
if(isTRUE(facet)){
p <- p + facet_wrap(~moderator, ncol = .ncol)
}
return(p)
}
#' @title Plot the posterior interval of the Conditional Average Treatment Effect grouped by a discrete variable
#' @description Plots the range of the Conditional Average Treatment Effect grouped by a discrete variable. This is analogous to plot_moderator_d_density but is preferable for moderators with many categories. Rather than plotting the full density, the posterior range is shown.
#'
#' @param .model a model produced by `bartCause::bartc()`
#' @param moderator the moderator as a vector
#' @param .alpha transparency value [0, 1]
#' @param horizontal flip the plot horizontal?
#'
#' @author George Perrett, Joseph Marlo
#'
#' @return ggplot object
#' @export
#'
#' @import ggplot2 dplyr
#' @importFrom bartCause extract
#'
#' @examples
#' \donttest{
#' data(lalonde)
#' confounders <- c('age', 'educ', 'black', 'hisp', 'married', 'nodegr')
#' model_results <- bartCause::bartc(
#' response = lalonde[['re78']],
#' treatment = lalonde[['treat']],
#' confounders = as.matrix(lalonde[, confounders]),
#' estimand = 'ate',
#' commonSuprule = 'none'
#' )
#' plot_moderator_d_linerange(model_results, lalonde$educ)
#' }
plot_moderator_d_linerange <- function(.model, moderator, .alpha = 0.7, horizontal = FALSE){
validate_model_(.model)
is_discrete_(moderator)
# adjust moderator to match estimand
moderator <- adjust_for_estimand_(.model, moderator)
# extract and rotate posterior
posterior <- bartCause::extract(.model, 'icate')
posterior <- posterior %>%
t() %>%
as.data.frame() %>%
as_tibble()
# split posterior into list of dfs by each level of moderator
split_posterior <- split(posterior, moderator)
posterior_means <- lapply(split_posterior, colMeans)
# unlist into a data.frame for plotting
dat <- data.frame(value = unlist(posterior_means))
dat$moderator <- sub("\\..*", '', rownames(dat))
rownames(dat) <- seq_len(nrow(dat))
# tidy up the data
dat <- dat %>%
group_by(moderator) %>%
mutate(.min = quantile(value, .025),
.max = quantile(value, .975),
point = mean(value)) %>%
dplyr::select(-value) %>%
arrange(desc(point)) %>%
ungroup() %>%
distinct()
# plot it
p <- ggplot(dat, aes(x = moderator, y = point, color = moderator)) +
geom_point(size = 2) +
geom_linerange(aes(ymin = .min, ymax = .max), alpha = .alpha) +
labs(title = NULL,
x = element_blank(),
y = 'CATE') +
theme(legend.position = 'bottom')
if (horizontal) p <- p + coord_flip()
return(p)
}
#' @title Plot a single regression tree of covariates on ICATEs
#' @description Plot a single regression tree for exploratory heterogeneous effects. Fit single regression tree on bartc() ICATEs to produce variable importance plot. This plot is useful for identifying potential moderating variables.
#' Tree depth may be set to depths 1, 2 or 3. Terminal nodes signal the Conditional Average Treatment effect within levels of moderation variables. Trees with different values across terminal nodes suggest strong treatment effect moderation.
#'
#' @param .model a model produced by `bartCause::bartc()`
#' @param max_depth one of c(1, 2, 3). Maximum number of node levels within the tree. 2 is recommended
#'
#' @author George Perrett, Joseph Marlo
#'
#' @import ggplot2 dplyr
#' @importFrom ggdendro dendro_data
#' @importFrom rpart rpart
#' @importFrom bartCause extract
#'
#' @return ggplot object
#' @export
#'
#' @examples
#' \donttest{
#' data(lalonde)
#' confounders <- c('age', 'educ', 'black', 'hisp', 'married', 'nodegr')
#' model_results <- bartCause::bartc(
#' response = lalonde[['re78']],
#' treatment = lalonde[['treat']],
#' confounders = as.matrix(lalonde[, confounders]),
#' estimand = 'ate',
#' commonSuprule = 'none'
#' )
#' plot_moderator_search(model_results)
#' }
plot_moderator_search <- function(.model, max_depth = c(2, 1, 3)){
validate_model_(.model)
max_depth <- max_depth[[1]]
if (max_depth %notin% c(2, 1, 3)) stop('max_depth must be one of c(1, 2, 3)')
icate <- bartCause::extract(.model , 'icate')
icate.m <- apply(icate, 2, mean)
# pull data from model and create a matrix of confounders
.data <- as.data.frame(.model$data.rsp@x)
# adjust data for estimand
if (.model$estimand == 'ate') {
confounders <- as.matrix(.data[, c(-1,-(length(.data)))])
} else if (.model$estimand == 'att') {
.data <- .data[.model$trt == 1,]
confounders <- as.matrix(.data[, c(-1,-(length(.data)))])
} else{
.data <- .data[.model$trt == 0,]
confounders <- as.matrix(.data[, c(-1,-(length(.data)))])
}
# fit regression tree
cart <- rpart::rpart(icate.m ~ ., data = as.data.frame(confounders), maxdepth = max_depth)
# p <- rpart.plot::rpart.plot(cart, type = 2, branch = 1, box.palette = 0)
# create dendrogram
p_gg <- rpart_ggplot_(cart)
return(p_gg)
}
rpart_ggplot_ <- function(.model){
# remove depth information from model so resulting plot is easy to read
.model$frame$dev <- 1
# extract data to construct dendrogram
fitr <- ggdendro::dendro_data(.model)
n_leaf <- .model$frame$n[.model$frame$var == '<leaf>']
n_split <- .model$frame$n[.model$frame$var != '<leaf>']
pred_split <- round(.model$frame$yval[.model$frame$var != '<leaf>'], 1)
terminal_leaf_y <- 0.1
leaf_labels <- tibble(
x = fitr$leaf_labels$x,
y = terminal_leaf_y,
label = paste0(
'y = ', fitr$leaf_labels$label,
'\nn = ', n_leaf)
)
yes_no_offset <- c(0.75, 1.25)
yes_no <- tibble(
x = c(fitr$labels$x[[1]] * yes_no_offset[1],
fitr$labels$x[[1]] * yes_no_offset[2]),
y = rep(fitr$labels$y[[1]], 2),
label = c("yes", "no")
)
split_labels <- tibble(
x = fitr$labels$x,
y = fitr$labels$y + 0.07,
label = paste0(
'y = ', pred_split,
'\nn = ', n_split
)
)
# set terminal segments to y = terminal_leaf_y
initial_node_y <- fitr$labels$y[[1]]
fitr$segments <- fitr$segments %>%
mutate(y_new = ifelse(y > yend, y, yend),
yend_new = ifelse(yend < y, yend, y)) %>%
select(n, x, y = y_new, xend, yend = yend_new) %>%
mutate(y = ifelse(y > initial_node_y, terminal_leaf_y, y),
yend = ifelse(x == xend & x == round(x) & y > yend, terminal_leaf_y, yend))
# set plot constants
label_text_size <- 3
x_limits <- c(0.5, nrow(fitr$leaf_labels) + 0.5)
y_limits <- c(min(fitr$segments$y) - 0.05,
max(fitr$segments$y) + 0.15)
# plot it
p <- ggplot() +
geom_segment(data = fitr$segments,
aes(x = x, y = y, xend = xend, yend = yend)) +
geom_label(data = yes_no,
aes(x = x, y = y, label = label),
size = label_text_size) +
geom_label(data = leaf_labels,
aes(x = x, y = y, label = label),
size = label_text_size) +
geom_label(data = split_labels,
aes(x = x, y = y, label = label),
size = label_text_size) +
geom_label(data = fitr$labels,
aes(x = x, y = y, label = label),
label.size = NA, fontface = 'bold') +
expand_limits(x = x_limits,
y = y_limits) +
scale_x_continuous(labels = NULL, breaks = NULL) +
scale_y_continuous(labels = NULL, breaks = NULL) +
labs(title = 'Exploratory heterogeneous effects',
x = NULL,
y = NULL) +
theme(panel.background = element_blank())
return(p)
}