Skip to content

fix vline_vars display - #233

Merged
kartikeyakirar merged 4 commits into
mainfrom
230_display_vline@main
May 29, 2024
Merged

fix vline_vars display#233
kartikeyakirar merged 4 commits into
mainfrom
230_display_vline@main

Conversation

@gogonzo

@gogonzo gogonzo commented May 15, 2024

Copy link
Copy Markdown
Contributor

closes #230

installation code
remotes::install_github(
  "insightsengineering/goshawk", 
  ref = "230_display_vline@main"
)
Example graph
pkgload::load_all("goshawk")
library(stringr)
library(tidyr)

# original ARM value = dose value
arm_mapping <- list(
  "A: Drug X" = "150mg QD",
  "B: Placebo" = "Placebo",
  "C: Combination" = "Combination"
)
color_manual <- c("150mg QD" = "#000000", "Placebo" = "#3498DB", "Combination" = "#E74C3C")
# assign LOQ flag symbols: circles for "N" and triangles for "Y", squares for "NA"
shape_manual <- c("N" = 1, "Y" = 2, "NA" = 0)

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",
        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)) %>%
  mutate(
    ANRHI = case_when(
      PARAMCD == "ALT" ~ 60,
      PARAMCD == "CRP" ~ 11,
      PARAMCD == "IGA" ~ 80,
      TRUE ~ NA_real_
    ),
    ANRLO = case_when(
      PARAMCD == "ALT" ~ 20,
      PARAMCD == "CRP" ~ 7,
      PARAMCD == "IGA" ~ 40,
      TRUE ~ NA_real_
    )
  ) %>%
  rowwise() %>%
  group_by(PARAMCD) %>%
  mutate(LBSTRESC = ifelse(
    USUBJID %in% sample(USUBJID, 1, replace = TRUE),
    paste("<", round(runif(1, min = 25, max = 30))), LBSTRESC
  )) %>%
  mutate(LBSTRESC = ifelse(
    USUBJID %in% sample(USUBJID, 1, replace = TRUE),
    paste(">", round(runif(1, min = 70, max = 75))), LBSTRESC
  )) %>%
  ungroup()
attr(ADLB[["ARM"]], "label") <- var_labels[["ARM"]]
attr(ADLB[["ANRHI"]], "label") <- "Analysis Normal Range Upper Limit"
attr(ADLB[["ANRLO"]], "label") <- "Analysis Normal Range Lower Limit"

# add LLOQ and ULOQ variables
ADLB_LOQS <- goshawk:::h_identify_loq_values(ADLB, flag_var = "LOQFL")
ADLB <- left_join(ADLB, ADLB_LOQS, by = "PARAM")

# given the 2 param and 2 analysis vars we need to transform the data
plot_data_t1 <- ADLB %>%
  gather(
    ANLVARS, ANLVALS, PARAM, LBSTRESC, BASE2, BASE, AVAL, BASE, LOQFL,
    ANRHI, ANRLO, ULOQN, LLOQN
  ) %>%
  mutate(ANL.PARAM = ifelse(ANLVARS %in% c("PARAM", "LBSTRESC", "LOQFL"),
    paste0(ANLVARS, "_", PARAMCD),
    paste0(ANLVARS, ".", PARAMCD)
  )) %>%
  select(USUBJID, ARM, ARMCD, AVISITN, AVISITCD, ANL.PARAM, ANLVALS) %>%
  spread(ANL.PARAM, ANLVALS)

# the transformed analysis value variables are character and need to be converted to numeric for
# ggplot
# remove records where either of the analysis variables are NA since they will not appear on the
# plot and will ensure that LOQFL = NA level is removed
plot_data_t2 <- plot_data_t1 %>%
  filter(!is.na(BASE.CRP) & !is.na(AVAL.ALT)) %>%
  mutate_at(vars(contains(".")), as.numeric) %>%
  mutate(
    LOQFL_COMB = ifelse(LOQFL_CRP == "Y" | LOQFL_ALT == "Y", "Y", "N")
  )


