color_table: Creates a html or latex colored table

Description Usage Arguments Value Examples

View source: R/color_table.R

Description

Creates a html or latex colored table

Usage

1
2
3
4
color_table(x, body_bg = "#a6d96a", header_bg = "#74add1",
  body_color = "black", body_bold = FALSE, header_color = "black",
  header_bold = TRUE, align = "c", hide_body = FALSE, row_bgs = NA,
  col_bgs = NA, view = FALSE, cell_width = "15px", format)

Arguments

x

a matrix or data.frame to be displayed

body_bg

a single value or a matrix/data.frame of the same size of x with the background colors for the body of the table

header_bg

a single value or a vector of the same size as the number of columns of x, containing the background color(s) for the header

body_color

a single value or a matrix/data.frame of the same size of x with the text colors for the body of the table, if NA (default) takes the same value as the background color

body_bold

T/F if the body-text is bold

header_color

a single value or a vector of the same size as the number of columns of x, containing the text-color(s) for the header

header_bold

T/F if the header-text is bold

align

The alignment of the columns

hide_body

if the contents of the body of x are hidden (replaced with "")

row_bgs

a vector of colors for the rows (will be extended if necessary)

col_bgs

a vector of colors for the columns (will be extended if necessary)

view

T/F when the format is html, should it be displayed directly?

cell_width

a minimum width of the columns (applies to html only), defaults to 15px

format

a format for the code, is passed to knitr::kable, allowed is either html or latex

Value

the latex/html code (invisible in case of html-output and view = T)

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
x <- data.frame(x = 1:3, y = 2:4, z = 3:5)
color_table(x, format = "html", view = T)

# remove the text color of the body
color_table(x, body_color = NA, format = "html", view = T)
color_table(x, body_color = NA, header_color = NA, format = "html", view = T)

# remove the text color of the header
color_table(x, body_color = NA, header_color = NA, format = "html", view = T)

# change the colors:
color_table(x, body_color = "red", header_color = "white", format = "html",
            view = T)

color_table(x, body_color = "red", header_color = c("red", "green", "blue"),
            format = "html", view = T)

# color columns:
color_table(x, col_bgs = c("red", "green", "blue"), format = "html", view = T)

# color rows:
color_table(x, row_bgs = c("red", "green", "blue"), format = "html", view = T)
# can be subsets:
large_x <- data.frame(x = 1:9, y = 1:9, z = 1:9)
color_table(large_x, row_bgs = c("blue", "green"), format = "html", view = T)


# color cells individually
colors1 <- matrix(c("red", "green", "blue", "yellow", "purple", "white",
                    "black", "gray", "yellowgreen"),
                  nrow = nrow(x), ncol = ncol(x), byrow = T)

color_table(x, body_bg = colors1, format = "html", view = T)

# special case: body_bg/color contains the header-information as well
colors2 <- matrix(c("red", "red", "red",
                    "green", "blue", "green",
                    "blue", "green", "blue",
                    "green", "blue", "green"),
                  ncol = 3, byrow = T)
color_table(x, body_bg = colors2, format = "html", view = T)

# specify widths of the cell
x2 <- data.frame(x = 1:10, x2 = 2^(1:10))
color_table(x2, format = "html", view = T) -> a

color_table(x2, cell_width = "75px", format = "html", view = T)

DavZim/colorTable documentation built on May 28, 2019, 2:31 p.m.