consort_plot: Self generating consort diagram

Description Usage Arguments Details Value See Also Examples

View source: R/consort_plot.R

Description

Create CONSORT diagram from a participant disposition data.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
consort_plot(
  data,
  orders,
  side_box,
  allocation = NULL,
  labels = NULL,
  coords = NULL,
  dist = 0.02,
  cex = 0.8,
  text_width = NULL,
  widths = c(0.1, 0.9)
)

Arguments

data

Data set with disposition information for each participants.

orders

A named vector or a list, names as the variable in the dataset and values as labels in the box. The order of the diagram will be based on this.

side_box

Variable vector, appeared as side box in the diagram. The next box will be the subset of the missing values of these variables.

allocation

Name of the grouping/treatment variable (optional), the diagram will split into branches on this variables forward.

labels

Named vector, names is the location of the terminal node. The position location should plus 1 after the allocation variables if the allocation is defined.

coords

The horizontal coordinates of the boxes, see add_split.

dist

Optional, distance between boxes. Default is 0.02.

cex

Multiplier applied to font size, Default is 0.8

text_width

a positive integer giving the target column for wrapping lines in the output. String will not be wrapped if not defined (default). The stri_wrap function will be used if stringi package installed, otherwise strwrap will be used.

widths

A numeric vector of length 2 specifying relative percentage of the label and diagram in the final gprah.

Details

The calculation of numbers is as in an analogous to Kirchhoff's Laws of electricity. The numbers in terminal nodes must sum to those in the ancestor nodes. All the drop outs will be populated as a side box. Which was different from the official CONSORT diagram template, which has dropout inside a vertical node.

Value

A consort.plot object.

See Also

add_side_box,add_split, add_side_box

Examples

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
## Prepare test data
set.seed(1001)
N <- 300

trialno <- sample(c(1000:2000), N)
exc1 <- rep(NA, N)
exc1[sample(1:N, 15)] <- sample(c("Sample not collected", "MRI not collected", "Other"),
  15,
  replace = TRUE, prob = c(0.4, 0.4, 0.2)
)

induc <- rep(NA, N)
induc[is.na(exc1)] <- trialno[is.na(exc1)]

exc2 <- rep(NA, N)
exc2[sample(1:N, 20)] <- sample(c(
  "Sample not collected", "Dead",
  "Other"
), 20,
replace = TRUE,
prob = c(0.4, 0.4, 0.2)
)
exc2[is.na(induc)] <- NA

exc <- ifelse(is.na(exc2), exc1, exc2)

arm <- rep(NA, N)
arm[is.na(exc)] <- sample(c("Conc", "Seq"), sum(is.na(exc)), replace = TRUE)
arm3 <- sample(c("Trt A", "Trt B", "Trt C"), N, replace = TRUE)
arm3[is.na(arm)] <- NA

fow1 <- rep(NA, N)
fow1[!is.na(arm)] <- sample(c("Withdraw", "Discontinued", "Death", "Other", NA),
  sum(!is.na(arm)),
  replace = TRUE,
  prob = c(0.05, 0.05, 0.05, 0.05, 0.8)
)
fow2 <- rep(NA, N)
fow2[!is.na(arm) & is.na(fow1)] <- sample(c("Protocol deviation", "Outcome missing", NA),
  sum(!is.na(arm) & is.na(fow1)),
  replace = TRUE,
  prob = c(0.05, 0.05, 0.9)
)


df <- data.frame(trialno, exc1, induc, exc2, exc, arm, arm3, fow1, fow2)
rm(trialno, exc1, induc, exc2, exc, arm, arm3, fow1, fow2, N)

## Single arm
out <- consort_plot(
  data = df,
  order = c(
    trialno = "Population",
    exc1 = "Excluded",
    arm = "Allocated",
    fow1 = "Lost of Follow-up",
    trialno = "Finished Followup",
    fow2 = "Not evaluable for the final analysis",
    trialno = "Final Analysis"
  ),
  side_box = c("exc1", "fow1", "fow2"),
  cex = 0.9
)

## Two arms
out <- consort_plot(
  data = df,
  order = c(
    trialno = "Population",
    exc = "Excluded",
    arm = "Randomized patient",
    fow1 = "Lost of Follow-up",
    trialno = "Finished Followup",
    fow2 = "Not evaluable",
    trialno = "Final Analysis"
  ),
  side_box = c("exc", "fow1", "fow2"),
  allocation = "arm",
  labels = c(
    "1" = "Screening", "2" = "Randomization",
    "5" = "Final"
  )
)
## Three arms
consort_plot(
  data = df,
  order = c(
    trialno = "Population",
    exc = "Excluded",
    arm3 = "Randomized patient",
    fow1 = "Lost of Follow-up",
    trialno = "Finished Followup",
    fow2 = "Not evaluable",
    trialno = "Final Analysis"
  ),
  side_box = c("exc", "fow1", "fow2"),
  allocation = "arm3",
  labels = c(
    "1" = "Screening", "2" = "Randomization",
    "5" = "Final"
  )
)

## Multiple phase
consort_plot(
  data = df,
  order = list(
    trialno = "Population",
    exc1 = "Excluded",
    induc = "Induction",
    exc2 = "Excluded",
    arm3 = "Randomized patient",
    fow1 = "Lost of Follow-up",
    trialno = "Finished Followup",
    fow2 = "Not evaluable",
    trialno = "Final Analysis"
  ),
  side_box = c("exc1", "exc2", "fow1", "fow2"),
  allocation = "arm3",
  labels = c(
    "1" = "Screening", "2" = "Month 4",
    "3" = "Randomization", "5" = "Month 24",
    "6" = "End of study"
  ),
  dist = 0.02,
  cex = 0.7
)

consort documentation built on Nov. 4, 2021, 5:06 p.m.