Skip to content

add loqfl legend - #232

Merged
kartikeyakirar merged 5 commits into
mainfrom
231_shape_on_loqfl@main
May 29, 2024
Merged

add loqfl legend#232
kartikeyakirar merged 5 commits into
mainfrom
231_shape_on_loqfl@main

Conversation

@gogonzo

@gogonzo gogonzo commented May 15, 2024

Copy link
Copy Markdown
Contributor

Closes #231

Including shape parameter based on loq_flag_var value.

Install goshawk from the branch

installation code
remotes::install_github(
  "insightsengineering/goshawk", 
  ref = "231_shape_on_loqfl@main"
)
goshawk examples
pkgload::load_all("goshawk")
library(stringr)

# 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")

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(ANRLO = .5, ANRHI = 1) %>%
  rowwise() %>%
  group_by(PARAMCD) %>%
  mutate(LBSTRESC = ifelse(USUBJID %in% sample(USUBJID, 1, replace = TRUE),
    paste("<", round(runif(1, min = .5, max = .7))), LBSTRESC
  )) %>%
  mutate(LBSTRESC = ifelse(USUBJID %in% sample(USUBJID, 1, replace = TRUE),
    paste(">", round(runif(1, min = .9, max = 1.2))), LBSTRESC
  )) %>%
  ungroup()
attr(ADLB[["ARM"]], "label") <- var_labels[["ARM"]]
attr(ADLB[["ANRLO"]], "label") <- "Analysis Normal Range Lower Limit"
attr(ADLB[["ANRHI"]], "label") <- "Analysis Normal Range Upper Limit"

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

g_spaghettiplot(
  data = ADLB,
  subj_id = "USUBJID",
  biomarker_var = "PARAMCD",
  biomarker = "CRP",
  value_var = "AVAL",
  trt_group = "ARM",
  time = "AVISITCD",
  color_manual = color_manual,
  color_comb = "#39ff14",
  alpha = .02,
  xtick = c("BL", "W 1", "W 4"),
  xlabel = c("Baseline", "Week 1", "Week 4"),
  rotate_xlab = FALSE,
  group_stats = "median",
  hline_vars = c("ANRHI", "ANRLO"),
  hline_vars_colors = c("pink", "brown")
)

g_spaghettiplot(
  data = ADLB,
  subj_id = "USUBJID",
  biomarker_var = "PARAMCD",
  biomarker = "CRP",
  value_var = "AVAL",
  trt_group = "ARM",
  time = "AVISITCD",
  color_manual = color_manual,
  color_comb = "#39ff14",
  alpha = .02,
  xtick = c("BL", "W 1", "W 4"),
  xlabel = c("Baseline", "Week 1", "Week 4"),
  rotate_xlab = FALSE,
  group_stats = "median",
  hline_arb = 1.3,
  hline_vars = c("ANRHI", "ANRLO", "ULOQN", "LLOQN"),
  hline_vars_colors = c("pink", "brown", "purple", "gray")
)

g_spaghettiplot(
  data = ADLB,
  subj_id = "USUBJID",
  biomarker_var = "PARAMCD",
  biomarker = "CRP",
  value_var = "AVAL",
  trt_group = "ARM",
  time = "AVISITCDN",
  color_manual = color_manual,
  color_comb = "#39ff14",
  alpha = .02,
  xtick = c(0, 1, 4),
  xlabel = c("Baseline", "Week 1", "Week 4"),
  rotate_xlab = FALSE,
  group_stats = "median",
  hline_arb = c(.5, .7, 1),
  hline_arb_color = c("blue", "red", "green"),
  hline_arb_label = c("Arb_Hori_line_A", "Arb_Hori_line_B", "Arb_Hori_line_C"),
  hline_vars = c("ANRHI", "ANRLO")
)

# removing missing levels from the plot with facet_scales

g_spaghettiplot(
  data = ADLB,
  subj_id = "USUBJID",
  biomarker_var = "PARAMCD",
  biomarker = "CRP",
  value_var = "AVAL",
  trt_group = "ARM",
  time = "RACE",
  color_manual = color_manual,
  color_comb = "#39ff14",
  alpha = .02,
  facet_scales = "fixed",
  rotate_xlab = FALSE,
  group_stats = "median",
  hline_arb = c(.5, .7, 1),
  hline_arb_color = c("blue", "red", "green"),
  hline_arb_label = c("Arb_Hori_line_A", "Arb_Hori_line_B", "Arb_Hori_line_C"),
  hline_vars = c("ANRHI", "ANRLO")
)

g_spaghettiplot(
  data = ADLB,
  subj_id = "USUBJID",
  biomarker_var = "PARAMCD",
  biomarker = "CRP",
  value_var = "AVAL",
  trt_group = "ARM",
  time = "RACE",
  color_manual = color_manual,
  color_comb = "#39ff14",
  alpha = .02,
  facet_scales = "free_x",
  rotate_xlab = FALSE,
  group_stats = "median",
  hline_arb = c(.5, .7, 1),
  hline_arb_color = c("blue", "red", "green"),
  hline_arb_label = c("Arb_Hori_line_A", "Arb_Hori_line_B", "Arb_Hori_line_C"),
  hline_vars = c("ANRHI", "ANRLO")
)
main this
image image
image image
image image
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: 995a50f

Minimum allowed coverage is 80%

♻️ This comment has been updated with latest results

@npaszty

npaszty commented May 15, 2024

Copy link
Copy Markdown
Contributor

@gogonzo

similar comment to that which I left in PR #233

@kartikeyakirar
kartikeyakirar self-requested a review May 29, 2024 13:41

@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: test with sample code.

@kartikeyakirar
kartikeyakirar merged commit 409c91a into main May 29, 2024
@kartikeyakirar
kartikeyakirar deleted the 231_shape_on_loqfl@main branch May 29, 2024 16:58
@github-actions github-actions Bot locked and limited conversation to collaborators May 29, 2024
@npaszty

npaszty commented May 30, 2024

Copy link
Copy Markdown
Contributor

@kartikeyakirar

first, thanks for adding the LoQ legend to spaghetti plot but would it be possible to re-open this issue?

The current size of the symbols in the legend and on the lines in the spaguetti plot are too small to interpret. can you look at the other functions to see how the legend symbol size and the plot symbol size is being set and match that. thanks!

image

@kartikeyakirar

kartikeyakirar commented May 31, 2024

Copy link
Copy Markdown
Contributor

@npaszty Let me open a separate issue instead of reopening this one. I will link this issue for reference.

issue: #241

@kartikeyakirar

Copy link
Copy Markdown
Contributor

@npaszty The point size issue has been resolved and the update has been released to R-universe. The default point size is set to 3, but you can customize it by setting dot_size parameter in the function.

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.

LoQ Legend: Spaghetti Plot

3 participants