forked from ddsjoberg/gtsummary
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added plotting method for reg and uvreg objects (ddsjoberg#825)
* added plotting method for reg and uvreg objects * Update plot.R * doc updates
- Loading branch information
Showing
7 changed files
with
96 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#' Plot Regression Coefficients | ||
#' | ||
#' The `plot()` function extracts `x$table_body` and passes the it to | ||
#' `GGally::ggcoef_plot()` along with a formatting options. | ||
#' | ||
#' \lifecycle{experimental} | ||
#' @param x 'tbl_regression' or 'tbl_uvregression' object | ||
#' @param remove_header_rows logical indicating whether to remove header rows | ||
#' for categorical variables. Default is `TRUE` | ||
#' @param remove_reference_rows logical indicating whether to remove reference rows | ||
#' for categorical variables. Default is `FALSE`. | ||
#' @param ... arguments passed to `GGally::ggcoef_plot(...)` | ||
#' | ||
#' @return a ggplot | ||
#' @name plot | ||
#' | ||
#' @examples | ||
#' if (requireNamespace("GGally")) | ||
#' glm(response ~ marker + grade, trial, family = binomial) %>% | ||
#' tbl_regression( | ||
#' add_estimate_to_reference_rows = TRUE, | ||
#' exponentiate = TRUE | ||
#' ) %>% | ||
#' plot() | ||
NULL | ||
|
||
#' @rdname plot | ||
#' @export | ||
plot.tbl_regression <- function(x, | ||
remove_header_rows = TRUE, | ||
remove_reference_rows = FALSE, ...) { | ||
assert_package("GGally", fn = "plot.tbl_regression()", version = "2.1.0") | ||
|
||
df_coefs <- x$table_body | ||
if (isTRUE(remove_header_rows)) | ||
df_coefs <- df_coefs %>% filter(!.data$header_row %in% TRUE) | ||
if (isTRUE(remove_reference_rows)) | ||
df_coefs <- df_coefs %>% filter(!.data$reference_row %in% TRUE) | ||
|
||
df_coefs %>% | ||
GGally::ggcoef_plot(exponentiate = x$inputs$exponentiate, ...) | ||
} | ||
|
||
#' @rdname plot | ||
#' @export | ||
plot.tbl_uvregression <- plot.tbl_regression |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -93,6 +93,7 @@ reference: | |
- add_q | ||
- add_significance_stars | ||
- add_vif | ||
- plot | ||
|
||
- title: Inline Reporting | ||
- contents: | ||
|