library(palmerpenguins)
library(tidyverse)
## ── Attaching packages ─────────────────────────────────────── tidyverse 1.3.0 ──
## ✓ ggplot2 3.3.2 ✓ purrr 0.3.4
## ✓ tibble 3.1.0 ✓ dplyr 1.0.4
## ✓ tidyr 1.1.3 ✓ stringr 1.4.0
## ✓ readr 1.4.0 ✓ forcats 0.5.0
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## x dplyr::filter() masks stats::filter()
## x dplyr::lag() masks stats::lag()
library(kableExtra)
##
## Attaching package: 'kableExtra'
## The following object is masked from 'package:dplyr':
##
## group_rows
penguin_df <- penguins %>%
na.omit()
penguin_table <- penguin_df %>%
mutate(q_bill_length = ntile(bill_length_mm, 4)) %>%
mutate(q_bill_length = recode(q_bill_length,
`1` = "green", `2` = "yellow", `3` = "orange", `4` = "red"
)) %>%
select(species, island, bill_length_mm, q_bill_length) %>%
sample_n(10)
penguin_table %>%
select(species, island, bill_length_mm) %>%
kbl() %>%
kable_paper(bootstrap_options = "striped", full_width = F) %>%
column_spec(3, background = penguin_table$q_bill_length)
|
species
|
island
|
bill_length_mm
|
|
Adelie
|
Torgersen
|
38.6
|
|
Adelie
|
Biscoe
|
36.4
|
|
Adelie
|
Torgersen
|
34.4
|
|
Adelie
|
Torgersen
|
38.5
|
|
Gentoo
|
Biscoe
|
50.1
|
|
Adelie
|
Dream
|
37.2
|
|
Chinstrap
|
Dream
|
49.6
|
|
Gentoo
|
Biscoe
|
46.8
|
|
Adelie
|
Biscoe
|
37.9
|
|
Adelie
|
Torgersen
|
36.6
|