g_correlationplot(
  label = "Correlation Plot",
  data = plot_data_t2,
  param_var = "PARAMCD",
  xaxis_param = c("CRP"),
  xaxis_var = "AVAL",
  xvar = "AVAL.CRP",
  yaxis_param = c("ALT"),
  yaxis_var = "BASE",
  yvar = "BASE.ALT",
  trt_group = "ARM",
  visit = "AVISITCD",
  visit_facet = TRUE,
  loq_legend = TRUE,
  unit = "AVALU",
  title_text = "Correlation of ALT to CRP",
  xaxis_lab = "CRP",
  yaxis_lab = "ALT",
  color_manual = color_manual,
  shape_manual = shape_manual,
  facet_ncol = 4,
  facet = FALSE,
  facet_var = "ARM",
  reg_line = FALSE,
  vline_vars = c("ANRHI.CRP", "ANRLO.CRP", "ULOQN.CRP", "LLOQN.CRP"),
  vline_vars_colors = c("yellow", "orange", "brown", "gold"),
  vline_vars_labels = c("ANRHI CRP Label", "ANRLO CRP Label", "ULOQN CRP Label", "LLOQN CRP Label"),
  rotate_xlab = FALSE,
  font_size = 14,
  dot_size = 2,
  reg_text_size = 3
)
main this
image image

@github-actions

github-actions Bot commented May 15, 2024

Copy link
Copy Markdown
Contributor

badge

Code Coverage Summary

Filename                           Stmts    Miss  Cover    Missing
-------------------------------  -------  ------  -------  ---------
R/g_boxplot.R                        116     116  0.00%    147-310
R/g_correlationplot.R                135     135  0.00%    251-419
R/g_density_distribution_plot.R       86      86  0.00%    125-236
R/g_lineplot.R                       275     275  0.00%    262-606
R/g_scatterplot.R                    130     130  0.00%    142-310
R/g_spaghettiplot.R                  102     102  0.00%    243-376
R/geom_axes_line.R                   167     167  0.00%    46-358
R/t_summarytable.R                   102     102  0.00%    87-224
R/utils.R                             70      70  0.00%    17-137
TOTAL                               1183    1183  0.00%

Diff against main

Filename      Stmts    Miss  Cover
----------  -------  ------  --------
TOTAL             0       0  +100.00%

Results for commit: 2557bf5

Minimum allowed coverage is 80%

♻️ This comment has been updated with latest results

@npaszty

npaszty commented May 15, 2024

Copy link
Copy Markdown
Contributor

the change looks very small.
not sure how to test this without establishing some infrastructure for testing like what we used to do: docker, staged dependencies etc. which I don't have time to do. or is there an easy way to test this now?

@npaszty npaszty mentioned this pull request May 15, 2024
@gogonzo

gogonzo commented May 16, 2024

Copy link
Copy Markdown
Contributor Author

the change looks very small.
not sure how to test this without establishing some infrastructure for testing like what we used to do: docker, staged dependencies etc. which I don't have time to do. or is there an easy way to test this now?

Some way to install this is to:

  • clone repo on your instance (ocean),
  • checkout branch,
  • install from local,
  • then run the app

Or you can investigate example goshawk examples and confirm that issue on @main is addressed here.

Alternatively, we can review this within a team, merge it, deploy main to r-univers and then ask you to upgrade package from r-universe.

@npaszty

npaszty commented May 28, 2024

Copy link
Copy Markdown
Contributor

@gogonzo

thanks for the explanations. I like the last one "Alternatively, we can review this within a team, merge it, deploy main to r-univers and then ask you to upgrade package from r-universe." 😄

@gogonzo gogonzo added the core label May 29, 2024
@kartikeyakirar
kartikeyakirar self-requested a review May 29, 2024 13:39
@kartikeyakirar kartikeyakirar self-assigned this May 29, 2024
@donyunardi

donyunardi commented May 29, 2024

Copy link
Copy Markdown
Contributor

@kartikeyakirar @gogonzo

Internally, we have Non-Validated-Dev that pulls from main branch. If @npaszty can't install this from the branch, then we can merge the PR and have Nick install this from Non-Validated-Dev/latest.

This way, we don't need to do any release.

@github-actions

github-actions Bot commented May 29, 2024

Copy link
Copy Markdown
Contributor

CLA Assistant Lite bot ✅ All contributors have signed the CLA

@cicdguy

cicdguy commented May 29, 2024

Copy link
Copy Markdown
Contributor

I have read the CLA Document and I hereby sign the CLA

@kartikeyakirar kartikeyakirar left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM: tested with code

@kartikeyakirar
kartikeyakirar merged commit 5ce89eb into main May 29, 2024
@kartikeyakirar
kartikeyakirar deleted the 230_display_vline@main branch May 29, 2024 16:53
@github-actions github-actions Bot locked and limited conversation to collaborators May 29, 2024
@kartikeyakirar

Copy link
Copy Markdown
Contributor

@npaszty bugs are fixed and it is available in r-universe now.

@npaszty

npaszty commented May 30, 2024

Copy link
Copy Markdown
Contributor

@kartikeyakirar

the horizontal/vertical and LLOQN/ULOQN functionality seems to be working well now. thanks!

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.

Horizontal/Vertical Range Lines: Correlation Plot

5 participants