MonolixSuite in R
Auto Light Dark
Auto Light Dark

plotCovariates

[Monolix - PKanalix] Generate Covariate plots

Plot the covariates.

Usage

R
plotCovariates(
  covariatesRows = NULL,
  covariatesColumns = NULL,
  settings = list(),
  preferences = list(),
  stratify = list()
)

Arguments

covariatesRows

vector with the name of covariates to display on rows (by default the first 4 covariates are displayed).

covariatesColumns

vector with the name of covariates to display on columns (by default the first 4 covariates are displayed).

settings

List with the following settings

  • regressionLine (logical) If TRUE, Add regression line in scatterplots (default TRUE).

  • spline (logical) If TRUE, Add xpline in scatterplots (default FALSE).

  • histogramColors (vector) List of colors to use in histograms plots.

  • histogramPosition (character) Type of histogram: "stacked", "grouped" or "default" (histograms with categorical covariates in xaxis the plot is grouped else it is stacked), (Default is "default")

  • legend (logical) add (TRUE) / remove (FALSE) plot legend (default FALSE).

  • grid (logical) add (TRUE) / remove (FALSE) plot grid (default TRUE).

  • ncol (integer) number of columns when facet = TRUE (default 4).

  • bins (integer) number of bins for the histogram (default 10)

  • fontsize (integer) Plot text font size.

preferences

(optional) preferences for plot display, run getPlotPreferences("plotCovariates") to check available displays.

stratify

List with the stratification arguments:

  • groups - Definition of stratification groups. By default, stratification groups are already defined as one group for each category for categorical covariates, and two groups of equal number of individuals for continuous covariates. To redefine groups, for each covariate to redefine, specify a list with:

    name

    character

    covariate name (e.g "AGE")

    definition

    (vector(continuous) || list>(categorical))

    For continuous covariates, vector of break values (e.g c(35, 65)). For categorical covariates, groups of categories as a list of vectors(e.g list(c("study101"), c("study201","study202")))

  • split (vector) - Vector of covariates used to split (i.e facet) the plot (by default no split is applied). For instance c("FORM","AGE").

  • filter (list< list> >) - List of pairs containing a covariate name and the vector of indexes or categories (for categorical covariates) of the groups to keep (by default no filtering is applied). For instance, list("AGE",c(1,3)) to keep the individuals belonging to the first and third age group, according to the definition in groups. For instance, list("FORM","ref") using the category name for categorical covariates.

  • color (vector) - Vector of covariates used for coloring (by default no coloring is applied). For instance c("FORM","AGE").

  • colors - Vector of colors to use when color argument is used. Takes precedence over colors defined in preferences. For instance c("#ebecf0","#cdced1","#97989c").

  • individualSelection - Ids to display (by default the 12 first ids are displayed) defined as:

    • indices (vector) - Indices of the individuals to display (by default, the 12 first individuals are selected). If occasions are present, all occasions of the selected individuals will be displayed. Takes precedence over ids. For instance c(5,6,10,11).

    • isRange (logical) - If TRUE, all individuals whose index is inside [min(indices), max[indices]] are selected (FALSE by default). Forced to FALSE if ids is defined.

    • ids (vector) - Names of the individuals to display. If occasions are present, all occasions of the selected individuals will be displayed. For instance c("101-01","101-02","101-03"). If ids are integers, can also be c(1,3,6). Ignored if indices is defined.

Value

  • A ggplot object if one element in covariatesRows and covariatesColumns,

  • A TableGrob object if multiple plots (output of grid.arrange)

Details

Generate scatterplots between two continuous covariates or bar plot between categorical covariates.

See also

getPlotPreferences

Examples

R
  initializeLixoftConnectors(software = "pkanalix")
  project <- file.path(getDemoPath(), "2.case_studies/project_Theo_extravasc_SD.pkx")
  loadProject(project)

  # covariate distribution when only one covariate is specified
  plotCovariates(covariatesRows = "HT", settings = list(bins = 10))

Output of plotCovariates with covariatesRows HT and 10 bins. Four panels show HT against AGE, FORM, HT and WT. AGE and WT are scatter plots with rising regression lines, FORM shows identical boxplots for ref and test with red outlier crosses, and HT against itself is a histogram of heights from about 176 to 192.
R

#> TableGrob (1 x 1) "arrange": 1 grobs
#>   z     cells    name            grob
#> 1 1 (1-1,1-1) arrange gtable[arrange]

  # scatter plot when both covariates are continuous
  plotCovariates(covariatesRows = "HT", covariatesColumns = "AGE", settings = list(spline = TRUE))

Output of plotCovariates for HT versus AGE with spline set to true. Scatter plot of height HT, about 176 to 191, against AGE, about 21 to 39, with a purple linear regression line and an orange spline. Both lines rise, showing taller subjects at older ages, with the spline dipping near age 23.
R

  plotCovariates(covariatesRows = "HT", covariatesColumns = c("AGE", "FORM"))

Output of plotCovariates for HT versus AGE and FORM. Left panel is a scatter plot of HT against AGE with a rising regression line. Right panel shows boxplots of HT for FORM ref and test, which are identical, median about 181, with red crosses marking outliers near 190 and 191.
R

