Skip to content

Commit

Permalink
fix s3 method
Browse files Browse the repository at this point in the history
  • Loading branch information
hillalex committed Oct 23, 2024
1 parent d211dc0 commit 873b6d8
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 22 deletions.
29 changes: 15 additions & 14 deletions R/plot.R
Original file line number Diff line number Diff line change
Expand Up @@ -66,42 +66,43 @@ plot_data <- function(data, covariates) {

#' Plot method for "biokinetics_population_trajectories" class
#'
#' @param trajectories An object of class "biokinetics_population_trajectories". These are
#' generated by running biokinetics$simulate_populate_trajectories().
#' @param data Optional data.table containing raw data as provided to the
#' biokinetics model.
#' @seealso
#' [`bioikinetics$simulate_populate_trajectories`][biokinetics#method-simulate_populate_trajectories]
#' @param x An object of class "biokinetics_population_trajectories". These are
#' generated by running biokinetics$simulate_populate_trajectories(). See
#' \href{../../epikinetics/html/biokinetics.html#method-biokinetics-simulate_population_trajectories}{\code{biokinetics$simulate_population_trajectories()}}
#' @param \dots Further arguments passed to the method. For now the only extra argument supported is "data", which should be
#' a data.table containing raw data as provided to the biokinetics model.
#' @export
plot.biokinetics_population_trajectories <- function(trajectories, ..., data = NULL) {
if (!attr(trajectories, "summarised")) {
by <- setdiff(colnames(trajectories), c("t0_pop", "tp_pop", "ts_pop",
plot.biokinetics_population_trajectories <- function(x, ...) {
if (!attr(x, "summarised")) {
by <- setdiff(colnames(x), c("t0_pop", "tp_pop", "ts_pop",
"m1_pop", "m2_pop", "m3_pop",
".draw", "mu"))
trajectories <- summarise_draws(
trajectories, column_name = "mu", by = by)
x <- summarise_draws(
x, column_name = "mu", by = by)

Check warning on line 81 in R/plot.R

View check run for this annotation

Codecov / codecov/patch

R/plot.R#L76-L81

Added lines #L76 - L81 were not covered by tests
}
args <- list(...)

Check warning on line 83 in R/plot.R

View check run for this annotation

Codecov / codecov/patch

R/plot.R#L83

Added line #L83 was not covered by tests
# Declare variables to suppress notes when compiling package
# https://github.com/Rdatatable/data.table/issues/850#issuecomment-259466153
time_since_last_exp <- value <- me <- titre_type <- lo <- hi <- NULL
day <- last_exp_day <- NULL

Check warning on line 87 in R/plot.R

View check run for this annotation

Codecov / codecov/patch

R/plot.R#L86-L87

Added lines #L86 - L87 were not covered by tests

plot <- ggplot(trajectories) +
plot <- ggplot(x) +
geom_line(aes(x = time_since_last_exp, y = me, colour = titre_type)) +
geom_ribbon(aes(x = time_since_last_exp,
ymin = lo,
ymax = hi,
fill = titre_type), alpha = 0.5)

Check warning on line 94 in R/plot.R

View check run for this annotation

Codecov / codecov/patch

R/plot.R#L89-L94

Added lines #L89 - L94 were not covered by tests

if (!is.null(data)) {
if (!is.null(args$data)) {
data <- args$data
validate_required_cols(data)
plot <- plot +
geom_point(data = data,
aes(x = as.integer(day - last_exp_day, units = "days"),
y = value), size = 0.5, alpha = 0.5)

Check warning on line 102 in R/plot.R

View check run for this annotation

Codecov / codecov/patch

R/plot.R#L96-L102

Added lines #L96 - L102 were not covered by tests
}
plot + scale_y_continuous(trans = "log2") +
facet_wrap(eval(parse(text = facet_formula(attr(trajectories, "covariates"))))) +
facet_wrap(eval(parse(text = facet_formula(attr(x, "covariates"))))) +
guides(fill = guide_legend(title = "Titre type"), colour = "none")

Check warning on line 106 in R/plot.R

View check run for this annotation

Codecov / codecov/patch

R/plot.R#L104-L106

Added lines #L104 - L106 were not covered by tests
}

Expand Down
14 changes: 6 additions & 8 deletions man/plot.biokinetics_population_trajectories.Rd

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

0 comments on commit 873b6d8

Please sign in to comment.