## ----include = FALSE----------------------------------------------------------
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.height = 5,
  fig.width = 8,
  fig.align = "center"
)

## ----message = FALSE----------------------------------------------------------
library(summarySCI)
data(hemoglobin_data)

hb <- hemoglobin_data
hb$hb_cat <- cut(hb$hb, c(-Inf, 120, 140, Inf),
                 labels = c("< 120", "120-140", "> 140"))

## ----message = FALSE, warning = FALSE-----------------------------------------
res <- summarizeByVisitSCI(hb, vars = c("hb", "hb_cat"), group = "Arm",
                           visit = "visit", order = "visit_nr",
                           stat_cont = "median_IQR",
                           labels = list(hb_cat = "Hemoglobin category"),
                           plot_args = list(risk_table = TRUE,
                                            group_names_short = c("A", "B")))
res$table

## -----------------------------------------------------------------------------
res$plots$hb
res$plots$hb_cat

## ----message = FALSE, warning = FALSE-----------------------------------------
res_box <- summarizeByVisitSCI(hb, vars = "hb", group = "Arm",
                               visit = "visit", order = "visit_nr",
                               stat_cont = "mean_sd", plot_cont = "boxplot",
                               plot_args = list(cex_axis = 0.8))
res_box$plots$hb

## -----------------------------------------------------------------------------
basename(save_plots(res, file_name = "visit", file_path = tempdir(),
                    width = 9, height = 5.5))

