errorbarClinData {clinDataReview} | R Documentation |
Interactive plot of confidence interval/error interval of clinical data.
Description
This plot is designed to display summary statistics
of a continuous variable with (confidence) intervals.
The intervals are either displayed:
vertically if
yErrorVar
is specifiedhorizontally if
xErrorVar
is specified
Error bars can visualized by group, via the color variable parameter.
Different symbols are set for each central point of the error bar
via the shape variable parameter.
Usage
errorbarClinData(
data,
xVar,
xLab = getLabelVar(xVar, labelVars = labelVars),
xLabVar = NULL,
yVar,
yLab = getLabelVar(yVar, labelVars = labelVars),
yLabVar = NULL,
yErrorVar = NULL,
yErrorLab = getLabelVar(yErrorVar, labelVars = labelVars),
xErrorVar = NULL,
xErrorLab = getLabelVar(xErrorVar, labelVars = labelVars),
xLabVars = NULL,
xAxisLab = paste(c(xLab, xErrorLab), collapse = " and "),
yAxisLab = paste(c(yLab, yErrorLab), collapse = " and "),
colorVar = NULL,
colorLab = getLabelVar(colorVar, labelVars = labelVars),
colorPalette = NULL,
shapeVar = NULL,
shapeLab = getLabelVar(shapeVar, labelVars = labelVars),
shapePalette = NULL,
size = 6,
title = paste(c(paste(yAxisLab, "vs", xAxisLab), titleExtra), collapse = "<br>"),
titleExtra = NULL,
subtitle = NULL,
caption = NULL,
labelVars = NULL,
mode = "markers",
legendPosition = "bottom",
width = NULL,
height = NULL,
pathVar = NULL,
pathLab = getLabelVar(pathVar, labelVars = labelVars),
hoverVars,
hoverLab,
id = paste0("plotClinData", sample.int(n = 1000, size = 1)),
selectVars = NULL,
selectLab = getLabelVar(selectVars, labelVars = labelVars),
table = FALSE,
tableVars,
tableLab,
tableButton = TRUE,
tablePars = list(),
watermark = NULL,
verbose = FALSE
)
Arguments
data |
Data.frame with data. |
xVar |
String with column of |
xLab |
String with label for |
xLabVar |
(optional) Character vector with column(s) of |
yVar |
String with column of |
yLab |
String with label for |
yLabVar |
(optional) Character vector with column(s) of |
xErrorVar , yErrorVar |
String with variable of |
xErrorLab , yErrorLab |
String with labels
for |
xLabVars |
(vertical error bars)
Character vector with variable(s) to be displayed
as the labels of the ticks in the x-axis. |
xAxisLab , yAxisLab |
Label for the x/y-axis. |
colorVar |
(optional) String with color variable. |
colorLab |
String with label for |
colorPalette |
(optional) Named character vector with color palette.
If not specified, the viridis color palette is used. |
shapeVar |
(optional) String with shape variable. |
shapeLab |
String with label for |
shapePalette |
(optional) Named character vector with
shape palette, |
size |
Integer with size of markers in pixels, 6 by default. |
title |
String with title for the plot. |
titleExtra |
String with extra title for the plot (appended after |
subtitle |
String with subtitle. |
caption |
String with caption. |
labelVars |
Named character vector containing variable labels. |
mode |
String with the mode of the plot,
'markers' by default, so only data points are displayed. |
legendPosition |
String with position of the legend, among: 'top'/'left'/'bottom'/'right', 'bottom' by default. |
width |
Numeric, width of the plot in pixels, 800 by default. |
height |
Numeric, height of the plot in pixels, 500 by default. |
pathVar |
String with variable of <a href="./path-to-report">label</a> .
|
pathLab |
String with label for |
hoverVars |
Character vector with variable(s) to be displayed in the hover, by default any position (and axis) and aesthetic variables displayed in the plot. |
hoverLab |
Named character vector with labels for |
id |
String with general id for the plot:
If not specified, a random id, as 'plotClinData[X]' is used. |
selectVars |
(optional) Character vector with variable(s) from |
selectLab |
(Named) character vector with label for |
table |
Logical, if TRUE (FALSE by default)
returns also a |
tableVars |
Character vector with variables to be included in the table. |
tableLab |
Named character vector with labels
for each |
tableButton |
Logical, if TRUE (by default) the table is included within an HTML button. |
tablePars |
List with parameters passed to the
|
watermark |
(optional) String with path to a file containing a watermark. |
verbose |
Logical, if TRUE (FALSE by default) progress messages are printed in the current console. For the visualizations, progress messages during download of subject-specific report are displayed in the browser console. |
Value
Either:
if a
table
is requested: aclinDataReview
object, a.k.a a list with the 'plot' (plotly
object) and 'table' (datatable
object)otherwise: a
plotly
object
Author(s)
Laure Cougnaud
See Also
Other visualizations of summary statistics for clinical data:
barplotClinData()
,
boxplotClinData()
,
plotCountClinData()
,
sunburstClinData()
,
treemapClinData()
Examples
library(clinUtils)
data(dataADaMCDISCP01)
labelVars <- attr(dataADaMCDISCP01, "labelVars")
## Summary plot with vertical error bars
dataVSDIABP <- subset(dataADaMCDISCP01$ADVS,
PARAMCD == "DIABP" & ANL01FL == "Y" &
AVISIT %in% c("Baseline", "Week 2", "Week 4", "Week 6", "Week 8")
)
# compute summary statistics by visit
if (requireNamespace("inTextSummaryTable", quietly = TRUE)) {
summaryTableVSDIABP <- inTextSummaryTable::computeSummaryStatisticsTable(
data = dataVSDIABP,
rowVar = c("AVISIT", "ATPT"),
var = "AVAL",
stats = inTextSummaryTable::getStats(c("n", "Mean", "SE")),
labelVars = labelVars
)
dataPlot <- subset(summaryTableVSDIABP, !isTotal)
errorbarClinData(
data = dataPlot,
xVar = "AVISIT",
colorVar = "ATPT",
# use non-rounded statistics for the plot
yVar = "statMean", yErrorVar = "statSE",
yLab = "Mean", yErrorLab = "Standard Error",
# include lines connecting the error bars
mode = "markers+lines",
labelVars = labelVars
)
# add number of subjects in labels
dataPlot$nSubj <- with(dataPlot, paste0("N=", n))
errorbarClinData(
data = dataPlot,
xVar = "AVISIT",
xLabVars = c("AVISIT", "nSubj"),
colorVar = "ATPT",
yVar = "statMean", yLab = "Mean",
yErrorVar = "statSE", yErrorLab = "Standard error",
mode = "markers+lines",
title = paste("Diastolic Blood Pressure summary profile by actual visit",
"and analysis timepoint"),
labelVars = labelVars
)
## Add a selection box
if(interactive()){
summaryTable <- inTextSummaryTable::computeSummaryStatisticsTable(
data = subset(dataADaMCDISCP01$ADVS,
ANL01FL == "Y" &
AVISIT %in% c("Baseline", "Week 2", "Week 4", "Week 6", "Week 8")
),
rowVar = c("PARAM", "AVISIT", "ATPT"),
var = "AVAL",
stats = inTextSummaryTable::getStats(c("Mean", "SE")),
labelVars = labelVars
)
dataPlot <- subset(summaryTable, !isTotal)
errorbarClinData(
data = dataPlot,
xVar = "AVISIT",
colorVar = "ATPT",
yVar = "statMean", yLab = "Mean",
yErrorVar = "statSE", yErrorLab = "Standard error",
mode = "markers+lines",
title = paste("Lab parameters summary profile by actual visit",
"and analysis timepoint"),
labelVars = labelVars,
selectVars = "PARAM"
)
}
## Summary plot with horizontal error bars
# Data of interest: ratio from baseline at week 16
dataLBW8 <- subset(dataADaMCDISCP01$ADLBC, grepl("Week 8", AVISIT))
# compute ratio from baseline
dataLBW8$R2BASE <- with(dataLBW8, AVAL/BASE)
dataLBW8 <- subset(dataLBW8, !is.na(R2BASE))
# Order actual treatments
dataLBW8$TRTA <- with(dataLBW8, reorder(TRTA, TRTAN))
# compute summary statistics of the ratio per baseline per parameter
summaryTableLBW8 <- inTextSummaryTable::computeSummaryStatisticsTable(
data = dataLBW8,
var = "R2BASE",
rowVar = "PARAM",
colVar = "TRTA",
stats = inTextSummaryTable::getStats(x = dataLBW8$R2BASE, type = c("n", "Median", "SD"))
)
dataPlot <- subset(summaryTableLBW8, !isTotal)
# extract direction of ratio
dataPlot$dir <- factor(
ifelse(dataPlot$statMedian >= 1, "Increase", "Decrease"),
levels = c("Decrease", "Increase")
)
# compute relative ratio (percentage above 1)
dataPlot$statMedianRelative <- with(dataPlot,
ifelse(statMedian < 1, 1/statMedian, statMedian)
)
# order based on mean relative ratio across treatment arms
params <- names(sort(with(dataPlot, tapply(statMedianRelative, PARAM, mean))))
dataPlot$PARAM <- factor(dataPlot$PARAM, levels = params)
errorbarClinData(
data = dataPlot,
xVar = "statMedianRelative", xErrorVar = "statSD",
xLab = "Median", xErrorLab = "Standard deviation",
xAxisLab = "Relative ratio from baseline (Median +- SD)",
yVar = "PARAM",
colorVar = "TRTA",
shapeVar = "dir", shapeLab = "Direction of ratio",
shapePalette = c(`Decrease` = 25, `Increase` = 24),
size = 10,
labelVars = labelVars,
title = "Summary ratio from baseline at week 8 by treatment"
)
}