View source: R/plots-treemapClinData.R
treemapClinData | R Documentation |
Note: the table and plot are not (yet) linked.
treemapClinData(...)
... |
Arguments passed on to
|
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 visualizations of summary statistics for clinical data:
barplotClinData()
,
boxplotClinData()
,
errorbarClinData()
,
plotCountClinData()
,
sunburstClinData()
library(clinUtils)
data(dataADaMCDISCP01)
labelVars <- attr(dataADaMCDISCP01, "labelVars")
dataDM <- dataADaMCDISCP01$ADSL
dataAE <- dataADaMCDISCP01$ADAE
library(plyr)
## basic treemap:
# treemap takes as input table with counts
if (requireNamespace("inTextSummaryTable", quietly = TRUE)) {
# total counts: Safety Analysis Set (patients with start date for the first treatment)
dataTotal <- subset(dataDM, RFSTDTC != "")
# compute adverse event table
tableAE <- inTextSummaryTable::getSummaryStatisticsTable(
data = dataAE,
rowVar = c("AESOC", "AEDECOD"),
dataTotal = dataTotal,
rowOrder = "total",
labelVars = labelVars,
stats = inTextSummaryTable::getStats("count"),
# plotly treemap requires records (rows) for each group
rowVarTotalInclude = "AEDECOD",
outputType = "data.frame-base"
)
dataPlot <- tableAE
dataPlot$n <- as.numeric(dataPlot$n)
# create plot
treemapClinData(
data = dataPlot,
vars = c("AESOC", "AEDECOD"),
valueVar = "n",
valueLab = "Number of patients with adverse events"
)
## treemap with coloring
# extract worst-case scenario
dataAE$AESEVN <- as.numeric(factor(dataAE$AESEV, levels = c("MILD", "MODERATE", "SEVERE")))
if(any(is.na(dataAE$AESEVN)))
stop("Severity should be filled for all subjects.")
dataAEWC <- ddply(dataAE, c("AESOC", "AEDECOD", "USUBJID"), function(x){
x[which.max(x$AESEVN), ]
})
dataTotalRow <- list(AEDECOD =
ddply(dataAEWC, c("AESOC", "USUBJID"), function(x){
x[which.max(x$AESEVN), ]
})
)
# compute adverse event table
tableAE <- inTextSummaryTable::getSummaryStatisticsTable(
data = dataAEWC,
rowVar = c("AESOC", "AEDECOD"),
var = "AESEVN",
dataTotal = dataTotal,
rowOrder = "total",
labelVars = labelVars,
# plotly treemap requires records (rows) for each group
rowVarTotalInclude = "AEDECOD",
dataTotalRow = dataTotalRow,
outputType = "data.frame-base"
)
dataPlot <- tableAE
dataPlot$statN <- as.numeric(dataPlot$statN)
dataPlot$statMean <- as.numeric(dataPlot$statMean)
# create plot
treemapClinData(
data = dataPlot,
vars = c("AESOC", "AEDECOD"),
valueVar = "statN", valueLab = "Number of patients with adverse events",
colorVar = "statMean", colorLab = "Mean severity"
)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.