Skip to content

Commit

Permalink
Updated plot examples for missing ggplot2 packages.
Browse files Browse the repository at this point in the history
  • Loading branch information
alexzwanenburg committed Sep 10, 2024
1 parent f5bcc99 commit f84b106
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 34 deletions.
10 changes: 7 additions & 3 deletions R/PlotQQPlot.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,13 @@
#' x = x,
#' method = "box_cox")
#'
#' plot_qq_plot(
#' x = x,
#' transformer = transformer)
#' if (rlang::is_installed("ggplot2")) {
#' plot_qq_plot(
#' x = x,
#' transformer = transformer
#' )
#' }
#'
plot_qq_plot <- function(
x,
transformer,
Expand Down
25 changes: 15 additions & 10 deletions R/PlotResidualPlot.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,23 @@
#' x <- exp(stats::rnorm(1000))
#' transformer <- find_transformation_parameters(
#' x = x,
#' method = "box_cox")
#' method = "box_cox"
#' )
#'
#' plot_residual_plot(
#' x = x,
#' transformer = transformer)
#' if (rlang::is_installed("ggplot2")) {
#' plot_residual_plot(
#' x = x,
#' transformer = transformer
#' )
#'
#' # Plot only central 80% of the data.
#' plot_residual_plot(
#' x = x,
#' transformer = transformer,
#' centre_width = 0.80,
#' show_original = FALSE)
#' # Plot only central 80% of the data.
#' plot_residual_plot(
#' x = x,
#' transformer = transformer,
#' centre_width = 0.80,
#' show_original = FALSE
#' )
#' }
plot_residual_plot <- function(
x,
transformer,
Expand Down
19 changes: 13 additions & 6 deletions R/PlotUtilities.R
Original file line number Diff line number Diff line change
@@ -1,21 +1,28 @@
.check_ggtheme <- function(ggtheme) {
.check_ggtheme <- function(ggtheme, call = rlang::caller_env()) {

# Check if the provided theme is a suitable theme.
if (inherits(ggtheme, "theme")) {

# Check if the theme is complete.
if (!attr(ggtheme, "complete")) {
stop(paste0(
"The plotting theme is not complete. The most likely cause is lack of a valid template, such as ",
"theme_familiar or ggplot2::theme_light. Note that ggplot2::theme is designed to tweak existing ",
"themes when creating a plot."))
rlang::abort(
paste0(
"The plotting theme is not complete. The most likely cause is lack of a valid template, such as ",
"theme_familiar or ggplot2::theme_light. Note that ggplot2::theme is designed to tweak existing ",
"themes when creating a plot."
),
call = call
)
}

} else if (is.null(ggtheme)) {
ggtheme <- ggplot2::theme_light(base_size = 9)

} else {
stop(paste0("The provided ggplot2 theme is not a theme. Found: ", class(ggtheme)))
rlang::abort(
paste0("The provided ggplot2 theme is not a theme. Found: ", class(ggtheme)),
call = call
)
}

return(ggtheme)
Expand Down
4 changes: 2 additions & 2 deletions R/Utilities.R
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ is_package_installed <- function(name) {



require_package <- function(x, purpose = NULL, ...) {
require_package <- function(x, purpose = NULL, call = rlang::caller_env(), ...) {

# Check whether packages are installed, without loading the
# packages.
Expand All @@ -128,7 +128,7 @@ require_package <- function(x, purpose = NULL, ...) {
ifelse(is.null(purpose), ": ", paste0(" ", purpose, ": ")),
paste_s(x), ".")

stop(message_str)
rlang::abort(message_str, call = call)
}


Expand Down
10 changes: 7 additions & 3 deletions man/plot_qq_plot.Rd

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

25 changes: 15 additions & 10 deletions man/plot_residual_plot.Rd

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

0 comments on commit f84b106

Please sign in to comment.