# NOT RUN {
# Use `pizzaplace` to create a gt table;
# format the `f_sold` and `f_income`
# columns to display fractions
tab_1 <-
pizzaplace %>%
dplyr::group_by(type, size) %>%
dplyr::summarize(
sold = dplyr::n(),
income = sum(price),
.groups = "drop_last"
) %>%
dplyr::group_by(type) %>%
dplyr::mutate(
f_sold = sold / sum(sold),
f_income = income / sum(income),
) %>%
dplyr::arrange(type, dplyr::desc(income)) %>%
gt(rowname_col = "size") %>%
tab_header(
title = "Pizzas Sold in 2015",
subtitle = "Fraction of Sell Count and Revenue by Size per Type"
) %>%
fmt_integer(columns = sold) %>%
fmt_currency(columns = income) %>%
fmt_fraction(
columns = starts_with("f_"),
accuracy = 10,
simplify = FALSE
) %>%
fmt_missing(
columns = everything(),
missing_text = ""
) %>%
tab_spanner(
label = "Sold",
columns = contains("sold")
) %>%
tab_spanner(
label = "Revenue",
columns = contains("income")
) %>%
text_transform(
locations = cells_body(),
fn = function(x) {
dplyr::case_when(
x == 0 ~ "<em>nil</em>",
x != 0 ~ x
)
}
) %>%
cols_label(
sold = "Amount",
income = "Amount",
f_sold = md("_f_"),
f_income = md("_f_")
) %>%
cols_align(align = "center", columns = starts_with("f")) %>%
tab_options(
table.width = px(400),
row_group.as_column = TRUE
)
# }
Run the code above in your browser using DataLab