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

arbitrary horizontal lines to tm_g_gh_spaghettiplot #41

Merged
merged 28 commits into from
Sep 16, 2021
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
270f60a
initial fix to accommodate API change to goshawk
denisovan31415 Sep 9, 2021
cf41f4c
new select input to spaghettiplot module for horizontal lines
denisovan31415 Sep 9, 2021
148e7bc
NEWS
denisovan31415 Sep 9, 2021
f53799d
hline
denisovan31415 Sep 9, 2021
a83546d
re labeling and moving ui
denisovan31415 Sep 9, 2021
53bf300
indentation
denisovan31415 Sep 9, 2021
8c72da7
added arbitrary line label to legend
denisovan31415 Sep 9, 2021
c757587
Merge branch 'main' into 39_arb_hori_lines_spaigeitti@main
denisovan31415 Sep 10, 2021
b0ddb6d
removed unused hline parameter
denisovan31415 Sep 10, 2021
f7f0fe4
fixed empty group stat lable
denisovan31415 Sep 10, 2021
0eda77e
fixed name reference bug
denisovan31415 Sep 10, 2021
de49425
added hline_arb_color argument
denisovan31415 Sep 13, 2021
782c623
working roxygen APP with the ANRLO and ANRHI horizontal lines
denisovan31415 Sep 14, 2021
e23cc5f
docs
denisovan31415 Sep 14, 2021
a5ecb4a
fixed mass pasting error
denisovan31415 Sep 14, 2021
be9d75c
docs
denisovan31415 Sep 14, 2021
285a902
Merge branch 'main' into 39_arb_hori_lines_spaigeitti@main
denisovan31415 Sep 14, 2021
beab50e
argument reorder
denisovan31415 Sep 14, 2021
a5c3fe9
Update R/tm_g_gh_spaghettiplot.R
denisovan31415 Sep 14, 2021
fabe01f
Update R/tm_g_gh_spaghettiplot.R
denisovan31415 Sep 14, 2021
fb3325f
docs
denisovan31415 Sep 14, 2021
b61ffb7
roxygen app comment bug
denisovan31415 Sep 14, 2021
945a6c5
reorder validation code
denisovan31415 Sep 14, 2021
1f42343
updated horizontal line section labels
npaszty Sep 14, 2021
414e4e4
fixed reproducible error in roxygen app
denisovan31415 Sep 15, 2021
3f9a550
docs
denisovan31415 Sep 15, 2021
31099d8
removed random numbers in roxygen app
denisovan31415 Sep 15, 2021
4dd7e35
Revert "removed random numbers in roxygen app"
denisovan31415 Sep 15, 2021
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
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* Update examples and document using `scda` synthetic data to replace `random.cdisc.data`.
* Updated license and `README.md` with appropriate information for migration to public Github.
* Added `error_on_lint: TRUE` to `.lintr`.
* Added another select input to `tm_g_gh_spaghettiplot` to add arbitrary horizontal lines to the plot.
* Fixed bug in `tm_g_gh_boxplot` module that always uses the `AVISITCD` variable as the `Visit` Column of the table.

