When presenting tables in an HTML Rmarkdown report, it is more common to have all tables styled in the same manner. This is an example of all tables having the same style, with a few overridden styles.
This package is meant to implement the concept of a grammar of tables. It allows for a simple formula expression and a data frame to create a rich summary table in a variety of formats. It is designed for extensibility at each step of the process, so that one is not limited by the authors choice of table statistics, output format. The grammar however is an integral part of the package, and as such is not modifiable.
Supposed that further in addition to the lancet style one really wanted a shade of cyan to make the document pop. This was added to the header of this document to make all this magic happen:
<style type="text/css">
\```{r, results='asis'}
cat(custom_css("lancet.css"))
```
.figbody thead
{
background: #aaffff !important;
}
.figbody tbody .odd
{
background: #aaffff !important;
}
</style>
Here’s an example similary to summaryM from Hmisc to get us started:
head(pbc)
## bili albumin stage protime sex fu.days age spiders hepatom
## 1 14.5 2.60 4 12.2 female 400 58.76523 present present
## 2 1.1 4.14 3 10.6 female 4500 56.44627 present present
## 3 1.4 3.48 4 12.0 male 1012 70.07255 absent absent
## 4 1.8 2.54 4 10.3 female 1925 54.74059 present present
## 5 3.4 3.53 3 10.9 female 1504 38.10541 present present
## 6 0.8 3.98 3 11.0 female 2503 66.25873 absent present
## ascites alk.phos sgot chol trig platelet drug status
## 1 present 1718.0 137.95 261 172 190 placebo 1
## 2 absent 7394.8 113.52 302 88 221 placebo 0
## 3 absent 516.0 96.10 176 55 151 placebo 1
## 4 absent 6121.8 60.63 244 92 183 placebo 1
## 5 absent 671.0 113.15 279 72 136 D-penicillamine 0
## 6 absent 944.0 93.00 248 63 NA D-penicillamine 1
## edema copper
## 1 edema despite diuretic therapy 156
## 2 no edema 54
## 3 edema, no diuretic therapy 210
## 4 edema, no diuretic therapy 64
## 5 no edema 143
## 6 no edema 50
html5(tangram("drug ~ bili[2] + albumin + stage::Categorical + protime + sex + age + spiders", tangram::pbc),
fragment=TRUE, caption = "Hmisc::PBC", id="tbl2")
N | D-penicillamine | placebo | not randomized | Test Statistic | |
154 | 158 | 106 | |||
Serum Bilirubinmg/dl | 418 | 0.701.303.60 | 0.801.403.22 | 0.701.403.12 | F2,415 = 0.03,P = 0.9721 |
Albumingm/dl | 418 | 3.343.543.78 | 3.213.563.83 | 3.123.473.73 | F2,415 = 2.13,P = 0.1201 |
Histologic Stage, Ludwig Criteria | 412 | χ2 6 = 5.33,P = 0.502 | |||
1 | 0 . 0262.597 4154 | 0 . 0767.595 12158 | 0 . 0505.000 5100 | ||
2 | 0 . 20820.779 32154 | 0 . 22222.152 35158 | 0 . 25025.000 25100 | ||
3 | 0 . 41641.558 64154 | 0 . 35435.443 56158 | 0 . 35035.000 35100 | ||
4 | 0 . 35135.065 54154 | 0 . 34834.810 55158 | 0 . 35035.000 35100 | ||
Prothrombin Timesec. | 416 | 10.010.611.4 | 10.010.611.0 | 10.110.611.0 | F2,413 = 0.23,P = 0.7951 |
sex : female | 418 | 0 . 90390.260139154 | 0 . 86786.709137158 | 0 . 92592.453 98106 | χ2 2 = 2.38,P = 0.304 |
Age | 418 | 41.448.155.8 | 42.951.959.0 | 46.053.061.1 | F2,415 = 6.10,P = 0.0021 |
spiders : present | 312 | 0 . 29229.221 45154 | 0 . 28528.481 45158 | χ2 1 = 0.02,P = 0.885 |
set.seed(1234)
x <- round(rnorm(375, 79, 10))
y <- round(rnorm(375, 80, 9))
y[rbinom(375, 1, prob=0.05)] <- NA
attr(x, "label") <- "Global score, 3m"
attr(y, "label") <- "Global score, 12m"
html5(tangram(1 ~ x+y,
data.frame(x=x, y=y),
after=hmisc_intercept_cleanup),
fragment=TRUE, caption="Intercept", id="tbl5")
N | All | |
Global score, 3m | 375 | 737985 |
Global score, 12m | 374 | 738085 |