The cells_stub_summary()
function
Use a portion of the countrypops
dataset to create a gt table. Add some styling to the summary data stub cells with tab_style()
and cells_stub_summary()
in the locations
argument.
countrypops |>
dplyr:: filter (country_name == "Japan" , year < 1970 ) |>
dplyr:: select (- contains ("country" )) |>
dplyr:: mutate (decade = paste0 (substr (year, 1 , 3 ), "0s" )) |>
gt (
rowname_col = "year" ,
groupname_col = "decade"
) |>
fmt_integer (columns = population) |>
summary_rows (
groups = "1960s" ,
columns = population,
fns = list ("min" , "max" ),
fmt = ~ fmt_integer (.)
) |>
tab_style (
style = list (
cell_text (
weight = "bold" ,
transform = "capitalize"
),
cell_fill (
color = "lightblue" ,
alpha = 0.5
)
),
locations = cells_stub_summary (
groups = "1960s"
)
)
population
1960s
1960
93,216,000
1961
94,055,000
1962
94,933,000
1963
95,900,000
1964
96,903,000
1965
97,952,000
1966
98,851,000
1967
99,879,000
1968
101,011,000
1969
102,219,000
min
93,216,000
max
102,219,000