# Aesthetics

#### Michela Pasetto and Laure Cougnaud

#### March 03, 2023

The `inTextSummaryTable` contains functionalities to set palettes up.

The palettes for visualization are retrieved from the `clinUtils` package, whereas the palettes for the tables are defined in the `inTextSummaryTable` itself.

Moreover, palettes are set through global options.

This has the main advantage that if you wish to change the default palettes, it is possible to set your preferences only once at the beginning of the R script or Rmd document.

When loading the package, the global options for palettes get automatically defined into the R session. If you wish to change the default color scheme, you can apply your preferences by changing the global options.

Below, we present what options are available and how to customize them.

# 1 Available options

The `inTextSummaryTable` package has the following options:

- `inTextSummaryTable.colors.table.presentation`

- `inTextSummaryTable.pageDim.presentation`

- `inTextSummaryTable.colors.plot`

- `inTextSummaryTable.shapes.plot`

- `inTextSummaryTable.linetypes.plot`

The options with the wording colors.table.presentation and pageDim.presentation define the color scheme for tables and the dimensions of the page in a presentation, respectively.

Instead, the options with colors.plot, shapes.plot and linetype.plot set up the palettes for the visualization functionalities.

Note that the options have to be defined after loading the package. This because when loading the package, the default global options for palettes will overwrite the custom palettes.

In this way, you can see how the options are visible after loading the package:

    library(inTextSummaryTable)

    # options for color scheme in in presentations
    options("inTextSummaryTable.colors.table.presentation")

    ## $inTextSummaryTable.colors.table.presentation
    ##                    header          headerBackground headerBackgroundHighlight                      body           bodyBackground1           bodyBackground2
    ##                 "#FFFFFF"               "#32648EFF"               "#287D8EFF"                 "#000000"                 "#D9D9D9"                 "#D9D9D9"
    ##  bodyBackgroundHighlight1  bodyBackgroundHighlight2                    footer          footerBackground                      line
    ##               "#DCE318FF"               "#DCE318FF"                 "#000000"                 "#FFFFFF"                 "#FFFFFF"

    # options for colors in plots: viridis palette
    options("inTextSummaryTable.colors.plot")

    ## $inTextSummaryTable.colors.plot
    ## function (n, alpha = 1, begin = 0, end = 1, direction = 1, option = "D")
    ## {
    ##     if (begin < 0 | begin > 1 | end < 0 | end > 1) {
    ##         stop("begin and end must be in [0,1]")
    ##     }
    ##     if (abs(direction) != 1) {
    ##         stop("direction must be 1 or -1")
    ##     }
    ##     if (n == 0) {
    ##         return(character(0))
    ##     }
    ##     if (direction == -1) {
    ##         tmp <- begin
    ##         begin <- end
    ##         end <- tmp
    ##     }
    ##     option <- switch(EXPR = option, A = "A", magma = "A", B = "B",
    ##         inferno = "B", C = "C", plasma = "C", D = "D", viridis = "D",
    ##         E = "E", cividis = "E", F = "F", rocket = "F", G = "G",
    ##         mako = "G", H = "H", turbo = "H", {
    ##             warning(paste0("Option '", option, "' does not exist. Defaulting to 'viridis'."))
    ##             "D"
    ##         })
    ##     map <- viridisLite::viridis.map[viridisLite::viridis.map$opt ==
    ##         option, ]
    ##     map_cols <- grDevices::rgb(map$R, map$G, map$B)
    ##     fn_cols <- grDevices::colorRamp(map_cols, space = "Lab",
    ##         interpolate = "spline")
    ##     cols <- fn_cols(seq(begin, end, length.out = n))/255
    ##     grDevices::rgb(cols[, 1], cols[, 2], cols[, 3], alpha = alpha)
    ## }
    ## <bytecode: 0x55713cbab280>
    ## <environment: namespace:viridisLite>

    # options for shapes in plots
    options("inTextSummaryTable.shapes.plot")

    ## $inTextSummaryTable.shapes.plot
    ##  [1] 21 22 23 24 25  0  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 17 18 19

    # options for linetypes in plots
    options("inTextSummaryTable.linetypes.plot")

    ## $inTextSummaryTable.linetypes.plot
    ## [1] "solid"    "dashed"   "dotdash"  "twodash"  "dotted"   "longdash"

# 2 Options for reporting

