Skip to content

Commit

Permalink
fix matching col.stderr argument when col.lci and col.uci are used
Browse files Browse the repository at this point in the history
  • Loading branch information
neilstats committed Jul 25, 2023
1 parent fd68ea7 commit c94a60d
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 11 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Title: Create CKB Plots
Description: ckbplotr provides functions to help create and style plots in R.
It is being developed by, and primarily for, China Kadoorie Biobank
researchers.
Version: 0.9.0
Version: 0.9.1
Authors@R:
person(given = "Neil",
family = "Wright",
Expand Down
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# ckbplotr 0.9.1

* Fix error when using col.lci and col.uci arguments in shape_plot() and forest_plot().

# ckbplotr 0.9.0

* `+ ckb_style()` can now be used to make a ggplot into CKB style (instead of using plot_like_ckb()).
Expand Down
15 changes: 11 additions & 4 deletions R/forest-plot.R
Original file line number Diff line number Diff line change
Expand Up @@ -220,11 +220,18 @@ forest_plot <- function(
}
col.estimate <- col.estimate[col.estimate %in% column_names_in_data][[1]]

if (length(col.stderr[col.stderr %in% column_names_in_data]) == 0) {
rlang::abort(glue::glue("Column '{col.stderr}' does not exist in panels data frame."))
if (!is.null(col.lci) | !is.null(col.uci)) {
for (x in c(col.lci, col.uci)){
if (!x %in% column_names_in_data){
rlang::abort(glue::glue("Column '{x}' does not exist in panels data frame."))
}
}
} else {
if (length(col.stderr[col.stderr %in% column_names_in_data]) == 0) {
rlang::abort(glue::glue("Column '{col.stderr}' does not exist in panels data frame."))
}
col.stderr <- col.stderr[col.stderr %in% column_names_in_data][[1]]
}
col.stderr <- col.stderr[col.stderr %in% column_names_in_data][[1]]



# Check for scale of x axis and transformation of estimates ----
Expand Down
15 changes: 12 additions & 3 deletions R/shape-plot.R
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,19 @@ shape_plot <- function(data,
}
col.estimate <- col.estimate[col.estimate %in% column_names_in_data][[1]]

if (length(col.stderr[col.stderr %in% column_names_in_data]) == 0) {
rlang::abort(glue::glue("Column '{col.stderr}' does not exist in panels data frame."))
if (!is.null(col.lci) | !is.null(col.uci)) {
for (x in c(col.lci, col.uci)){
if (!x %in% column_names_in_data){
rlang::abort(glue::glue("Column '{x}' does not exist in panels data frame."))
}
}
} else {
if (length(col.stderr[col.stderr %in% column_names_in_data]) == 0) {
rlang::abort(glue::glue("Column '{col.stderr}' does not exist in panels data frame."))
}
col.stderr <- col.stderr[col.stderr %in% column_names_in_data][[1]]
}
col.stderr <- col.stderr[col.stderr %in% column_names_in_data][[1]]




Expand Down
2 changes: 1 addition & 1 deletion man/geom_text_move.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 13 additions & 2 deletions vignettes/forest_plots.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,22 @@ my_results <- data.frame(
forest_plot(my_results)
```
Use `col.est` and `col.stderr` to set the columns that contain estimates and standard errors. By default, the function will look for columns with names estimate/est/beta/loghr and stderr/std.err/se.
Use `col.est` and `col.stderr` to set the columns that contain estimates and standard errors. By default, the function will look for columns with names estimate/est/beta/loghr and stderr/std.err/se. If you want to supply confidence interval limits, set `col.lci` and `col.uci`.
```{r, include = FALSE}
my_results2 <- data.frame(
subgroup = c("men", "women", "35_49", "50_64", "65_79"),
est = c( 0.45, 0.58, 0.09, 0.35, 0.6),
lci = c( 0.31, 0.46, -0.03, 0.25, 0.44),
uci = c( 0.59, 0.70, 0.21, 0.45, 0.76)
)
If your estimates are not on the log scale, then set `exponentiate=FALSE`.
forest_plot(my_results2,
col.lci = "lci",
col.uci = "uci")
```


If your estimates are not on the log scale, then set `exponentiate=FALSE`.



Expand Down

0 comments on commit c94a60d

Please sign in to comment.