Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

783 profile plots #792

Open
wants to merge 28 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
cda0dc8
adding .csv files containing SAS results
marlenesg Feb 1, 2023
90c763b
Comparing posterior summaries (2-parameter-logistic model) and recomm…
marlenesg Feb 14, 2023
2444592
Comparing posterior summaries (2-parameter-logistic model) and recomm…
marlenesg Feb 14, 2023
289bdcd
solving merge conflict
marlenesg Feb 14, 2023
f4941c8
miscellaneous
marlenesg Feb 14, 2023
4f176a3
miscellaneous style updates
marlenesg Feb 14, 2023
3e6f6e6
Resolved merge conflict
marlenesg Feb 21, 2023
239af9e
Code styled (variable names etc.)
marlenesg Feb 23, 2023
b86c6ea
renamed test file
marlenesg Feb 23, 2023
851fbbf
changed back to original file
marlenesg Feb 23, 2023
c16c9ef
split each data example in a separate test_that() call
marlenesg Mar 14, 2023
cbf6cad
simplification by replacing unnecessary lists with vectors
marlenesg Mar 15, 2023
eb647bb
changed paths and updated description file
marlenesg Mar 15, 2023
469d310
reduced the number of mcmc samples
marlenesg Mar 23, 2023
0ac12f1
Added skip_on_cran() to the tests
marlenesg May 4, 2023
d1d91ef
Added skip_on_cran() to the tests
marlenesg May 4, 2023
7b5d17f
added another example setting for comparison of crmPack results to SA…
marlenesg Jun 1, 2023
efdc192
resolve merge conflict
marlenesg Jun 1, 2023
b9e51b0
resolve merge conflict
marlenesg Jun 1, 2023
4ae3a06
minor style fixes
marlenesg Jun 1, 2023
2697a01
Merge branch 'main' into test-sas-results
marlenesg Jun 15, 2023
9a79da7
Merge 2697a012c55f129dbeda275f0589908eb5c7c318 into b038c62a234d4fe51…
marlenesg Jun 15, 2023
d0cfe55
[skip actions] Restyle files
github-actions[bot] Jun 15, 2023
e7e9ff6
miscellaneous
marlenesg Jun 20, 2023
383bccd
added profiles plot in Data-methods
marlenesg Feb 6, 2024
b2ba80b
Merge branch 'main' into 783-profile-plots
marlenesg Feb 9, 2024
4a87aec
Merge b2ba80b7a0a675d93f25f6c9569fe44f2ada8b66 into 0c6a60f8c68598352…
marlenesg Feb 9, 2024
5de72ff
[skip actions] Restyle files
github-actions[bot] Feb 9, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
113 changes: 113 additions & 0 deletions R/Data-methods.R
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,119 @@ setMethod(
}
)

## Data ----

#' Plot Method for the [`Data`] Class
#'
#' A method that creates a profile plot for [`Data`] object.
#'
#' @param x (`Data`)\cr object we want to plot, which includes all evaluable subjects.
#' @param x_NE A data.frame, which includes all non-evaluable subjects.
#' @param unit A string specifying the dose unit used in the trials, for example "mg/kg".
#'
#' @return The [`ggplot2`] object.
#'
#' @examples
#' \dontrun{
#' dose_grid <- c(10, 15, 30, 45, 60, 80)
#' unit <- "mg/kg"
#' ## Specify the observed data
#' data <- Data(
#' x = c(rep(10, 3), rep(15, 3), rep(30, 3)),
#' y = c(rep(0, 3), rep(0, 2), 1, rep(0, 2), 1),
#' cohort = c(rep(1, 3), rep(2, 3), rep(3, 3)),
#' doseGrid = dose_grid,
#' ID = 1:9
#' )
#' ## Specify the NON-evaluable data
#' ## (if none, set data_NE <- data.frame(NULL))
#' data_NE <- data.frame(
#' IDs = 10,
#' doses = 30,
#' dlts = 2,
#' cohorts = 3
#' )
#'
#' plot(
#' x = data,
#' x_NE = data_NE,
#' unit = unit
#' )
#' }
#' @source This function uses \code{ggplot} function from \code{ggplot2}
#' R package.
#' @export
setGeneric(
name = "profiles",
def = function(x, xNE, unit, ...) {
standardGeneric("profiles")
}
)
setMethod(
f = "profiles",
signature = signature(x = "Data", xNE = "data.frame", unit = "character"),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how about another name instead of xNE ? e.g. x_not_eval?

definition = function(x, xNE, unit, ...) {
ID <- c(x@ID, xNE$IDs)
dose <- c(x@x, xNE$doses)
cohort <- c(x@cohort, xNE$cohorts)
DLT <- c(x@y, xNE$dlts)

df <- data.frame(
"ID" = ID,
"dose" = dose,
"DLT" = factor(DLT,
levels = c("0", "1", "2"),
labels = c("DLT No", "DLT Yes", "Not evaluable")
),
"cohort" = paste("Cohort", cohort)
)
df <- df[order(df$ID), ]

p <- ggplot(data = df) +
geom_point(
aes(
x = factor(ID, levels = unique(ID[order(cohort, ID)])),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we might need to work with

Suggested change
x = factor(ID, levels = unique(ID[order(cohort, ID)])),
x = factor(.data$ID, levels = unique(.data$ID[order(.data$cohort, .data$ID)])),

etc. to avoid R CMD check notes about missing global variables, please double check the R CMD check output

y = dose,
shape = DLT,
color = DLT
),
size = 2
) +
scale_shape_manual(values = c(
"DLT No" = 19, "DLT Yes" = 17,
"Not evaluable" = 0
), drop = FALSE) +
Comment on lines +174 to +177
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would recommend making this configurable by the user, i.e. here:

Suggested change
scale_shape_manual(values = c(
"DLT No" = 19, "DLT Yes" = 17,
"Not evaluable" = 0
), drop = FALSE) +
scale_shape_manual(values = scale_shape_values, drop = FALSE) +

and in the arguments of this method

scale_shape_values = c(
        "DLT No" = 19, "DLT Yes" = 17,
        "Not evaluable" = 0
      )

so that the user can keep defaults, or modify this

scale_color_manual(
values = c(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same idea also here

"DLT No" = "black",
"DLT Yes" = "red",
"Not evaluable" = "blue"
),
drop = FALSE
) +
scale_x_discrete(breaks = df$ID, labels = sort(df$ID)) +
scale_y_continuous(
limits = c(0, max(x@doseGrid)),
breaks = x@doseGrid,
labels = x@doseGrid
) +
facet_wrap(. ~ cohort, strip.position = "bottom", scales = "free_x") +
ggtitle("DLT Profile Plot") +
xlab("Subject IDs") +
ylab(paste0("Dose (", unit, ")")) +
theme_bw() +
theme(plot.title = element_text(hjust = 0.5)) +
theme(legend.title = element_blank()) +
theme(
legend.background = element_blank(),
legend.box.background = element_rect(colour = "black"),
axis.text.x = element_text(angle = 45, hjust = 1)
)
Comment on lines +196 to +203
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would keep the theme modifiable by the user.
options:

  • completely omit this here to just use the default theme
  • if that does not look ok, then define a theme_profiles function that returns this and in this method have argument theme = theme_profiles() that is then used here, but the user could modify it


p
}
)

## DataDual ----

#' Plot Method for the [`DataDual`] Class
Expand Down