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

Calculate density ranges based on treatment name and based on AVICITCD for density plot #308

Merged
merged 2 commits into from
Sep 18, 2024

Conversation

m7pr
Copy link
Contributor

@m7pr m7pr commented Sep 17, 2024

Fixes insightsengineering/goshawk#192

For proper density calculations, you need to calculate ranges within groups inside the plot. Groups are created based on treatment variable and based on AVICITCD plot. So the max ranges need to be calculated in each group, and the max needs to be extracted.

Set filters to: ADSL -> SEX -> Male, ADSL -> AGE -> 31.41, 35

How it looked before

image

How it looks now

image

Example code

Example from `?tm_g_gh_density_distribution_plot`
pkgload::load_all("../teal.widgets")
pkgload::load_all("../teal")
pkgload::load_all(".")

data <- teal_data()
data <- within(data, {
  library(dplyr)
  library(stringr)
  
  # original ARM value = dose value
  arm_mapping <- list(
    "A: Drug X" = "150mg QD",
    "B: Placebo" = "Placebo",
    "C: Combination" = "Combination"
  )
  ADSL <- rADSL
  ADLB <- rADLB
  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", str_extract(AVISIT, "(?<=(WEEK ))[0-9]+")),
        TRUE ~ as.character(NA)
      ),
      AVISITCDN = case_when(
        AVISITCD == "SCR" ~ -2,
        AVISITCD == "BL" ~ 0,
        grepl("W", AVISITCD) ~ as.numeric(gsub("[^0-9]*", "", AVISITCD)),
        TRUE ~ as.numeric(NA)
      ),
      AVISITCD = factor(AVISITCD) %>% reorder(AVISITCDN),
      TRTORD = case_when(
        ARMCD == "ARM C" ~ 1,
        ARMCD == "ARM B" ~ 2,
        ARMCD == "ARM A" ~ 3
      ),
      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)
    )
  
  attr(ADLB[["ARM"]], "label") <- var_labels[["ARM"]]
  attr(ADLB[["ACTARM"]], "label") <- var_labels[["ACTARM"]]
})

datanames <- c("ADSL", "ADLB")
datanames(data) <- datanames
join_keys(data) <- default_cdisc_join_keys[datanames]

app <- init(
  data = data,
  modules = modules(
    tm_g_gh_density_distribution_plot(
      label = "Density Distribution Plot",
      dataname = "ADLB",
      param_var = "PARAMCD",
      param = choices_selected(c("ALT", "CRP", "IGA"), "ALT"),
      xaxis_var = choices_selected(c("AVAL", "BASE", "CHG", "PCHG"), "AVAL"),
      trt_group = choices_selected(c("ARM", "ACTARM"), "ARM"),
      color_manual = c(
        "150mg QD" = "#000000",
        "Placebo" = "#3498DB",
        "Combination" = "#E74C3C"
      ),
      color_comb = "#39ff14",
      comb_line = TRUE,
      plot_height = c(500, 200, 2000),
      font_size = c(12, 8, 20),
      line_size = c(1, .25, 3),
      hline_arb = c(.02, .05),
      hline_arb_color = c("red", "black"),
      hline_arb_label = c("Horizontal Line A", "Horizontal Line B")
    )
  )
)
if (interactive()) {
  shinyApp(app$ui, app$server)
}

@m7pr m7pr added the core label Sep 17, 2024
@m7pr m7pr requested a review from donyunardi September 17, 2024 12:59
Copy link
Contributor

github-actions bot commented Sep 17, 2024

badge

Code Coverage Summary

Filename                                 Stmts    Miss  Cover    Missing
-------------------------------------  -------  ------  -------  ---------
R/tm_g_gh_boxplot.R                        352     352  0.00%    175-594
R/tm_g_gh_correlationplot.R                555     555  0.00%    227-891
R/tm_g_gh_density_distribution_plot.R      279     279  0.00%    135-464
R/tm_g_gh_lineplot.R                       565     565  0.00%    161-820
R/tm_g_gh_scatterplot.R                    245     245  0.00%    144-441
R/tm_g_gh_spaghettiplot.R                  315     315  0.00%    194-590
R/toggleable_slider.R                      154     154  0.00%    72-243
R/utils-arbitrary_lines.r                  125     125  0.00%    19-176
R/utils-data_constraints.r                 190     190  0.00%    2-257
R/utils-keep_range_slider_updated.r         29      29  0.00%    9-45
R/utils-maptrt.r                             9       9  0.00%    24-36
R/utils-templ_ui.r                          48      48  0.00%    2-73
R/utils.R                                   49      49  0.00%    12-112
R/zzz.R                                      2       2  0.00%    2-3
TOTAL                                     2917    2917  0.00%

Diff against main

Filename                                 Stmts    Miss  Cover
-------------------------------------  -------  ------  --------
R/tm_g_gh_density_distribution_plot.R       +1      +1  +100.00%
R/utils-keep_range_slider_updated.r         +6      +6  +100.00%
TOTAL                                       +7      +7  +100.00%

Results for commit: ae19dbb

Minimum allowed coverage is 80%

♻️ This comment has been updated with latest results

Copy link
Contributor

@donyunardi donyunardi left a comment

Choose a reason for hiding this comment

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

Looks good!

There several linting issues in CI/CD but all seems small.
Feel free to fix and merge once addressed.

@m7pr m7pr enabled auto-merge (squash) September 18, 2024 09:14
@m7pr m7pr merged commit dbbe6d9 into main Sep 18, 2024
25 checks passed
@m7pr m7pr deleted the 192_adjust_ylim@main branch September 18, 2024 15:48
@github-actions github-actions bot locked and limited conversation to collaborators Sep 18, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Adjust ylim to display a complete plot
2 participants