TLF examples through R Markdown

This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.

   

two different layouts from two package

This table (used package 'table1') can be displayed in HTML. But not in word because word enviroment does not convert the layout format.

Alive
(N=134)
Melanoma death
(N=57)
Non-melanoma death
(N=14)
Overall
(N=205)
factor(sex)
0 91 (67.9%) 28 (49.1%) 7 (50.0%) 126 (61.5%)
1 43 (32.1%) 29 (50.9%) 7 (50.0%) 79 (38.5%)
age
Mean (SD) 50.0 (15.9) 55.1 (17.9) 65.3 (10.9) 52.5 (16.7)
Median [Min, Max] 52.0 [4.00, 84.0] 56.0 [14.0, 95.0] 65.0 [49.0, 86.0] 54.0 [4.00, 95.0]
factor(ulcer)
0 92 (68.7%) 16 (28.1%) 7 (50.0%) 115 (56.1%)
1 42 (31.3%) 41 (71.9%) 7 (50.0%) 90 (43.9%)
thickness
Mean (SD) 2.24 (2.33) 4.31 (3.57) 3.72 (3.63) 2.92 (2.96)
Median [Min, Max] 1.36 [0.100, 12.9] 3.54 [0.320, 17.4] 2.26 [0.160, 12.6] 1.94 [0.100, 17.4]
   

This table (used package 'gtsummary') can be displayed in HTML and in word with most of the layout format elements.

Characteristic Alive,
N = 134 (65%)
Melanoma death,
N = 57 (28%)
Non-melanoma death,
N = 14 (6.8%)
Overall,
N = 205
Sex
0 91 / 134 (67.910%) 28 / 57 (49.123%) 7 / 14 (50.000%) 126 / 205 (61.463%)
1 43 / 134 (32.090%) 29 / 57 (50.877%) 7 / 14 (50.000%) 79 / 205 (38.537%)
Age
Mean (SD) 50 (15.92) 55 (17.91) 65 (10.90) 52 (16.67)
Range 4, 84 14, 95 49, 86 4, 95
Ulcer
0 92 / 134 (68.657%) 16 / 57 (28.070%) 7 / 14 (50.000%) 115 / 205 (56.098%)
1 42 / 134 (31.343%) 41 / 57 (71.930%) 7 / 14 (50.000%) 90 / 205 (43.902%)
thickness
Mean (SD) 2 (2.33) 4 (3.57) 4 (3.63) 3 (2.96)
Range 0, 13 0, 17 0, 13 0, 17

   

Another example with other dataset

   

Table 1: basic descriptive stat table 1

Characteristic N = 2001
Chemotherapy Treatment
Drug A 98 (49.00%)
Drug B 102 (51.00%)
Age 47 (38, 57)
Unknown 11
Grade
I 68 (34.00%)
II 68 (34.00%)
III 64 (32.00%)
Tumor Response 61 (31.61%)
Unknown 7

1 Statistics presented: n (%); Median (IQR)

   

Table 2: basic descriptive stat by treatment and overall

Characteristic Drug A,
N = 98 (49%)
Drug B,
N = 102 (51%)
Overall,
N = 200
Age
Mean (SD) 47 (14.71) 47 (14.01) 47 (14.31)
Range 6, 78 9, 83 6, 83
Unknown 7 4 11
Tumor Grade
I 35 / 98 (35.71%) 33 / 102 (32.35%) 68 / 200 (34.00%)
II 32 / 98 (32.65%) 36 / 102 (35.29%) 68 / 200 (34.00%)
III 31 / 98 (31.63%) 33 / 102 (32.35%) 64 / 200 (32.00%)
Tumor Response 28.0 / 95.0 (29.474%) 33.0 / 98.0 (33.673%) 61.0 / 193.0 (31.606%)
Unknown 3 4 7

   

Table 3: basic test

Variable N Drug A, N = 981 Drug B, N = 1021 p-value2
Age 189 46 (37, 59) 48 (39, 56) 0.7
Grade 200 0.9
I 35 (35.71%) 33 (32.35%)
II 32 (32.65%) 36 (35.29%)
III 31 (31.63%) 33 (32.35%)
Tumor Response 193 28 (29.47%) 33 (33.67%) 0.6

1 Statistics presented: Median (IQR); n (%)

2 Statistical tests performed: Wilcoxon rank-sum test; chi-square test of independence

 

Table 4: logistic regression result

Characteristic OR1 95% CI1 p-value
Chemotherapy Treatment
Drug A
Drug B 1.13 0.60, 2.13 0.7
Age 1.02 1.00, 1.04 0.10
Grade
I
II 0.85 0.39, 1.85 0.7
III 1.01 0.47, 2.15 >0.9

1 OR = Odds Ratio, CI = Confidence Interval

   

Table 5: Result from logistic and Cox regression side by side table

Characteristic Tumor Response Time to Death
OR1 95% CI1 p-value HR1 95% CI1 p-value
Chemotherapy Treatment
Drug A
Drug B 1.13 0.60, 2.13 0.7 1.30 0.88, 1.92 0.2
Age 1.02 1.00, 1.04 0.10 1.01 0.99, 1.02 0.3
Grade
I
II 0.85 0.39, 1.85 0.7 1.21 0.73, 1.99 0.5
III 1.01 0.47, 2.15 >0.9 1.79 1.12, 2.86 0.014

1 OR = Odds Ratio, CI = Confidence Interval, HR = Hazard Ratio

   

Including Plots

You can also embed plots, for example:

Figure 1: a forest plot based on table 4

   

Figure 2: Forest plot with table

 

 

plotly pakcage cannot display inside of Rstudio to show interactive plot( but can be displayed in HTML output) need to install extra js to knit into WORD But no interactive plot in WORD

#install.packages("webshot")
#webshot::install_phantomjs()
library(plotly)
ggplotly(p)

Figure 3: Kaplan-Meier plot based on the same dataset