# NOT RUN {
# Use `countrypops` to create a gt table; add
# some styling to the summary data cells with
# with `tab_style()`, using `cells_summary()`
# in `locations`
tab_1 <-
countrypops %>%
dplyr::filter(
country_name == "Japan",
year < 1970) %>%
dplyr::select(-contains("country")) %>%
dplyr::mutate(
decade = paste0(substr(year, 1, 3), "0s")
) %>%
dplyr::group_by(decade) %>%
gt(
rowname_col = "year",
groupname_col = "decade"
) %>%
fmt_number(
columns = vars(population),
decimals = 0
) %>%
summary_rows(
groups = "1960s",
columns = vars(population),
fns = list("min", "max"),
formatter = fmt_number,
decimals = 0
) %>%
tab_style(
style = list(
cell_text(style = "italic"),
cell_fill(color = "lightblue")
),
locations = cells_summary(
groups = "1960s",
columns = vars(population),
rows = 1)
) %>%
tab_style(
style = list(
cell_text(style = "italic"),
cell_fill(color = "lightgreen")
),
locations = cells_summary(
groups = "1960s",
columns = vars(population),
rows = 2)
)
# }
Run the code above in your browser using DataLab