Skip to content

Commit f6fe8f9

Browse files
add flextable & gt examples; turn off striping
1 parent 98b7fec commit f6fe8f9

File tree

7 files changed

+111
-2
lines changed

7 files changed

+111
-2
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
---
2+
title: "flextable - background colors"
3+
format:
4+
typst:
5+
quality: 1
6+
html:
7+
quality: 1
8+
format-links: false
9+
example-source: https://ardata-fr.github.io/flextable-book/define-visual-properties.html#formatting-functions
10+
---
11+
12+
```{r}
13+
#| classes: plain
14+
library(flextable)
15+
library(magrittr)
16+
myft <- as.data.frame(matrix(runif(5*5), ncol = 5)) %>%
17+
flextable() %>%
18+
colformat_double() %>% autofit() %>%
19+
align(align = "center", part = "all") %>%
20+
bg(bg = "black", part = "header") %>%
21+
color(color = "white", part = "all") %>%
22+
bg(bg = scales::col_numeric(palette = "viridis", domain = c(0, 1)))
23+
myft
24+
```

tests/docs/typst/tables/gt/air-quality.qmd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ format:
99
---
1010

1111
```{r}
12+
#| classes: plain
1213
library(gt)
1314
library(dplyr)
1415
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
---
2+
title: "gt - gtcars"
3+
format:
4+
typst:
5+
quality: 1
6+
html:
7+
quality: 1
8+
format-links: false
9+
example-source: https://themockup.blog/static/resources/gt-cookbook.html#multiple-colors
10+
---
11+
12+
```{=typst}
13+
// this example is a little large for a standard page, at least at 0.75px = 1pt
14+
// and we don't have
15+
#set page(margin: 0cm)
16+
17+
// striped
18+
// #set table(fill: (_,y) => if calc.odd(y) {luma(240)} else {white})
19+
```
20+
21+
22+
```{r}
23+
#| classes: plain
24+
library(dplyr)
25+
library(gt)
26+
27+
gtcars %>%
28+
dplyr::filter(mfr == "Ferrari", hp < 900) %>%
29+
dplyr::select(model, hp, mpg_c, mpg_h, msrp) %>%
30+
gt() %>%
31+
data_color(
32+
columns = vars(hp),
33+
colors = scales::col_numeric(
34+
palette = c(
35+
"white", "orange", "red"),
36+
domain = c(500, 750))
37+
) %>%
38+
data_color(
39+
columns = vars(mpg_c, mpg_h),
40+
colors = scales::col_numeric(
41+
palette = c(
42+
"white", "green"),
43+
domain = c(10, 25))
44+
) %>%
45+
data_color(
46+
columns = vars(msrp),
47+
colors = scales::col_numeric(
48+
palette = c(
49+
"white", "pink", "red"),
50+
domain = NULL)
51+
)
52+
```

tests/docs/typst/tables/gt/islands.qmd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ format:
99
---
1010

1111
```{r}
12+
#| classes: plain
1213
library(gt)
1314
library(dplyr)
1415

tests/docs/typst/tables/gt/mtcars.qmd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ format:
1919

2020

2121
```{r}
22-
2322
library(dplyr)
2423
library(gt)
2524
@@ -38,6 +37,7 @@ order_countries <- c("Germany", "Italy", "United States", "Japan")
3837

3938

4039
```{r}
40+
#| classes: plain
4141
# Reorder the table rows by our specific ordering of groups
4242
tab <-
4343
gtcars_8 |>
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
---
2+
title: "gt - Red-Blue Palette"
3+
format:
4+
typst:
5+
quality: 1
6+
html:
7+
quality: 1
8+
format-links: false
9+
example-source: https://themockup.blog/static/resources/gt-cookbook.html#red-blue-palette
10+
---
11+
12+
```{r}
13+
#| classes: plain
14+
library(dplyr)
15+
library(gt)
16+
17+
dimnames <- list(start(nottem)[1]:end(nottem)[1], month.abb)
18+
temps <- matrix(nottem, ncol = 12, byrow = TRUE, dimnames = dimnames) %>%
19+
data.frame() %>%
20+
tibble::rownames_to_column() %>%
21+
head(10)
22+
23+
temps %>%
24+
gt() %>%
25+
data_color(
26+
columns = vars(month.abb),
27+
colors = scales::col_numeric(
28+
colorspace::diverge_hcl(n = 9, palette = "Blue-Red 3"),
29+
domain = range(nottem))
30+
)
31+
```

tests/docs/typst/tables/gt/test-pattern.qmd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ format:
1313
```
1414

1515
```{r}
16-
16+
#| classes: plain
1717
library(dplyr)
1818
library(gt)
1919

0 commit comments

Comments
 (0)