library(gdtools)
register_gfont("Permanent Marker")
#> [1] TRUE
register_gfont("Open Sans")
#> [1] TRUE
set_flextable_defaults(
font.family = "Open Sans",
theme_fun = theme_vanilla,
digits = 2, big.mark = "",
scroll = list(),
font.color = "#333333", na_str = ""
)
library(palmerpenguins)
ft <- as_flextable(penguins)
ft
species | island | bill_length_mm | bill_depth_mm | flipper_length_mm | body_mass_g | sex | year |
---|---|---|---|---|---|---|---|
factor | factor | numeric | numeric | integer | integer | factor | integer |
Adelie | Torgersen | 39.10 | 18.70 | 181 | 3750 | male | 2007 |
Adelie | Torgersen | 39.50 | 17.40 | 186 | 3800 | female | 2007 |
Adelie | Torgersen | 40.30 | 18.00 | 195 | 3250 | female | 2007 |
Adelie | Torgersen | 2007 | |||||
Adelie | Torgersen | 36.70 | 19.30 | 193 | 3450 | female | 2007 |
Adelie | Torgersen | 39.30 | 20.60 | 190 | 3650 | male | 2007 |
Adelie | Torgersen | 38.90 | 17.80 | 181 | 3625 | female | 2007 |
Adelie | Torgersen | 39.20 | 19.60 | 195 | 4675 | male | 2007 |
Adelie | Torgersen | 34.10 | 18.10 | 193 | 3475 | 2007 | |
Adelie | Torgersen | 42.00 | 20.20 | 190 | 4250 | 2007 | |
n: 344 |
Le seul élément de flextable à utiliser est la fonction gen_grob()
, le
reste du code concerne des opérations ‘grid’.
library(grid)
grid.raster(magick::image_read("lter_penguins.png"))
grid.rect(gp = gpar(col = "transparent", fill = radialGradient(
colours = c(
adjustcolor("white", .6),
adjustcolor("#f2af00", .8),
adjustcolor("#c32900", .7)
),
stops = c(0, .7, 1)
)))
grid.text(y = .1, x = .95, just = "right",
label = "Size measurements for adult foraging penguins near Palmer Station, Antarctica",
gp = gpar(col = "white", fontsize = 10, fontfamily = "Open Sans", fontface = "italic"))
grid.text(y = .9,
label = "Made with packages 'grid', 'flextable', 'ragg' and 'palmerpenguins'",
gp = gpar(col = "white", fontsize = 14, fontfamily = "Permanent Marker"))
pushViewport(viewport(width = .95, height = .75, gp = gpar(col = "transparent")))
grid.circle(gp = gpar(fill = adjustcolor("white", .9)), r = .4)
grid.draw(gen_grob(ft, just = "center", scaling = "min", fit = "width"))
popViewport()