R语言 将本Map像添加到更大的gt表头

jgwigjjp  于 2023-03-15  发布在  其他
关注(0)|答案(1)|浏览(133)

我正在尝试把这个头文件中的本Map像做得更大。我目前正在使用html代码来格式化R的gt表中的图像。
下面是我的代码示例:

library(tidyverse)
library(gt)

pizza_filename <- file.path("C:","
                            "Documents",
                            "pizza.png")

pizzaplace %>%
  mutate(type = case_when(
    type == "chicken" ~ "chicken (pizzas with chicken as a major ingredient)",
    type == "classic" ~ "classic (classical pizzas)",
    type == "supreme" ~ "supreme (pizzas that try a little harder)",
    type == "veggie" ~ "veggie (pizzas without any meats whatsoever)",
  )) %>%
  mutate(size = factor(size, levels = c("S", "M", "L", "XL", "XXL"))) %>%
  dplyr::group_by(type, size) %>%
  dplyr::summarize(
    sold = n(),
    income = sum(price)
  ) %>%
  gt(rowname_col = "size") %>%
  tab_header(title = html(gt::local_image(pizza_filename), "<b>", 
                          "Pizzas Sold",
                          "</b><br>", "in 2015")
               ) %>%
  fmt_number(
    columns = vars(sold),
    decimals = 0,
    use_seps = TRUE
  )

图像可以正确显示(和保存),这是我之前关于这个问题的一个重大改进。但是,现在我希望图像跨越标题文本的两行,而不仅仅是一行,如下面输出中绘制的红色框所示。这可能吗?

chy5wohz

chy5wohz1#

我建议使用常规的html表格格式,如:

tab_header(title = html("<table><tr><td align='center' valign='center'>", 
                      gt::local_image(pizza_filename, height = 120, width = 120),
                      "</td><td><b>Pizzas Sold</b><br>in 2015</td></tr></table>")

相关问题