diff --git a/DESCRIPTION b/DESCRIPTION index d437032..f525630 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -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", diff --git a/NEWS.md b/NEWS.md index 34ded34..1d7a595 100644 --- a/NEWS.md +++ b/NEWS.md @@ -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()). diff --git a/R/forest-plot.R b/R/forest-plot.R index 6be3b2a..da3fbc3 100644 --- a/R/forest-plot.R +++ b/R/forest-plot.R @@ -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 ---- diff --git a/R/shape-plot.R b/R/shape-plot.R index 883462a..c92ca5b 100644 --- a/R/shape-plot.R +++ b/R/shape-plot.R @@ -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]] + diff --git a/man/geom_text_move.Rd b/man/geom_text_move.Rd index 4f4be93..63024f9 100644 --- a/man/geom_text_move.Rd +++ b/man/geom_text_move.Rd @@ -50,7 +50,7 @@ stat stripped of the \code{stat_} prefix (e.g. \code{"count"} rather than \code{"stat_count"})} \item{position}{Position adjustment, either as a string, or the result of -a call to a position adjustment function. Cannot be jointy specified with +a call to a position adjustment function. Cannot be jointly specified with \code{nudge_x} or \code{nudge_y}.} \item{...}{Other arguments passed on to \code{\link[ggplot2:layer]{layer()}}. These are diff --git a/vignettes/forest_plots.Rmd b/vignettes/forest_plots.Rmd index e110f80..2348917 100644 --- a/vignettes/forest_plots.Rmd +++ b/vignettes/forest_plots.Rmd @@ -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`.