I am using the gt package to great a table and I can't figure out why there are no values appearing in my summary rows.
I am able to format the group names, so it seems gt is recognizing the groups, but no luck with actual summary values. Am I missing something obvious?
Data and code:
library(gt)
df <- structure(list(Data.Source = c("Group A", "Group A", "Group A",
"Group A", "Group B", "Group B", "Group B", "Group B"),
Action_Bucket = c("Individuals Educated", "Warnings", "Part I Offence", "Part III Offence"),
Jan = c(0, 0, 0, 0, 0, 0, 0, 0), Feb = c(0, 0, 0, 0, 0, 0, 0, 0), Mar = c(0, 0, 0, 0, 0, 0, 0, 0),
Apr = c(3162, 20, 159, 19, 0, 3, 31, 1), May = c(13696, 7, 429, 9, 0, 18, 24, 0), Jun = c(8104, 4, 103, 1, 0, 0, 0, 0),
Jul = c(610, 2, 23, 4, 0, 0, 0, 0), Aug = c(304, 0, 2, 10, 0, 0, 0, 0), Sep = c(370, 0, 12, 3, 0, 0, 0, 0),
Oct = c(345, 5, 49, 2, 0, 0, 0, 0), Nov = c(0, 0, 0, 0, 0, 0, 3, 0)),
row.names = c(NA, -8L), class = "data.frame")
gt_table <- gt(df, groupname_col = "Data.Source") %>%
tab_header(
title = md("GT Table"),
subtitle = md("Subtitle")
) %>%
summary_rows(
groups = TRUE,
columns = vars(Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov),
fns = list(Total = "sum")) %>%
tab_options(
#heading.background.color = "#477DC0"
column_labels.background.color = "#477DC0",
row_group.background.color = '#D9E1F2',
table.font.size = 10
)
gt_table
Thank you!
See @Ben's comment - rowname_col needs to be specified.