# teal.goshawk 0.1.9
Expand Down
119 changes: 100 additions & 19 deletions R/tm_g_gh_spaghettiplot.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
#' level of trt_group.
#' @param man_color string vector representing customized colors
#' @param color_comb name or hex value for combined treatment color.
#' @param hline numeric value to add horizontal line to plot
#' @param xtick numeric vector to define the tick values of x-axis
#' when x variable is numeric. Default value is waive().
#' @param xlabel vector with same length of xtick to define the
Expand All @@ -35,6 +34,10 @@
#' @param plot_width optional, controls plot width.
#' @param font_size control font size for title, x-axis, y-axis and legend font.
#' @param group_stats control group mean or median overlay.
#' @param hline_arb_color a character naming the color for the arbitrary horizontal line
#' @param hline_vars a character vector to name the columns that will define additional horizontal lines.
#' @param hline_vars_colors a character vector equal in length to hline_vars that will define the colors.
#' @param hline_vars_labels a character vector equal in length to hline_vars that will define the legend labels.
#' @inheritParams teal.devel::standard_layout
#'
#' @import goshawk
Expand All @@ -53,7 +56,7 @@
#' library(dplyr)
#' library(scda)
#'
#' # original ARM value = dose value
#' original ARM value = dose value
#' arm_mapping <- list("A: Drug X" = "150mg QD",
#' "B: Placebo" = "Placebo",
#' "C: Combination" = "Combination")
Expand All @@ -80,9 +83,17 @@
#' ARM = as.character(arm_mapping[match(ARM, names(arm_mapping))]),
#' ARM = factor(ARM) %>% reorder(TRTORD),
#' ACTARM = as.character(arm_mapping[match(ACTARM, names(arm_mapping))]),
#' ACTARM = factor(ACTARM) %>% reorder(TRTORD))
#' ACTARM = factor(ACTARM) %>% reorder(TRTORD),
#' ANRLO = 30,
#' ANRHI = 75)
#' attr(ADLB[["ARM"]], "label") <- var_labels[["ARM"]]
#' attr(ADLB[["ACTARM"]], 'label') <- var_labels[["ACTARM"]]
#' attr(ADLB[["ANRLO"]], "label") <- "Analysis Normal Range Lower Limit"
#' attr(ADLB[["ANRHI"]], "label") <- "Analysis Normal Range Upper Limit"
#'
#' #' add LLOQ and ULOQ variables
denisovan31415 marked this conversation as resolved.
Show resolved Hide resolved
#' ALB_LOQS <- goshawk:::h_identify_loq_values(ADLB)
#' ADLB <- left_join(ADLB, ALB_LOQS, by = "PARAM")
#'
#' app <- teal::init(
#' data = cdisc_data(
Expand Down Expand Up @@ -112,11 +123,17 @@
#' ARM = as.character(arm_mapping[match(ARM, names(arm_mapping))]),
#' ARM = factor(ARM) %>% reorder(TRTORD),
#' ACTARM = as.character(arm_mapping[match(ACTARM, names(arm_mapping))]),
#' ACTARM = factor(ACTARM) %>% reorder(TRTORD))
#' ACTARM = factor(ACTARM) %>% reorder(TRTORD),
#' ANRLO = 30,
#' ANRHI = 75)
#' attr(ADLB[['ARM']], 'label') <- var_labels[['ARM']]
#' attr(ADLB[['ACTARM']], 'label') <- var_labels[['ACTARM']]",
#' attr(ADLB[['ACTARM']], 'label') <- var_labels[['ACTARM']]
#' attr(ADLB[['ANRLO']], 'label') <- 'Analysis Normal Range Lower Limit'
#' attr(ADLB[['ANRHI']], 'label') <- 'Analysis Normal Range Upper Limit'
#' ALB_LOQS <- goshawk:::h_identify_loq_values(ADLB)
#' ADLB <- left_join(ADLB, ALB_LOQS, by = 'PARAM')",
#' vars = list(arm_mapping = arm_mapping)),
#' check = TRUE
#' check = TRUE
#' ),
#' modules = root_modules(
#' tm_g_gh_spaghettiplot(
Expand All @@ -133,7 +150,10 @@
#' color_comb = "#39ff14",
#' man_color = c('Combination' = "#000000",
#' 'Placebo' = "#fce300",
#' '150mg QD' = "#5a2f5f")
#' '150mg QD' = "#5a2f5f"),
#' hline_vars = c("ANRHI", "ANRLO"),
#' hline_vars_colors = c("pink", "brown"),
#' hline_vars_labels = NULL
#' )
#' )
#' )
Expand All @@ -156,7 +176,6 @@ tm_g_gh_spaghettiplot <- function(label,
trt_group,
trt_group_level = NULL,
group_stats = "NONE",
hline = NULL,
man_color = NULL,
color_comb = NULL,
xtick = waiver(),
Expand All @@ -166,9 +185,30 @@ tm_g_gh_spaghettiplot <- function(label,
plot_height = c(600, 200, 2000),
plot_width = NULL,
font_size = c(12, 8, 20),
hline_arb_color = "red",
hline_vars = NULL,
hline_vars_colors = NULL,
hline_vars_labels = NULL,
pre_output = NULL,
post_output = NULL) {

if (!is.null(hline_vars)) {
stopifnot(is_character_vector(hline_vars, min_length = 1))
if (!is.null(hline_vars_labels)) {
stopifnot(is_character_vector(
hline_vars_labels, min_length = length(hline_vars),
max_length = (length(hline_vars)))
)
}
if (!is.null(hline_vars_colors)) {
stopifnot(is_character_vector(
hline_vars_colors,
min_length = length(hline_vars),
max_length = (length(hline_vars)))
)
}
}

Comment on lines +218 to +234
Copy link
Contributor

Choose a reason for hiding this comment

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

also, it makes sense to validate arguments in the order as they are in function definition so those should be right after validations on plot_width

Copy link
Contributor Author

Choose a reason for hiding this comment

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

implemented

stopifnot(is.choices_selected(param))
stopifnot(is.choices_selected(xaxis_var))
stopifnot(is.choices_selected(yaxis_var))
Expand All @@ -193,8 +233,11 @@ tm_g_gh_spaghettiplot <- function(label,
param_var_label = param_var_label,
xtick = xtick,
xlabel = xlabel,
hline_arb_color = hline_arb_color,
plot_height = plot_height,
plot_width = plot_width
plot_width = plot_width,
hline_vars_colors = hline_vars_colors,
hline_vars_labels = hline_vars_labels
),
ui = g_ui_spaghettiplot,
ui_args = args,
Expand Down Expand Up @@ -229,7 +272,41 @@ g_ui_spaghettiplot <- function(id, ...) {
ns("group_stats"),
"Group Statistics",
c("None" = "NONE", "Mean" = "MEAN", "Median" = "MEDIAN"),
inline = TRUE),
inline = TRUE
),
if (!is.null(a$hline_vars)) {
optionalSelectInput(
ns("hline_vars"),
label = "Add Horizontal Range Line(s):",
choices = a$hline_vars,
selected = a$hline_vars[1],
multiple = TRUE)
},
div(
style = "display: flex",
div(
style = "padding: 0px;",
div(
style = "display: inline-block;vertical-align:moddle; width: 100%;",
tags$b("Line:")
),
div(
style = "display: inline-block;vertical-align:middle; width: 100%;",
numericInput(ns("hline"), "", a$hline)
)
),
gogonzo marked this conversation as resolved.
Show resolved Hide resolved
div(
style = "padding: 0px;",
div(
style = "display: inline-block;vertical-align:moddle; width: 100%;",
tags$b("Label:")
),
div(
style = "display: inline-block;vertical-align:middle; width: 100%;",
textInput(ns("hline_label"), "", "")
)
)
),
templ_ui_constraint(ns), # required by constr_anl_chunks
toggle_slider_ui(
ns("yrange_scale"),
Expand All @@ -247,12 +324,6 @@ g_ui_spaghettiplot <- function(id, ...) {
numericInput(ns("facet_ncol"), "", a$facet_ncol, min = 1))
),
checkboxInput(ns("rotate_xlab"), "Rotate X-Axis Label", a$rotate_xlab),
div(style = "padding: 0px;",
div(style = "display: inline-block;vertical-align:moddle; width: 175px;",
tags$b("Add a Horizontal Line:")),
div(style = "display: inline-block;vertical-align:middle; width: 100px;",
numericInput(ns("hline"), "", a$hline))
),
optionalSliderInputValMinMax(ns("font_size"), "Font Size", a$font_size, ticks = FALSE),
optionalSliderInputValMinMax(
ns("alpha"),
Expand Down Expand Up @@ -286,7 +357,10 @@ srv_g_spaghettiplot <- function(input,
xtick,
xlabel,
plot_height,
plot_width) {
plot_width,
hline_vars_colors,
hline_vars_labels,
hline_arb_color) {
init_chunks()
# reused in all modules
anl_chunks <- constr_anl_chunks(
Expand All @@ -306,6 +380,7 @@ srv_g_spaghettiplot <- function(input,
facet_ncol <- input$facet_ncol
rotate_xlab <- input$rotate_xlab
hline <- input$hline
hline_label <- input$hline_label
group_stats <- input$group_stats
font_size <- input$font_size
alpha <- input$alpha
Expand All @@ -318,6 +393,7 @@ srv_g_spaghettiplot <- function(input,
param <- input$xaxis_param
xaxis_var <- input$xaxis_var
yaxis_var <- input$yaxis_var
hline_vars <- input$hline_vars
# nolint end
chunks_push(
chunks = private_chunks,
Expand All @@ -338,13 +414,18 @@ srv_g_spaghettiplot <- function(input,
color_comb = .(color_comb),
ylim = .(ylim),
facet_ncol = .(facet_ncol),
hline = .(`if`(is.na(hline), NULL, as.numeric(hline))),
hline_arb = .(`if`(is.na(hline), NULL, as.numeric(hline))),
hline_arb_label = .(`if`(is.na(hline), NULL, hline_label)),
hline_arb_color = .(hline_arb_color),
xtick = .(xtick),
xlabel = .(xlabel),
rotate_xlab = .(rotate_xlab),
font_size = .(font_size),
alpha = .(alpha),
group_stats = .(group_stats)
group_stats = .(group_stats),
hline_vars = .(hline_vars),
hline_vars_colors = .(hline_vars_colors[seq_along(hline_vars)]),
hline_vars_labels = .(hline_vars_labels[seq_along(hline_vars)])
)
print(p)
})
Expand Down
1 change: 1 addition & 0 deletions inst/WORDLIST
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ ggplot
gh
github
gshawk
hline
Copy link
Contributor

Choose a reason for hiding this comment

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

you shouldn't have to add technical names in the wordlist exceptions - any technical name should be wrapped up in "`"

Copy link
Contributor

Choose a reason for hiding this comment

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

okay, whatever the right way to do this

https
init
inputId
Expand Down
44 changes: 35 additions & 9 deletions man/tm_g_gh_spaghettiplot.Rd

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