-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathREADME.Rmd
More file actions
108 lines (84 loc) · 3.79 KB
/
Copy pathREADME.Rmd
File metadata and controls
108 lines (84 loc) · 3.79 KB
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
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```
# consort
<!-- badges: start -->
[](https://github.com/adayim/consort/actions)
[](https://CRAN.R-project.org/package=consort)
[](https://cran.r-project.org/package=consort)
[](https://app.codecov.io/gh/adayim/consort)
<!-- badges: end -->
The goal of `consort` is to make it easy to create CONSORT diagrams for the transparent reporting of participant allocation in randomized, controlled clinical trials. This is done by creating a standardized disposition data, and using this data as the source for the creation a standard CONSORT diagram. Human effort by supplying text labels on the node can also be achieved.
## Installation
You can install the released version of consort from [CRAN](https://CRAN.R-project.org) with:
``` r
install.packages("consort")
```
And the development version from [GitHub](https://github.com/) with:
``` r
# install.packages("devtools")
devtools::install_github("adayim/consort")
```
## Example
This is a basic example which shows you how to solve a create CONSORT diagram with a given subject disposition data:
```{r example}
library(consort)
library(grid)
## basic example code
```
```{r sample-data}
set.seed(1001)
N <- 300
trialno <- sample(c(1000:2000), N)
exc <- rep(NA, N)
exc[sample(1:N, 15)] <- sample(c("Sample not collected", "MRI not collected", "Other"),
15, replace = T, prob = c(0.4, 0.4, 0.2))
arm <- rep(NA, N)
arm[is.na(exc)] <- sample(c("Conc", "Seq"), sum(is.na(exc)), replace = T)
fow1 <- rep(NA, N)
fow1[!is.na(arm)] <- sample(c("Withdraw", "Discontinued", "Death", "Other", NA),
sum(!is.na(arm)), replace = T,
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 = T,
prob = c(0.05, 0.05, 0.9))
df <- data.frame(trialno, exc, arm, fow1, fow2)
head(df)
```
```{r diagram, fig.width = 7, fig.height = 6}
set_consort_defaults(txt_gp = gpar(cex = 0.6), parse_markup = TRUE)
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"))
plot(out)
```
As the `grid` plotting is not very ideal, calculation of the coodinates for the nodes are not easy job and tried my best. Feel free to PR if you want to improve. Or you can produce `Graphviz` plot by setting `grViz = TRUE` in `plot`. This will use `DiagrammeR` to print the plot. The plot is ideal for Shiny or HTML output.
```{r eval=FALSE}
plot(out, grViz = TRUE)
```
Or save this `Graphviz` plot to `png` or `pdf`
```{r eval=FALSE}
plot(g, grViz = TRUE) |>
DiagrammeRsvg::export_svg() |>
charToRaw() |>
rsvg::rsvg_pdf("svg_graph.pdf")
```