Skip to content

Commit 59d85b0

Browse files
authored
v0.10.1
2 parents 54a40fb + 6e552d4 commit 59d85b0

File tree

6 files changed

+37
-4
lines changed

6 files changed

+37
-4
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Title: Create CKB Plots
33
Description: ckbplotr provides functions to help create and style plots in R.
44
It is being developed by, and primarily for, China Kadoorie Biobank
55
researchers.
6-
Version: 0.10.0
6+
Version: 0.10.1
77
Authors@R:
88
person(given = "Neil",
99
family = "Wright",

NEWS.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# ckbplotr 0.10.1
2+
3+
* Fix xlab and column headings when xlim is a list in forest_plot().
4+
15
# ckbplotr 0.10.0
26

37
* Added ggpreview() and preview argument in save_figure().

R/forest-plot-list-xlim.R

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ forest_plot_list_xlim <- function(call){
55
xlim <- eval(call$xlim)
66
xticks <- eval(call$xticks)
77
panels <- eval(call$panels)
8+
xlab <- eval(call$xlab)
9+
col.left.heading <- eval(call$col.left.heading)
10+
col.right.heading <- eval(call$col.right.heading)
811

912
## check arguments
1013
if (!is.list(xlim) | !is.list(xticks) | !is.list(panels)){
@@ -14,6 +17,19 @@ forest_plot_list_xlim <- function(call){
1417
rlang::abort("panels, xlim and xticks must be lists of the same length")
1518
}
1619

20+
## make lists
21+
xlab <- as.list(xlab)
22+
if (length(xlab) < length(xlim)){
23+
xlab <- rep(xlab, length(xlim))
24+
}
25+
if (!is.list(col.left.heading)){
26+
col.left.heading <- rep(list(col.left.heading), length(xlim))
27+
}
28+
if (!is.list(col.right.heading)){
29+
col.right.heading <- rep(list(col.right.heading), length(xlim))
30+
}
31+
32+
1733
## create arguments for plot.margin and mid.space
1834
plot.margin <- eval(call$plot.margin)
1935
if (is.null(plot.margin)){
@@ -39,6 +55,16 @@ forest_plot_list_xlim <- function(call){
3955
plot.margin = plot_margin,
4056
quiet = TRUE)
4157

58+
if (!is.null(xlab[i]) && length(xlab) > 0){
59+
update_args$xlab <- xlab[[i]]
60+
}
61+
if (!is.null(col.left.heading[i])){
62+
update_args$col.left.heading <- col.left.heading[[i]]
63+
}
64+
if (!is.null(col.right.heading[i])){
65+
update_args$col.right.heading <- col.right.heading[[i]]
66+
}
67+
4268
forest <- do.call("forest_plot",
4369
utils::modifyList(call, update_args))
4470

R/forest-plot.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ forest_plot <- function(
126126
col.right = NULL,
127127
col.right.parse = FALSE,
128128
col.left.heading = "",
129-
col.right.heading = xlab,
129+
col.right.heading = as.list(xlab),
130130
col.left.pos = NULL,
131131
col.right.pos = NULL,
132132
col.left.hjust = 1,

man/forest_plot.Rd

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vignettes/forest_plots.Rmd

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,10 @@ forest <- forest_plot(split(my_resultsAB, ~ analysis),
261261
xlim = list(c(0.5, 3 + 1e-10),
262262
c(0.1, 4)),
263263
xticks = list(c(0.5, 1, 2, 3),
264-
c(0.1, 1, 2, 4)))
264+
c(0.1, 1, 2, 4)),
265+
xlab = c("Hazard Ratio (95% CI)", "Odds Ratio (95% CI)"),
266+
col.right.heading = list("HR (95% CI)", "OR (95% CI)"))
267+
grid::grid.newpage()
265268
grid::grid.draw(forest$figure)
266269
```
267270

0 commit comments

Comments
 (0)