View source: R/plots-scatterplotClinData.R
scatterplotClinData | R Documentation |
The parameters for this visualization
are based on ggplot2
(aesthetic, scale, ...), parameter specification,
unlike the other visualizations of the package.
scatterplotClinData(
data,
xVar,
yVar,
xLab = getLabelVar(var = xVar, labelVars = labelVars),
xLabVar = NULL,
yLab = getLabelVar(var = yVar, labelVars = labelVars),
yLabVar = NULL,
aesPointVar = list(),
pointPars = list(),
aesLineVar = list(),
linePars = list(),
lineInclude = length(aesLineVar) > 0,
aesSmoothVar = list(),
smoothPars = list(),
smoothInclude = length(c(aesSmoothVar, smoothPars)) > 0,
aesLab,
xTrans = "identity",
yTrans = "identity",
xPars = list(),
yPars = list(),
xLabVars = NULL,
yLim = NULL,
xLim = NULL,
yLimExpandData = TRUE,
xLimExpandData = TRUE,
title = paste(c(paste(yLab, "vs", xLab), titleExtra), collapse = "<br>"),
titleExtra = NULL,
caption = NULL,
subtitle = NULL,
facetPars = list(),
facetType = c("wrap", "grid"),
scalePars = list(),
themePars = list(legend.position = "bottom"),
refLinePars = NULL,
labelVars = NULL,
width = NULL,
height = NULL,
hoverVars,
hoverLab,
idVar = "USUBJID",
idLab = getLabelVar(idVar, labelVars = labelVars),
idHighlightBox = FALSE,
pathVar = NULL,
pathExpand = FALSE,
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
)
data |
Data.frame with input data. |
xVar |
String with column of |
yVar |
String with column of |
xLab |
String with label for |
xLabVar |
(optional) Character vector with column(s) of |
yLab |
String with label for |
yLabVar |
(optional) Character vector with column(s) of |
aesPointVar |
List with specification of aesthetic variable(s),
for the point, passed to the |
pointPars |
List with parameters other than aesthetic variables to pass to |
aesLineVar |
List with specification of aesthetic variable(s),
for the line, passed to the |
linePars |
List with parameters other than aesthetic variables to pass to |
lineInclude |
Logical, if TRUE (by default if |
aesSmoothVar |
List with specification of aesthetic variable(s),
for the smoothing layer, passed to the |
smoothPars |
List with parameters other than aesthetic variables to pass to |
smoothInclude |
Logical, if TRUE (by default if one of |
aesLab |
Named character vector with labels for each aesthetic variable. |
xTrans , yTrans |
Transformation for the x/y- variables,
passed to the |
xPars , yPars |
List with extra parameters for x/y axis, passed to the
|
xLabVars |
Character vector with variable(s) to be displayed
as the labels of the ticks in the x-axis. |
xLim , yLim |
Numeric vector of length 2 with limits for the x/y axes. |
xLimExpandData , yLimExpandData |
Logical (TRUE by default), should the
limits specified via |
title |
String with title for the plot. |
titleExtra |
String with extra title for the plot (appended after |
caption |
String with caption. |
subtitle |
String with subtitle. |
facetPars |
List with facetting parameters, passed to the facetting function. |
facetType |
String with facetting type, either:
|
scalePars |
List with parameters to customize
scales. Each sublist should contains a set of parameters
passed to the |
themePars |
List with general theme parameters
(see |
refLinePars |
(optional) Nested list, with parameters for each reference line(s). Each sublist (a.k.a reference line) contains:
|
labelVars |
Named character vector containing variable labels. |
width |
Numeric, width of the plot in pixels, 800 by default. |
height |
Numeric, height of the plot in pixels, 500 by default. |
hoverVars |
Character vector with variables to be displayed in the hover,
by default |
hoverLab |
Named character vector with labels for |
idVar |
String with variable containing subject ID. |
idLab |
String with label for |
idHighlightBox |
Logical, if TRUE (FALSE by default) a selectize box
is included to highlight selected element(s) of the ID variable ( |
pathVar |
String with variable of
|
pathExpand |
Logical, if FALSE (by default)
the path to subject-report is included in an hyperlink in the table,
otherwise a collapsed row is created.
This should be set to TRUE only if multiple paths
are included for each row in |
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. |
Either:
if a table
is requested: a clinDataReview
object,
a.k.a a list with the 'plot' (plotly
object) and 'table'
(datatable
object)
otherwise: a plotly
object
Laure Cougnaud
Other Clinical data visualization of individual profiles.:
timeProfileIntervalPlot()
library(clinUtils)
data(dataADaMCDISCP01)
labelVars <- attr(dataADaMCDISCP01, "labelVars")
dataLB <- dataADaMCDISCP01$ADLBC
dataDM <- dataADaMCDISCP01$ADSL
dataLB <- annotateData(dataLB, annotations = list(data = dataDM))
# subset of the data for the example
dataLB <- subset(dataLB, VISIT %in% c("SCREENING 1", "WEEK 2", "WEEK 8"))
## time profile
dataPlot <- subset(dataLB, PARAMCD == "ALT")
# with relative day
scatterplotClinData(
data = dataPlot,
xVar = "ADY",
yVar = "LBSTRESN",
aesPointVar = list(color = "TRTP", fill = "TRTP"),
aesLineVar = list(group = "USUBJID", color = "TRTP"),
labelVars = labelVars
)
# with actual visit
dataPlot$AVISIT <- with(dataPlot, reorder(trimws(AVISIT), AVISITN))
scatterplotClinData(
data = dataPlot,
xVar = "AVISIT",
yVar = "LBSTRESN",
aesPointVar = list(color = "TRTP", fill = "TRTP"),
aesLineVar = list(group = "USUBJID", color = "TRTP"),
labelVars = labelVars
)
# add number of subjects below each visit
if (requireNamespace("inTextSummaryTable", quietly = TRUE)) {
# compute number of subjects by visit
summaryTable <- inTextSummaryTable::computeSummaryStatisticsTable(
dataPlot,
rowVar = "AVISIT",
stats = "n"
)
# add it in the data
dataPlot <- merge(dataPlot, summaryTable[, c("AVISIT", "n")], all.x = TRUE)
dataPlot$n <- paste0("N=", dataPlot$n)
scatterplotClinData(
data = dataPlot,
xVar = "AVISIT", xLabVars = c("AVISIT", "n"),
yVar = "LBSTRESN",
aesPointVar = list(color = "TRTP", fill = "TRTP"),
aesLineVar = list(group = "USUBJID", color = "TRTP"),
labelVars = labelVars
)
}
## pairwise comparison plot of two parameters of interest:
# format data long -> wide format (one column per lab param)
dataPlot <- subset(dataLB, PARAMCD %in% c("ALT", "AST"))
dataPlot <- stats::aggregate(
LBSTRESN ~ USUBJID + VISIT + VISITNUM + PARAMCD,
data = dataPlot,
FUN = mean
)
dataPlotWide <- stats::reshape(
data = dataPlot,
timevar = "PARAMCD", idvar = c("USUBJID", "VISIT", "VISITNUM"),
direction = "wide"
)
colnames(dataPlotWide) <- sub("^LBSTRESN.", "", colnames(dataPlotWide))
# scatterplot per visit
scatterplotClinData(
data = dataPlotWide,
xVar = "ALT", yVar = "AST",
aesPointVar = list(color = "USUBJID", fill = "USUBJID"),
themePars = list(legend.position = "none"),
facetPars = list(facets = "VISIT"),
labelVars = labelVars,
subtitle = "Visualization is split by visit",
caption = "Points are colored by subject ID"
)
# scatterplot with all visits, link subjects
xLab <- getLabelParamcd(paramcd = "ALT", data = dataLB,
paramcdVar = "PARAMCD", paramVar = "PARAM")
yLab <- getLabelParamcd(paramcd = "AST", data = dataLB,
paramcdVar = "PARAMCD", paramVar = "PARAM")
scatterplotClinData(
data = dataPlotWide,
xVar = "ALT", yVar = "AST",
xLab = xLab,
yLab = yLab,
aesPointVar = list(color = "VISIT", fill = "VISIT"),
aesLineVar = list(group = "USUBJID"),
labelVars = labelVars
)
# scatterplot of different visits versus baseline
# add baseline as extra column:
dataPlot <- subset(dataLB, PARAMCD == "ALT")
dataPlotBL <- subset(dataPlot, VISIT == "SCREENING 1")
dataPlotBL <- dataPlotBL[with(dataPlotBL, order(USUBJID, -ADY)), ]
dataPlotBL <- dataPlotBL[!duplicated(dataPlotBL$USUBJID), ]
dataPlot$LBSTRESNBL <- dataPlot[match(dataPlot$USUBJID, dataPlotBL$USUBJID), "LBSTRESN"]
# sort visits:
dataPlot$VISIT <- with(dataPlot, reorder(VISIT, VISITNUM))
xLab <- paste(labelVars["LBSTRESN"], "for last screening visit")
yLab <- paste(labelVars["LBSTRESN"], "at visit X")
paramLab <- getLabelParamcd(paramcd = "ALT", data = dataLB,
paramcdVar = "PARAMCD", paramVar = "PARAM")
scatterplotClinData(
data = dataPlot,
xVar = "LBSTRESNBL", xLab = xLab,
yVar = "LBSTRESN", yLab = yLab,
aesPointVar = list(color = "USUBJID", fill = "USUBJID"),
aesLineVar = list(group = "USUBJID", color = "USUBJID"),
hoverVars = c("USUBJID", "VISIT", "ADY", "LBSTRESN"),
labelVars = labelVars,
facetPars = list(facets = "VISIT"),
themePars = list(legend.position = "none"),
title = paste("Comparison of actual value of",
paramLab,
"at each visit versus baseline"
),
refLinePars = list(
list(slope = 1, intercept = 0, linetype = 1, color = "black",
label = FALSE),
list(yintercept = "A1LO", linetype = 2, color = "blue"),
list(yintercept = "A1HI", linetype = 2, color = "purple",
label = "Reference Range Upper Limit")
)
)
## scatterplot with smoothing layer
data <- data.frame(
USUBJID = c(rep('subj1', 20), rep('subj2', 20)),
time = rep( 1:20 , 2 ),
response = c(1:20, 50:31) + runif(min =-3, max = +3, 40),
treat = rep(c('trA', 'trB'), 20),
stringsAsFactors = FALSE
)
# smoothing per subject
scatterplotClinData(
data = data,
xVar = "time", yVar = "response",
aesPointVar = list(color = "treat"),
aesLineVar = list(group = 'USUBJID'),
linePars = list(linetype='dotted'),
aesSmoothVar = list(color='USUBJID', group='USUBJID'),
smoothPars = list(alpha=0.5, size=0.3 , se=TRUE, color = 'black')
)
# plot smoothing over subjects
scatterplotClinData(
data = data,
xVar = "time", yVar = "response",
aesPointVar = list(color = "treat"),
aesLineVar = list(group = 'USUBJID'),
linePars = list(linetype='dotted'),
aesSmoothVar = list(),
smoothPars = list(alpha=0.5, size=0.3 , se=TRUE, color = 'black')
)
# add a selection box
if(interactive()){
dataPlot <- subset(dataLB, PARAMCD == "ALT")
dataPlot$TRTA <- with(dataPlot, reorder(TRTA, TRTAN))
scatterplotClinData(
data = dataPlot,
xVar = "ADY",
yVar = "LBSTRESN",
aesPointVar = list(fill = "TRTA", color = "TRTA"),
aesLineVar = list(group = "USUBJID", color = "TRTA"),
selectVars = "TRTA",
labelVars = labelVars
)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.