#> TableGrob (1 x 1) "arrange": 1 grobs
#>   z     cells    name            grob
#> 1 1 (1-1,1-1) arrange gtable[arrange]

  # box plot when one covariate is categorical and the othe one is continuous
  preferences <- list(boxplot = list(fill = "#2075AE"), boxplotOutlier = list(shape = 3))
  plotCovariates(covariatesRows = "FORM", covariatesColumns = "AGE", preferences = preferences)

Output of plotCovariates for FORM versus AGE with custom preferences. Stacked histogram of AGE from 20 to 40, with bar heights giving counts split into two shades of blue for the two FORM categories. Each bar is split evenly between the two formulations, with the tallest bar of 10 near age 22.
R


  # histogram when covariate on column is categorical
  plotCovariates(covariatesRows = "FORM", covariatesColumns = "SEQ",
                 settings = list(histogramColors = c("#5DC088", "#DBA92B")))

Output of plotCovariates for FORM versus SEQ with custom histogram colors green and gold. Grouped bar chart with SEQ categories RT and TR on the x axis, each with a green and a gold bar of height about 9, one per FORM category, showing equal counts in every group.
R

  plotCovariates(covariatesRows = "AGE", covariatesColumns = "SEQ",
                 settings = list(histogramColors = c("#5DC088", "#DBA92B")))

Box plot from plotCovariates with AGE on the y-axis versus the categorical covariate SEQ on the x-axis, with one box for RT and one for TR. Both medians are about 25. RT spans a wider range, about 21 to 39 with a box from about 22 to 29, while TR spans about 22 to 30 with a box from about 23 to 27.
R


  # stratification
  plotCovariates(covariatesRows = "HT", covariatesColumns = "WT",
                 stratify = list(split = "AGE",
                                 filter = list("Period", 1),
                                 groups = list(name = "AGE", definition = 25)))

Scatter plot from plotCovariates of HT versus WT for Period 1, split into two panels by AGE group, AGE 21-25 and AGE 25-39, using a break at 25. Each panel shows individual points with a magenta regression line. Both lines slope upward, with HT ranging about 176 to 190 and WT about 65 to 83.
R

  preferences <- list(regressionLine = list(color = "#E5551B"))
  plotCovariates(covariatesRows = "AGE", covariatesColumns = "WT",
                 stratify = list(color = "HT",
                                 groups = list(name = "HT", definition = 181),
                                 colors = c("#2BB9DB", "#DD6BD2")),
                 preferences = preferences)

Scatter plot from plotCovariates of AGE versus WT, with points colored by two HT groups split at 181, shown in cyan and pink. A single orange regression line, set through preferences, rises from about AGE 24 at WT 65 to about AGE 30 at WT 83. No legend is shown.
R

  plotCovariates(covariatesRows = "HT", covariatesColumns = "WT",
                 stratify = list(split = c("AGE", "SEQ"),
                                 groups = list(name = "AGE", definition = 25)))

Scatter plots from plotCovariates of HT versus WT split into four panels by AGE group and SEQ, namely AGE 21-25 with RT, AGE 21-25 with TR, AGE 25-39 with RT and AGE 25-39 with TR. Each panel has few points and its own magenta regression line. The line slopes downward in the AGE 21-25 RT panel and upward in the other three.
R


  # Mulitple covariates
  plotCovariates()

Default plotCovariates output, a 4 by 4 matrix of the covariates AGE, FORM, HT and WT. Diagonal cells show histograms or bar charts of each covariate. Off-diagonal cells show scatter plots with magenta regression lines for continuous pairs, box plots by FORM ref and test, and stacked histograms colored by FORM. HT and WT show a clear positive relationship.
R

#> TableGrob (1 x 1) "arrange": 1 grobs
#>   z     cells    name            grob
#> 1 1 (1-1,1-1) arrange gtable[arrange]
  plotCovariates(covariatesRows = c("AGE", "SEQ", "HT"), covariatesColumns = c("AGE", "SEQ", "HT"))

plotCovariates output as a 3 by 3 matrix of AGE, HT and SEQ chosen for rows and columns. Diagonal cells show histograms of AGE and HT and a bar chart of the RT and TR counts. Off-diagonal cells show an AGE versus HT scatter plot with a rising regression line, box plots of AGE and HT by SEQ, and histograms of AGE and HT stacked by SEQ.
R

#> TableGrob (1 x 1) "arrange": 1 grobs
#>   z     cells    name            grob
#> 1 1 (1-1,1-1) arrange gtable[arrange]
  plotCovariates(stratify = list(filter = list("AGE", 2),
                                 groups = list(name = "AGE", definition = c(25, 30))))

plotCovariates matrix of AGE, FORM, HT and WT after filtering to the second AGE group, with groups defined by breaks at 25 and 30, so only ages 25 to 29 remain. Layout matches the default matrix with histograms, box plots by FORM, stacked histograms and scatter plots, but with fewer individuals and nearly flat regression lines.
R

#> TableGrob (1 x 1) "arrange": 1 grobs
#>   z     cells    name            grob
#> 1 1 (1-1,1-1) arrange gtable[arrange]


Last updated: