Last chance! 50% off unlimited learning
Sale ends in
applies background colors to cells of a FlexTable
setFlexTableBackgroundColors(object, i, j, colors, to = "body")
a FlexTable
object
vector (integer index, row.names values or boolean vector) for rows selection.
vector (integer index, col.names values or boolean vector) for columns selection.
background colors to apply (e.g. "#000000" or "black"). a character vector of colors with as many elements as defined by the selection.
specify on which part of the FlexTable to apply colors, must be one of the following values "body" (default) or "header" or "footer"
# NOT RUN {
#START_TAG_TEST
data = cor( cor(mtcars) )
pal = c( "#D73027", "#F46D43", "#FDAE61", "#FEE08B",
"#D9EF8B", "#A6D96A", "#66BD63", "#1A9850" )
mycut = cut( data,
breaks = c(-1,-0.75,-0.5,-0.25,0,0.25,0.5,0.75,1),
include.lowest = TRUE, label = FALSE )
mycolors = pal[ mycut ]
MyFTable = FlexTable( round(data, 3), add.rownames = TRUE )
# set computed colors
MyFTable = setFlexTableBackgroundColors( MyFTable,
j = seq_len(ncol(data)) + 1,
colors = mycolors )
# cosmetics
MyFTable = setFlexTableBackgroundColors( MyFTable, i = 1,
colors = "gray", to = "header" )
MyFTable[1, , to = "header"] = textBold(color="white")
MyFTable = setFlexTableBackgroundColors( MyFTable, j = 1, colors = "gray" )
MyFTable[,1] = textBold(color="white")
MyFTable = setFlexTableBorders( MyFTable
, inner.vertical = borderProperties( style = "dashed", color = "white" )
, inner.horizontal = borderProperties( style = "dashed", color = "white" )
, outer.vertical = borderProperties( width = 2, color = "white" )
, outer.horizontal = borderProperties( width = 2, color = "white" )
)
#STOP_TAG_TEST
# }
Run the code above in your browser using DataLab