-
Notifications
You must be signed in to change notification settings - Fork 10
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
base: main
Are you sure you want to change the base?
783 profile plots #792
Changes from all commits
cda0dc8
90c763b
2444592
289bdcd
f4941c8
4f176a3
3e6f6e6
239af9e
b86c6ea
851fbbf
c16c9ef
cbf6cad
eb647bb
469d310
0ac12f1
d1d91ef
7b5d17f
efdc192
b9e51b0
4ae3a06
2697a01
9a79da7
d0cfe55
e7e9ff6
383bccd
b2ba80b
4a87aec
5de72ff
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -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"), | ||||||||||||
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)])), | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we might need to work with
Suggested change
etc. to avoid |
||||||||||||
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
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
and in the arguments of this method
so that the user can keep defaults, or modify this |
||||||||||||
scale_color_manual( | ||||||||||||
values = c( | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would keep the
|
||||||||||||
|
||||||||||||
p | ||||||||||||
} | ||||||||||||
) | ||||||||||||
|
||||||||||||
## DataDual ---- | ||||||||||||
|
||||||||||||
#' Plot Method for the [`DataDual`] Class | ||||||||||||
|
There was a problem hiding this comment.
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
?