insightsengineering / goshawk

Functions that plot and summarize biomarkers/labs of interest
https://insightsengineering.github.io/goshawk/
Other
5 stars 1 forks source link

Lineplot: dodge #220

Closed npaszty closed 6 months ago

npaszty commented 6 months ago

What happened?

We observed that the dodging no longer dodges while maintaining grouping around a visit tic but instead spreads the data points evenly across the plot horizontally. this makes it difficult to interpret.

image

The dodging by default once filters are added to produce the plot looked like this when I screen shotted last Thursday

image

Also hoping we could control the step value increment with a finer step resolution (.5 instead of 1 for example) to allow fine tuning, it doesn't look like that UI element is built that way. the value passed in is c(1, 0, 10) in our case which is the default position in a range from 0 to 10.

sessionInfo()

Current: Shiny application began 4 minutes ago
LMIFfFqMwuAagRMo on ppdpaa0838-euc1.aws.science.roche.com
2024/04/08 11:47:40 AM: [rsc-session] Content GUID: 7bb9648c-75ab-4075-a021-d587f175a42e
2024/04/08 11:47:40 AM: [rsc-session] Content ID: 6254
2024/04/08 11:47:40 AM: [rsc-session] Bundle ID: 106681
2024/04/08 11:47:40 AM: [rsc-session] Job Key: LMIFfFqMwuAagRMo
2024/04/08 11:47:40 AM: Running on host: ppdpaa0838-euc1.aws.science.roche.com
2024/04/08 11:47:40 AM: Linux distribution: Ubuntu 22.04.3 LTS (jammy)
2024/04/08 11:47:40 AM: Running as user: uid=999(rstudio-connect) gid=998(rstudio-connect) groups=998(rstudio-connect)
2024/04/08 11:47:40 AM: Connect version: 2023.09.0
2024/04/08 11:47:40 AM: LANG: C.UTF-8
2024/04/08 11:47:40 AM: Working directory: /opt/rstudio-connect/mnt/app
2024/04/08 11:47:40 AM: Using R 4.2.2
2024/04/08 11:47:40 AM: R.home(): /opt/R/4.2.2/lib/R
2024/04/08 11:47:40 AM: Content will use associated Packrat library
2024/04/08 11:47:41 AM: Adding Packrat library to R_LIBS and .libPaths: /opt/rstudio-connect/mnt/app/packrat/lib/x86_64-pc-linux-gnu/4.2.2
2024/04/08 11:47:41 AM: R_LIBS: /opt/rstudio-connect/mnt/app/packrat/lib/x86_64-pc-linux-gnu/4.2.2
2024/04/08 11:47:41 AM: .libPaths(): /opt/rstudio-connect/mnt/app/packrat/lib/x86_64-pc-linux-gnu/4.2.2, /opt/R/4.2.2/lib/R/library
2024/04/08 11:47:41 AM: shiny version: 1.7.5.1
2024/04/08 11:47:41 AM: httpuv version: 1.6.12
2024/04/08 11:47:41 AM: rmarkdown version: 2.25
2024/04/08 11:47:41 AM: knitr version: 1.44
2024/04/08 11:47:41 AM: jsonlite version: 1.8.7
2024/04/08 11:47:41 AM: RJSONIO version: (none)
2024/04/08 11:47:41 AM: htmltools version: 0.5.6.1
2024/04/08 11:47:41 AM: reticulate version: (none)
2024/04/08 11:47:41 AM: Using pandoc: /opt/rstudio-connect/ext/pandoc/2.16
2024/04/08 11:47:42 AM: Using Shiny bookmarking base directory /opt/rstudio-connect/mnt/bookmarks
2024/04/08 11:47:42 AM:
2024/04/08 11:47:42 AM: Starting R with process ID: '4029224'
2024/04/08 11:47:42 AM: Shiny application starting ...
2024/04/08 11:47:45 AM: There are no scda.XXXX libraries installed, like scda.2022.
2024/04/08 11:47:45 AM: Please install an scda database to take full advantage of the scda package.
2024/04/08 11:47:45 AM: Visit https://insightsengineering.github.io/scda.2022/ for details on scda.2022 and how it can be installed.
2024/04/08 11:47:45 AM:
2024/04/08 11:47:45 AM: Attaching package: ‘shinydashboard’
2024/04/08 11:47:45 AM:
2024/04/08 11:47:45 AM: The following object is masked from ‘package:graphics’:
2024/04/08 11:47:45 AM:
2024/04/08 11:47:45 AM:     box
2024/04/08 11:47:45 AM:
2024/04/08 11:47:45 AM: Loading required package: goshawk
2024/04/08 11:47:45 AM: Loading required package: dplyr
2024/04/08 11:47:45 AM:
2024/04/08 11:47:45 AM: Attaching package: ‘dplyr’
2024/04/08 11:47:45 AM:
2024/04/08 11:47:45 AM: The following objects are masked from ‘package:stats’:
2024/04/08 11:47:45 AM:
2024/04/08 11:47:45 AM:     filter, lag
2024/04/08 11:47:45 AM:
2024/04/08 11:47:45 AM: The following objects are masked from ‘package:base’:
2024/04/08 11:47:45 AM:
2024/04/08 11:47:45 AM:     intersect, setdiff, setequal, union
2024/04/08 11:47:45 AM:
2024/04/08 11:47:45 AM: Loading required package: teal
2024/04/08 11:47:45 AM: Loading required package: teal.data
2024/04/08 11:47:45 AM: Loading required package: teal.slice
2024/04/08 11:47:45 AM: Loading required package: teal.transform
2024/04/08 11:47:46 AM:
2024/04/08 11:47:46 AM: You are using teal version 0.14.0
2024/04/08 11:47:46 AM:
2024/04/08 11:47:46 AM: Attaching package: ‘teal’
2024/04/08 11:47:46 AM:
2024/04/08 11:47:46 AM: The following objects are masked from ‘package:teal.slice’:
2024/04/08 11:47:46 AM:
2024/04/08 11:47:46 AM:     as.teal_slices, teal_slices
2024/04/08 11:47:46 AM:
2024/04/08 11:47:46 AM: Loading required package: tern
2024/04/08 11:47:46 AM: Loading required package: rtables
2024/04/08 11:47:46 AM: Loading required package: formatters
2024/04/08 11:47:47 AM: Registered S3 method overwritten by 'tern':
2024/04/08 11:47:47 AM:   method   from 
2024/04/08 11:47:47 AM:   tidy.glm broom
2024/04/08 11:47:47 AM:
2024/04/08 11:47:47 AM: Attaching package: ‘tern’
2024/04/08 11:47:47 AM:
2024/04/08 11:47:47 AM: The following object is masked from ‘package:goshawk’:
2024/04/08 11:47:47 AM:
2024/04/08 11:47:47 AM:     g_lineplot
2024/04/08 11:47:47 AM:
2024/04/08 11:47:47 AM: Loading required package: ggmosaic
2024/04/08 11:47:47 AM: Loading required package: ggplot2
2024/04/08 11:47:47 AM: Loading required package: shinyTree
2024/04/08 11:48:11 AM: Warning: There was 1 warning in `mutate()`.
2024/04/08 11:48:11 AM: ℹ In argument: `AVISITCDN = case_when(...)`.
2024/04/08 11:48:11 AM: Caused by warning:
2024/04/08 11:48:11 AM: ! NAs introduced by coercion
2024/04/08 11:48:22 AM: [INFO] 2024-04-08 11:48:22.8679 pid:4029224 token:[] teal.modules.general Initializing tm_variable_browser
2024/04/08 11:48:22 AM: [INFO] 2024-04-08 11:48:22.9126 pid:4029224 token:[] teal.modules.general Initializing tm_data_table
2024/04/08 11:48:22 AM: [INFO] 2024-04-08 11:48:22.9188 pid:4029224 token:[] teal.modules.clinical Initializing tm_t_summary
2024/04/08 11:48:22 AM: [INFO] 2024-04-08 11:48:22.9292 pid:4029224 token:[] teal.modules.clinical Initializing tm_t_events_summary
2024/04/08 11:48:22 AM: [INFO] 2024-04-08 11:48:22.9434 pid:4029224 token:[] teal.modules.clinical Initializing tm_t_events
2024/04/08 11:48:22 AM: [INFO] 2024-04-08 11:48:22.9539 pid:4029224 token:[] teal.modules.clinical Initializing tm_t_events_by_grade
2024/04/08 11:48:22 AM: [INFO] 2024-04-08 11:48:22.9665 pid:4029224 token:[] teal.modules.clinical Initializing tm_t_smq
2024/04/08 11:48:22 AM: [INFO] 2024-04-08 11:48:22.9821 pid:4029224 token:[] teal.goshawk Initializing tm_g_gh_boxplot
2024/04/08 11:48:22 AM: [INFO] 2024-04-08 11:48:22.9884 pid:4029224 token:[] teal.goshawk Initializing tm_g_gh_correlationplot
2024/04/08 11:48:22 AM: [INFO] 2024-04-08 11:48:22.9945 pid:4029224 token:[] teal.goshawk Initializing tm_g_gh_density_distribution_plot
2024/04/08 11:48:23 AM: [INFO] 2024-04-08 11:48:22.9996 pid:4029224 token:[] teal.goshawk Initializing tm_g_gh_lineplot
2024/04/08 11:48:23 AM: [INFO] 2024-04-08 11:48:23.0057 pid:4029224 token:[] teal.goshawk Initializing tm_g_gh_spaghettiplot
2024/04/08 11:48:23 AM:
2024/04/08 11:48:23 AM: Listening on http://127.0.0.1:35793
2024/04/08 11:48:30 AM: Warning in length(token_data) > 0 && !is.na(token_data) :
2024/04/08 11:48:30 AM:   'length(x) = 15 > 1' in coercion to 'logical(1)'
2024/04/08 11:48:34 AM: Warning in length(token_data) > 0 && !is.na(token_data) :
2024/04/08 11:48:34 AM:   'length(x) = 15 > 1' in coercion to 'logical(1)'
2024/04/08 11:48:34 AM: module "Report previewer" server function takes no data so "datanames" will be ignored
2024/04/08 11:48:35 AM: ✔ Writing to "app-usage".
2024/04/08 11:48:35 AM: ✔ Appending 1 row to 'Data'.
2024/04/08 11:52:12 AM: Warning in length(token_data) > 0 && !is.na(token_data) :
2024/04/08 11:52:12 AM:   'length(x) = 15 > 1' in coercion to 'logical(1)'
2024/04/08 11:52:16 AM: Warning in length(token_data) > 0 && !is.na(token_data) :
2024/04/08 11:52:16 AM:   'length(x) = 15 > 1' in coercion to 'logical(1)'
2024/04/08 11:52:16 AM: module "Report previewer" server function takes no data so "datanames" will be ignored
2024/04/08 11:52:17 AM: ✔ Writing to "app-usage".
2024/04/08 11:52:18 AM: ✔ Appending 1 row to 'Data'.

