kable_coloring {jamba} | R Documentation |
Extend kableExtra colorization of 'Rmarkdown' tables
Description
Extend kableExtra colorization of 'Rmarkdown' tables
Usage
kable_coloring(
df,
colorSub = NULL,
background_as_tile = TRUE,
color_cells = TRUE,
row_color_by = NULL,
sep = "_",
border_left = "1px solid #DDDDDD",
border_right = FALSE,
extra_css = "white-space: nowrap;",
format = "html",
format.args = list(trim = TRUE, big.mark = ","),
row.names = NA,
align = NULL,
return_type = c("kable", "data.frame"),
verbose = FALSE,
...
)
Arguments
df |
|
colorSub |
one of the following inputs:
|
background_as_tile |
|
color_cells |
|
row_color_by |
|
sep |
|
border_left , border_right , extra_css |
|
format |
|
format.args |
|
row.names |
|
align |
|
return_type |
|
verbose |
boolean indicating whether to print verbose output. |
... |
additional arguments are passed to |
Details
This function extends the kableExtra
package, and is only
available for use if the kableExtra
package is installed. It is
intended to allow specific color assignment of elements in a
data.frame, but otherwise uses the kableExtra
functions to
apply those colors.
The use case is to provide colorized HTML output for 'Rmarkdown',
it has not been tested with other format
output.
The argument colorSub
accepts:
-
character
vector input where names should match column values -
function
that accepts column values and returns acharacter
vector of colors of equal length -
list
input where names should matchcolnames(df)
, and where each list element should contain either acharacter
vector, orfunction
as described above.
Value
object with class c("kableExtra", "knitr_kable")
by default
when return_type="kable"
, suitable to render inside an 'Rmarkdown'
or HTML context. Or returns data.frame
when return_type="data.frame"
.
See Also
Other jam color functions:
alpha2col()
,
applyCLrange()
,
col2alpha()
,
col2hcl()
,
col2hsl()
,
col2hsv()
,
color2gradient()
,
fixYellow()
,
fixYellowHue()
,
getColorRamp()
,
hcl2col()
,
hsl2col()
,
hsv2col()
,
isColor()
,
makeColorDarker()
,
rainbow2()
,
rgb2col()
,
setCLranges()
,
setTextContrastColor()
,
showColors()
,
unalpha()
,
warpRamp()
Other jam practical functions:
breakDensity()
,
call_fn_ellipsis()
,
checkLightMode()
,
check_pkg_installed()
,
colNum2excelName()
,
color_dither()
,
exp2signed()
,
getAxisLabel()
,
isFALSEV()
,
isTRUEV()
,
jargs()
,
lldf()
,
log2signed()
,
middle()
,
minorLogTicks()
,
newestFile()
,
printDebug()
,
reload_rmarkdown_cache()
,
renameColumn()
,
rmInfinite()
,
rmNA()
,
rmNAs()
,
rmNULL()
,
setPrompt()
Examples
expt_df <- data.frame(
Sample_ID="",
Treatment=rep(c("Vehicle", "Dex"), each=6),
Genotype=rep(c("Wildtype", "Knockout"), each=3),
Rep=paste0("rep", c(1:3)))
expt_df$Sample_ID <- pasteByRow(expt_df[, 2:4])
# define colors
colorSub <- c(Vehicle="palegoldenrod",
Dex="navy",
Wildtype="gold",
Knockout="firebrick",
nameVector(
color2gradient("grey48", n=3, dex=10),
rep("rep", 3),
suffix=""),
nameVector(
color2gradient(n=3,
c("goldenrod1", "indianred3", "royalblue3", "darkorchid4")),
expt_df$Sample_ID))
kbl <- kable_coloring(
expt_df,
caption="Experiment design table showing categorical color assignment.",
colorSub)
# Note that the HTML table is rendered in 'Rmarkdown', not pkgdown
kbl
# return_type="data.frame" is a data.frame with HTML contents
kdf3 <- kable_coloring(
return_type="data.frame",
df=expt_df,
colorSub=colorSub)
kdf3;