# Report-specific parameters
template: plotTemplate.Rmd
templatePackage: clinDataReview
reportTitle: "Laboratory shift plots"
reportTitleLevel: 2
split_by: 4

# Dataset of interest
dataFileName: lb.xpt
dataProcessing:
  - annotate:
    - dataset: dm
      vars: ["RFXSTDTC", "ARM", "ARMCD"]
    - vars: LBCAT
      varFct: 'ifelse(LBCAT == "", "Not Coded", LBCAT)'
    - vars: VISIT
      varFct: reorder(VISIT, VISITNUM)
    # combine parameter name and unit
    - vars: LBTESTSP
      varLabel: "Lab Test (Standard Units)"
      varFct: paste0(LBTEST, " (", LBSTRESU, ")")
    # add baseline value in separated column
    - vars: BASE
      varsBy: ["USUBJID", "LBTESTSP"]
      varFct: LBSTRESN
      filters:
        - var: LBBLFL
          value: "Y"
      varLabel: "Baseline value"
    # format reference range
    - vars: LBNRIND
      varFct: 'factor(ifelse(is.na(LBNRIND), "UNKNOWN", LBNRIND), levels = c("LOW", "NORMAL", "HIGH", "ABNORMAL", "UNKNOWN"))'

  - filter:
    # safety analysis set: treated-patients
    - var: "RFXSTDTC" 
      value: ""
      rev: true

# Looping parameters
loopingVar: ["LBCAT", "LBTESTSP"]

# Plot parameters
plotFunction: "scatterplotClinData"
plotParams:
  title: "Actual value versus baseline value"
  xVar: "BASE"
  yVar: "LBSTRESN"
  aesPointVar:
    colour: "ARM"
    fill: "ARM"
    shape: "LBNRIND"
  aesLineVar:
    group: "USUBJID"
  refLinePars:
    - yintercept: "LBSTNRLO"
      colour: "lightblue"
    - yintercept: "LBSTNRHI"
      colour: "darkblue"
    - intercept: 0
      slope: 1
      colour:  "grey"
      label: ""
  scalePars:
    - aesthetic: shape
      values: !r-lazy clinUtils::getPaletteCDISC(x = dataI$LBNRIND, var = "NRIND", type = "shape")
  themePars:
      legend.position: "none"
  hoverVars: ["USUBJID", "VISIT", "LBDY", "BASE", "LBSTRESN", "LBNRIND", "LBSTNRLO", "LBSTNRHI"]
  tableVars: ["LBCAT", "LBTESTSP", "USUBJID", "VISIT", "LBDY", "BASE", "LBSTRESN", "LBNRIND", "LBSTNRLO", "LBSTNRHI"]