Relevant log output

see images in the description above

Code of Conduct

Contribution Guidelines

Security Policy

m7pr commented 6 months ago

Hi @npaszty I took some time today to investigate today and I can not reproduce this. What version of the R packages are you using? By sessionInfo() we aimed to get an output of sessionInfo() call just after you loaded all R libraries. The output from shiny session if not that helpful as it does not contain package versions.

I tried to reproduce the issue on

The code that I run to create the plot was taken from ?g_lineplot examples

Code ```r library(stringr) library(dplyr) library(nestcolor) # original ARM value = dose value arm_mapping <- list( "A: Drug X" = "150mg QD", "B: Placebo" = "Placebo", "C: Combination" = "Combination" ) color_manual <- c("150mg QD" = "thistle", "Placebo" = "orange", "Combination" = "steelblue") type_manual <- c("150mg QD" = "solid", "Placebo" = "dashed", "Combination" = "dotted") ADSL <- rADSL %>% filter(!(ARM == "B: Placebo" & AGE < 40)) ADLB <- rADLB ADLB <- right_join(ADLB, ADSL[, c("STUDYID", "USUBJID")]) var_labels <- lapply(ADLB, function(x) attributes(x)$label) ADLB <- ADLB %>% mutate(AVISITCD = case_when( AVISIT == "SCREENING" ~ "SCR", AVISIT == "BASELINE" ~ "BL", grepl("WEEK", AVISIT) ~ paste( "W", trimws( substr( AVISIT, start = 6, stop = str_locate(AVISIT, "DAY") - 1 ) ) ), TRUE ~ NA_character_ )) %>% mutate(AVISITCDN = case_when( AVISITCD == "SCR" ~ -2, AVISITCD == "BL" ~ 0, grepl("W", AVISITCD) ~ as.numeric(gsub("\\D+", "", AVISITCD)), TRUE ~ NA_real_ )) %>% # use ARMCD values to order treatment in visualization legend mutate(TRTORD = ifelse(grepl("C", ARMCD), 1, ifelse(grepl("B", ARMCD), 2, ifelse(grepl("A", ARMCD), 3, NA) ) )) %>% mutate(ARM = as.character(arm_mapping[match(ARM, names(arm_mapping))])) %>% mutate(ARM = factor(ARM) %>% reorder(TRTORD)) attr(ADLB[["ARM"]], "label") <- var_labels[["ARM"]] g_lineplot( label = "Line Plot", data = ADLB, biomarker_var = "PARAMCD", biomarker = "CRP", value_var = "AVAL", trt_group = "ARM", shape = NULL, time = "AVISITCDN", color_manual = color_manual, line_type = type_manual, median = FALSE, hline_arb = c(.9, 1.1, 1.2, 1.5), hline_arb_color = c("green", "red", "blue", "pink"), hline_arb_label = c("A", "B", "C", "D"), xtick = c(0, 1, 5), xlabel = c("Baseline", "Week 1", "Week 5"), rotate_xlab = FALSE, plot_height = 600 ) g_lineplot( label = "Line Plot", data = ADLB, biomarker_var = "PARAMCD", biomarker = "CRP", value_var = "AVAL", trt_group = "ARM", shape = NULL, time = "AVISITCD", color_manual = NULL, line_type = type_manual, median = TRUE, hline_arb = c(.9, 1.1, 1.2, 1.5), hline_arb_color = c("green", "red", "blue", "pink"), hline_arb_label = c("A", "B", "C", "D"), xtick = c("BL", "W 1", "W 5"), xlabel = c("Baseline", "Week 1", "Week 5"), rotate_xlab = FALSE, plot_height = 600 ) g_lineplot( label = "Line Plot", data = ADLB, biomarker_var = "PARAMCD", biomarker = "CRP", value_var = "AVAL", trt_group = "ARM", shape = NULL, time = "AVISITCD", color_manual = color_manual, line_type = type_manual, median = FALSE, hline_arb = c(.9, 1.1, 1.2, 1.5), hline_arb_color = c("green", "red", "blue", "pink"), hline_arb_label = c("A", "B", "C", "D"), xtick = c("BL", "W 1", "W 5"), xlabel = c("Baseline", "Week 1", "Week 5"), rotate_xlab = FALSE, plot_height = 600, count_threshold = 90, table_font_size = 15 ) g_lineplot( label = "Line Plot", data = ADLB, biomarker_var = "PARAMCD", biomarker = "CRP", value_var = "AVAL", trt_group = "ARM", shape = NULL, time = "AVISITCDN", color_manual = color_manual, line_type = type_manual, median = TRUE, hline_arb = c(.9, 1.1, 1.2, 1.5), hline_arb_color = c("green", "red", "blue", "pink"), hline_arb_label = c("A", "B", "C", "D"), xtick = c(0, 1, 5), xlabel = c("Baseline", "Week 1", "Week 5"), rotate_xlab = FALSE, plot_height = 600 ) g_lineplot( label = "Line Plot", data = subset(ADLB, SEX %in% c("M", "F")), biomarker_var = "PARAMCD", biomarker = "CRP", value_var = "AVAL", trt_group = "ARM", shape = "SEX", time = "AVISITCDN", color_manual = color_manual, line_type = type_manual, median = FALSE, hline_arb = c(.9, 1.1, 1.2, 1.5), hline_arb_color = c("green", "red", "blue", "pink"), hline_arb_label = c("A", "B", "C", "D"), xtick = c(0, 1, 5), xlabel = c("Baseline", "Week 1", "Week 5"), rotate_xlab = FALSE, plot_height = 1500 ) g_lineplot( label = "Line Plot", data = subset(ADLB, SEX %in% c("M", "F")), biomarker_var = "PARAMCD", biomarker = "CRP", value_var = "AVAL", trt_group = "ARM", shape = "SEX", time = "AVISITCDN", color_manual = NULL, median = FALSE, hline_arb = c(.9, 1.1, 1.2, 1.5), hline_arb_color = c("green", "red", "blue", "pink"), hline_arb_label = c("A", "B", "C", "D"), xtick = c(0, 1, 5), xlabel = c("Baseline", "Week 1", "Week 5"), rotate_xlab = FALSE, plot_height = 1500 ) ```

The output that I see is dodged

image

Does reinstallation of the package, or resizing the plot (to have wider width) fixes the issue on your side?

npaszty commented 6 months ago

@m7pr

thanks for looking into this.

FYI reported out by our in-app "About" modal. The app uses R version: R version 4.2.2 (2022-10-31) The app uses teal version: 0.14.0

I can not replicate this issue anymore in our latest deploy. Apologies for the time you spent on this. Not sure what the cause was but perhaps something overlooked in the study data.

I have closed the issue.

m7pr commented 6 months ago

Alrighty. No worries. No need to apologize. This happens and will happen and it's normal