Reputation: 179
How do I add color to the header (i.e the column names) of my data frame using the gt()
function in R
gt_Head <-
gt_Head %>%
tab_header(
title = md("**Table of First 10 Observations**")
)%>%
tab_style(
style = cell_text(weight = "bold"),
locations = cells_body(
rows = 0
)
)
Upvotes: 4
Views: 3759
Reputation: 9260
You can use the column_labels.background.color
option (see all options here), e.g.
library(gt)
head(mtcars, 10) |>
gt() |>
tab_header(
title = md("**Table of First 10 Observations**")
) |>
tab_options(column_labels.background.color = "blue")
Upvotes: 9
Reputation: 78947
Here is an example using exibble
dataset from gt
package.
As you can find here in the documentation https://gt.rstudio.com/reference/tab_options.html we could use heading.background.color
argument:
library(gt)
library(dplyr)
tab_1 <-
exibble %>%
dplyr::select(-c(fctr, date, time, datetime)) %>%
gt(
rowname_col = "row",
groupname_col = "group"
) %>%
tab_options(
heading.background.color = "#eebf00",
heading.border.bottom.color = "#eebd00",
heading.border.bottom.width = "5px",
heading.border.lr.color = "#aae100",
heading.border.lr.width = "50px", #no effect
) %>%
tab_header(
title = md("Data listing from **exibble**"),
subtitle = md("`exibble` is an R dataset")
) %>%
fmt_number(columns = num) %>%
fmt_currency(columns = currency) %>%
tab_footnote(
footnote = "Using commas for separators.",
locations = cells_body(
columns = num,
rows = num > 1000
)
) %>%
tab_footnote(
footnote = "Using commas for separators.",
locations = cells_body(
columns = currency,
rows = currency > 1000
)
) %>%
tab_footnote(
footnote = "Alphabetical fruit.",
locations = cells_column_labels(columns = char)
)
tab_1
Upvotes: 5