Skip to content

Commit

Permalink
move title text in training error plot via ModelSpec's new plot_title…
Browse files Browse the repository at this point in the history
…_line attribute
  • Loading branch information
lgessl committed Jan 17, 2024
1 parent 61050aa commit d2900a4
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
8 changes: 8 additions & 0 deletions R/model_spec.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ new_ModelSpec <- function(
create_directory,
plot_fname,
plot_ncols,
plot_title_line,
fit_fname
){
stopifnot(is.character(name))
Expand All @@ -31,6 +32,7 @@ new_ModelSpec <- function(
stopifnot(is.numeric(time_cutoffs) || is.null(time_cutoffs))
stopifnot(is.character(plot_fname))
stopifnot(is.numeric(plot_ncols))
stopifnot(is.numeric(plot_title_line) || is.null(plot_title_line))
stopifnot(is.character(fit_fname))

model_spec_list <- list(
Expand All @@ -49,6 +51,7 @@ new_ModelSpec <- function(
"create_directory" = create_directory,
"plot_fname" = plot_fname,
"plot_ncols" = plot_ncols,
"plot_title_line" = plot_title_line,
"fit_fname" = fit_fname
)
return(structure(model_spec_list, class = "ModelSpec"))
Expand Down Expand Up @@ -101,6 +104,9 @@ new_ModelSpec <- function(
#' @param plot_fname string. Store the plot resulting from `plot(fit_obj)` in `directory`
#' under this name. Default is `"training_error.pdf"`.
#' @param plot_ncols integer. The number of columns in the plot. Default is `2`.
#' @param plot_title_line numeric or NULL. Pass this as the `line` argument to [`graphics::title()`]
#' after calling `plot(fit_obj)`. This is the distance (in inches) between the title text and
#' the upper limit of the figure. Default is `2.5`.
#' @param fit_fname string. The name of the model-fits file inside `directory`.
#' Default is `"fit_obj.rds"`.
#' @return A ModelSpec S3 object.
Expand All @@ -127,6 +133,7 @@ ModelSpec <- function(
create_directory = TRUE,
plot_fname = "training_error.pdf",
plot_ncols = 2,
plot_title_line = 2.5,
fit_fname = "fit_obj.rds"
){
response_type <- match.arg(response_type)
Expand All @@ -147,6 +154,7 @@ ModelSpec <- function(
create_directory = create_directory,
plot_fname = plot_fname,
plot_ncols = plot_ncols,
plot_title_line = plot_title_line,
fit_fname = fit_fname
)
return(model_spec)
Expand Down
2 changes: 1 addition & 1 deletion R/prepare_and_fit.R
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ prepare_and_fit <- function(
split_name <- paste0(data_spec$split_col_prefix, i)
fit <- fits[[split_name]]
plot(fit)
graphics::title(main = paste0("Split ", i))
graphics::title(main = paste0("Split ", i), line = model_spec$plot_title_line)
}
grDevices::dev.off()

Expand Down
5 changes: 5 additions & 0 deletions man/ModelSpec.Rd

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

0 comments on commit d2900a4

Please sign in to comment.