In this section we discuss the options for reporting, namely the `inTextSummaryTable.colors.table.presentation` and `inTextSummaryTable.pageDim.presentation`.

## 2.1 Colors

By default, the reporting format makes tables with a black text on a white background.

On the contrary, the presentation format creates tables with a blue header and white text, whereas the body is grey with black text.

Below a demonstration for a dummy data set.

    # default report style
    getSummaryStatisticsTable(
        data = data.frame(USUBJID = c(1, 2)),
        style = "report"
    )

Statistic | StatisticValue (N=2)
--- | ---
statN | 2
statm | 2
statPercTotalN | 2
statPercN | 100

    # default presentation style
    getSummaryStatisticsTable(
        data = data.frame(USUBJID = c(1, 2)),
        style = "presentation"
    )

Statistic | StatisticValue (N=2)
--- | ---
statN | 2
statm | 2
statPercTotalN | 2
statPercN | 100

If you wish to define a personal color scheme, a named vector can be created and passed to the `options`, as shown below.

Colors can be provided in hexadecimals or in `rgb` specification. In the example we use hexadecimals just for convenience.

Note that the `bodyBackground1` and `bodyBackground2` allow to have alternating row colors.

    # create named vector
    customColorTable <- c(
        # black text in the header
        'header' = "#000000",
        # green background in the header
        'headerBackground' = "#74D055FF",
        # black text in the body
        'body' = "#000000",
        # yellow background for all rows
        'bodyBackground1' = "#FDE725FF",
        'bodyBackground2' = "#FDE725FF",
        # black footer
        'footer' = "#000000",
        # white footer background
        'footerBackground' = "#FFFFFF",
        # black line for footer
        'line' = "#000000"
    )
    # set options
    options(inTextSummaryTable.colors.table.presentation = customColorTable)
    # create the table
    getSummaryStatisticsTable(
        data = data.frame(USUBJID = c(1, 2)),
        style = "presentation"
    )

Statistic | StatisticValue (N=2)
--- | ---
statN | 2
statm | 2
statPercTotalN | 2
statPercN | 100

## 2.2 Dimension of the page

By default, the `inTextSummaryTable` ships with a default PowerPoint in the standard 4:3 size (7.5 x 10 inches).

However, it is often common to create a PowerPoint template with Widescreen size of 16:9 which consistts of 7.50 x 13.32 inches.

Therefore, it possible to accomodate such widescreen size by providing

    # default page dimension of a powerpoint created with Rmd
    getOption("inTextSummaryTable.pageDim.presentation")

    ## [1]  7.5 10.0

    # set custom dimension of page for presentation
    # in this example, the dimension is the widescreen size
    pageDimCustom <- c(7.5, 13.32)
    options(inTextSummaryTable.pageDim.presentation = pageDimCustom)
    getOption("inTextSummaryTable.pageDim.presentation")

    ## [1]  7.50 13.32

# 3 Options for visualization

The defaults palettes for visualization are retrieved from the `clinUtils` package.

If you wish to know more about those palettes, we refer to the vignette of `clinUtils` available with

    vignette("clinUtils-vignette", "clinUtils")

Below a demonstration with a dummy data set.

    # default colors, shapes and linetypes
    summaryTable <- data.frame(
        visit = c(1, 2, 1, 2),
        TRT = c("A", "A", "B", "B"),
        statMean = rnorm(4)
    )
    subjectProfileSummaryPlot(
        data = summaryTable,
        xVar = "visit",
        colorVar = "TRT"
    )

For the visualization, the same spirit of the tables applies. The user can specify a vector of colors, shapes or linetypes. The vector do not necessarly have to be named.

    # specify colors
    options(inTextSummaryTable.colors.plot = c("red", "green"))
    subjectProfileSummaryPlot(
        data = summaryTable,
        xVar = "visit",
        colorVar = "TRT"
    )

    # specify shape
    options(inTextSummaryTable.shapes.plot = c("circle", "square"))
    subjectProfileSummaryPlot(
        data = summaryTable,
        xVar = "visit",
        colorVar = "TRT"
    )

    # specify linetypes
    options(inTextSummaryTable.linetypes.plot = c("dotdash", "longdash"))
    subjectProfileSummaryPlot(
        data = summaryTable,
        xVar = "visit",
        colorVar = "TRT"
    )

# 4 Set back default palettes

