## basic usage: just supply a color name and let both the background color
## and the output format be decided automatically (the latter does not work
## correctly outside of a quarto/knitr document and hence just returns the text)
colorbox("red")
## emulate behavior in a quarto/knitr document with HTML or LaTeX output
colorbox("red", format = "latex")
colorbox("red", format = "html")
## instead of fully saturated red in sRGB, employ other flavors of red:
## - color 2 in R's default palette
## - color #D55E00 from the Okabe-Ito palette
colorbox("red", color = 2, format = "html")
colorbox("red", color = "#D55E00", format = "html")
## by default, either black or white is used for the text color
## (which ever has the better contrast) but alternatively a different
## main font color (say gray10) and a different background color (say cornsilk)
## can be used for the text
colorbox("red", color = 2, maincolor = "gray10", bgcolor = "cornsilk", format = "html")
colorbox("yellow", color = 7, maincolor = "gray10", bgcolor = "cornsilk", format = "html")
Run the code above in your browser using DataLab