❝本节来介绍如何使用「gtExtras」包来针对「gt」绘制的表格做增强,下面小编就来通过几个案例做演示,希望各位观众老爷能够喜欢。更多详细内容请参考作者官方文档 ❞
❝https://jthomasmock.github.io/gtExtras/ ❞
install.packages("gtExtras")
library(tidyverse)
library(gtExtras)
library(gt)
head(mtcars) %>% gt() %>% gt_theme_538()
head(mtcars) %>% gt() %>% gt_theme_espn()
head(mtcars) %>% gt() %>%
gt_theme_nytimes() %>%
tab_header(title = "Table styled like the NY Times")
head(mtcars) %>% gt::gt() %>% gt_hulk_col_numeric(mpg)
head(mtcars) %>% gt::gt() %>%
gt_hulk_col_numeric(mpg:disp, trim = TRUE)
mtcars %>% head() %>% gt() %>%
gt_color_rows(cyl,
palette = "ggthemes::colorblind",
domain = range(mtcars$cyl),
pal_type = "discrete")
head(mtcars[,1:5]) %>%
tibble::rownames_to_column("car") %>% gt() %>%
gt_highlight_rows(rows = 2, font_weight = "normal")
head(mtcars[,1:5]) %>%
tibble::rownames_to_column("car") %>%
gt() %>%
gt_highlight_rows(
rows = 5,
fill = "lightgrey",
bold_target_only = TRUE,
target_col = car)
mtcars %>%
dplyr::group_by(cyl) %>%
dplyr::summarize(mpg_data = list(mpg), .groups = "drop") %>%
gt() %>%
gt_plt_sparkline(mpg_data)
mtcars %>%
head() %>%
dplyr::select(cyl, mpg) %>%
dplyr::mutate(mpg_pct_max = round(mpg/max(mpg) * 100, digits = 2),
mpg_scaled = mpg/max(mpg) * 100) %>%
dplyr::mutate(mpg_unscaled = mpg) %>%
gt() %>%
gt_plt_bar_pct(column = mpg_scaled, scaled = TRUE) %>%
gt_plt_bar_pct(column = mpg_unscaled, scaled = FALSE, fill = "blue", background = "lightblue") %>%
cols_align("center", contains("scale")) %>%
cols_width(4 ~ px(125),5 ~ px(125))