如何将 gt table 插入到 ggplot2 折线图中

how to insert gt table into a ggplot2 line chart

我想将 gt table 插入到 ggplot2 折线图

下面是我的折线图代码

这是我的名为 value 的数据集,用于创建 ggplot2 折线图

Month Facevalue pct
January 36,434,456 -19
February 37,434,457 13
March 34,424,458 4
April 36,595,759 1
May 34,434,460 -6
June 44,434,461 54
July 22,434,462 -32
August 16,434,463 12
September 44,434,464 1
October 31,434,465 15
November 14,434,466 -4
December 11,434,467 9
p<-ggplot(data = value, aes(x=Month, y=Facevalue, group=1 , fill = Month))+
  geom_line(size = 1) +
  geom_point(color = "#0000FF" , shape = "diamond" , size = 8)+
  geom_text(aes(label = Facevalue), vjust = -0.5)+
  scale_y_continuous(label=scales::comma) +
  xlab("Monthly Face Value") + 
  ylab("Month")+
  labs(title =  "Polaris Bank Face value Trend from January to August 2021", element_text(face = "bold", colour = "white", size = 20))+
  theme_gray(base_size = 11)+
  theme(
        panel.border = element_rect(linetype = "dashed", fill = NA),
        panel.grid.major = element_line(colour = "#583759"),
        axis.line = element_line(size = 3, colour = "#0000FF"),
        axis.text = element_text(colour = "#400134"),
        axis.ticks = element_line(size = 0.5),
        axis.title.y = element_text(size = rel(1.5), angle = 90),
        axis.ticks.length.y = unit(.2, "cm"),
        panel.grid.minor = element_line(color = "red"),
  axis.ticks.length.x = unit(-.25, "cm"),
  axis.text.x = element_text(margin = margin(t = .3, unit = "cm")),
  legend.justification = "top")+
  scale_y_continuous(labels = unit_format(unit = "M", scale=1e-6))

p + coord_cartesian(ylim = c(1000000, 100000000))

它给出了下图中的图表

我的 gt table 是这样的 #create a table 并将其命名为 growth 增长 <-data.frame( Note=c("平均成功率:","平均处理时长:","平均每日计数:", “处理的总数:”), 六月=c({""},{""},{""},{""}), July=c({""},{""},{""},{""})) #创建数据框

 #insert the growth data frame in gt table
gt(growth)%>%
   tab_header("Point")%>%
  tab_options(table.width = pct(50))%>%
  tab_options(heading.background.color = "#7D0552", table.background.color = "lightcyan",
        table.font.size = px(14), table.font.color = "#000000", table.font.weight = "bold",
        )%>%
  cols_align(align = "center")%>%
  tab_style(
    style = cell_borders(
      sides = "all",
      color = "#7D0552",
      weight = px(2),
      style = "solid"),
    locations = cells_body(
      columns = everything(),
    rows = everything()))%>%
  cols_width(
    Note ~ px(200),
    ends_with(c("e","y")) ~ px(100),
    everything() ~ px(60))

这导致此 gt table 图片

那么如何将 gt(growth) 插入到 ggplot2 折线图中给出 下面是想要的输出图片

我能够通过使用 patchwork 包找到解决这个问题的方法

我要插入的table名字叫my_table

我的剧情是p

library (patchwork)
wrap_plots(p,my_table) 

在 return 中给出了问题的解决方案