Skip to content

Change automated label on g_spaghettiplot - #247

Merged
m7pr merged 5 commits into
mainfrom
g_spaghettiplot_legend_statistic@main
Jul 24, 2024
Merged

Change automated label on g_spaghettiplot #247
m7pr merged 5 commits into
mainfrom
g_spaghettiplot_legend_statistic@main

Conversation

@m7pr

@m7pr m7pr commented Jul 22, 2024

Copy link
Copy Markdown
Contributor

This fixes issue detected in Theory app on GitLab.

image

On legend, currently we display metric phrase instead of Mean or Median. With this fix we display actual statistic name

Tested with
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 = "MEAN",
  hline_vars = c("ANRHI", "ANRLO"),
  hline_vars_colors = c("pink", "brown")
)
Mean Median

Signed-off-by: Marcin <133694481+m7pr@users.noreply.github.com>
@m7pr m7pr added the core label Jul 22, 2024
@m7pr
m7pr requested review from gogonzo and npaszty July 22, 2024 12:54
@github-actions

github-actions Bot commented Jul 22, 2024

Copy link
Copy Markdown
Contributor

✅ All contributors have signed the CLA
Posted by the CLA Assistant Lite bot.

@github-actions

github-actions Bot commented Jul 22, 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%    266-610
R/g_scatterplot.R                    130     130  0.00%    142-310
R/g_spaghettiplot.R                  101     101  0.00%    248-381
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                               1182    1182  0.00%

Diff against main

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

Results for commit: af4a335

Minimum allowed coverage is 80%

♻️ This comment has been updated with latest results

@m7pr

m7pr commented Jul 22, 2024

Copy link
Copy Markdown
Contributor Author

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

@m7pr

m7pr commented Jul 22, 2024

Copy link
Copy Markdown
Contributor Author

recheck

m7pr and others added 2 commits July 22, 2024 15:04
Signed-off-by: Marcin <133694481+m7pr@users.noreply.github.com>
@m7pr
m7pr enabled auto-merge (squash) July 22, 2024 14:04
@npaszty

npaszty commented Jul 23, 2024

Copy link
Copy Markdown
Contributor

@m7pr

I guess the change looks okay to me but I can only test in the study data context. so if you have done testing to ensure the label changes dynamically and you'd like to merge the update then I will update my environment and test the package from https://pharmaverse.r-universe.dev

@m7pr

m7pr commented Jul 24, 2024

Copy link
Copy Markdown
Contributor Author

@npaszty I added the code that I used for testing in the main comment of this issue. We can test this function using all examples from ?goshawk::g_spaghettiplot.

@gogonzo gogonzo 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.

please add a NEWS entry

@m7pr
m7pr merged commit 7890087 into main Jul 24, 2024
@m7pr
m7pr deleted the g_spaghettiplot_legend_statistic@main branch July 24, 2024 08:09
@github-actions github-actions Bot locked and limited conversation to collaborators Jul 24, 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.

3 participants