There is always to possibility to switch back to the default palettes of the package:

    options(inTextSummaryTable.colors.table.presentation = tableColorsPresentation)
    options(inTextSummaryTable.colors.plot = clinUtils::clinColors)
    options(inTextSummaryTable.shapes.plot = clinUtils::clinShapes)
    options(inTextSummaryTable.linetypes.plot = clinUtils::clinLinetypes)

# 5 Set up specific palettes

# 6 Page dimensions in report/presentation

The function `getDimPage` extracts dimensions available for a content in a report or presentation, e.g. to specify the maximal width of a figure in A4 report or for a presentation.

    # a4 format with one 1 inch margin
    getDimPage(type = "width", style = "report")

    ## [1] 6.267717

    getDimPage(type = "height", style = "report")

    ## [1] 9.692913

    # Presentation format (according to template) with one 1 inch margin
    getDimPage(type = "width", style = "presentation")

    ## [1] 11.32

    getDimPage(type = "height", style = "presentation")

    ## [1] 5.5

# 7 Appendix

## 7.1 Session information

R version 4.2.2 (2022-10-31)

Platform: x86_64-pc-linux-gnu (64-bit)

locale: LC_CTYPE=en_US.UTF-8, LC_NUMERIC=C, LC_TIME=en_US.UTF-8, LC_COLLATE=C, LC_MONETARY=en_US.UTF-8, LC_MESSAGES=en_US.UTF-8, LC_PAPER=en_US.UTF-8, LC_NAME=C, LC_ADDRESS=C, LC_TELEPHONE=C, LC_MEASUREMENT=en_US.UTF-8 and LC_IDENTIFICATION=C

attached base packages: tools, stats, graphics, grDevices, utils, datasets, methods and base

other attached packages: pander(v.0.6.5), clinUtils(v.0.1.4), inTextSummaryTable(v.3.3.0) and knitr(v.1.42)

loaded via a namespace (and not attached): sass(v.0.4.5), jsonlite(v.1.8.4), viridisLite(v.0.4.1), bslib(v.0.4.2), shiny(v.1.7.4), askpass(v.1.1), highr(v.0.10), fontLiberation(v.0.1.0), yaml(v.2.3.7), ggrepel(v.0.9.3), gdtools(v.0.3.1), pillar(v.1.8.1), glue(v.1.6.2), uuid(v.1.1-0), digest(v.0.6.31), promises(v.1.2.0.1), colorspace(v.2.1-0), cowplot(v.1.1.1), htmltools(v.0.5.4), httpuv(v.1.6.9), plyr(v.1.8.8), gfonts(v.0.2.0), fontBitstreamVera(v.0.1.1), pkgconfig(v.2.0.3), httpcode(v.0.3.0), haven(v.2.5.1), xtable(v.1.8-4), scales(v.1.2.1), later(v.1.3.0), officer(v.0.6.0), fontquiver(v.0.2.1), tibble(v.3.1.8), openssl(v.2.0.5), generics(v.0.1.3), farver(v.2.1.1), ggplot2(v.3.4.1), ellipsis(v.0.3.2), DT(v.0.27), cachem(v.1.0.7), withr(v.2.5.0), cli(v.3.6.0), magrittr(v.2.0.3), crayon(v.1.5.2), mime(v.0.12), memoise(v.2.0.1), evaluate(v.0.20), fansi(v.1.0.4), forcats(v.1.0.0), xml2(v.1.3.3), textshaping(v.0.3.6), data.table(v.1.14.8), hms(v.1.1.2), lifecycle(v.1.0.3), stringr(v.1.5.0), flextable(v.0.8.6), munsell(v.0.5.0), zip(v.2.2.2), compiler(v.4.2.2), jquerylib(v.0.1.4), systemfonts(v.1.0.4), rlang(v.1.0.6), grid(v.4.2.2), htmlwidgets(v.1.6.1), crosstalk(v.1.2.0), labeling(v.0.4.2), rmarkdown(v.2.20), gtable(v.0.3.1), curl(v.5.0.0), reshape2(v.1.4.4), R6(v.2.5.1), dplyr(v.1.1.0), fastmap(v.1.1.1), utf8(v.1.2.3), ragg(v.1.2.5), stringi(v.1.7.12), crul(v.1.3), Rcpp(v.1.0.10), vctrs(v.0.5.2), tidyselect(v.1.2.0) and xfun(v.0.37)