Skip to content

Instantly share code, notes, and snippets.

@AlbertRapp
Created April 8, 2023 10:59
Show Gist options
  • Save AlbertRapp/17f1c262c34d0e2c6a0b150feed5abc7 to your computer and use it in GitHub Desktop.
Save AlbertRapp/17f1c262c34d0e2c6a0b150feed5abc7 to your computer and use it in GitHub Desktop.
dot-columns-gt.R
library(tidyverse)
library(gt)
circle <- '<span style="
display: inline-block;
background-color: pink;
width: 1cm;
height: 1cm;
border-radius: 100%;
border: black 1px solid;
margin-left: 5px;">
</span>'
tibble(
grade = c('A', 'B', 'C', 'D', 'F'),
students = c(2, 5, 3, 1, 1),
plot = map_chr(students, \(x) rep(circle, x) |> paste(collapse = ''))
) |>
gt() |>
fmt_markdown(columns = plot) |>
cols_label(grade = 'Grade', students = 'Students', plot = '') |>
tab_header(title = 'Fictitious exam results') |>
tab_options(heading.align = 'left')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment