【问题标题】:Forcing tableGrob() to fit in .tiff file强制 tableGrob() 适合 .tiff 文件
【发布时间】:2020-07-09 18:31:57
【问题描述】:

我正在尝试将 tableGrob 输出为 .tiff,但它有点长。我试图让表格区域适合 .tiff 文件,但它总是被切断,除非我将字体大小大幅更改为不可读的大小。有没有办法强制 tableGrob find 到 .tiff 文件而不被任何切断?

table.plot <- structure(list(A = c(2.8, 0.5, 1.3, 5.7, 6.5, 1.1, 3.3, 1, 16.9, 
8.6, 6.3, 22.2, 14.8, 1.3, 7.9, 12.4, 31, 9.9, 13.2, 26.2, 2), 
    B = c(13.7, 10.6, 12.7, 20.6, 13.2, 11.2, 14.7, 11.7, 22.3, 
    12.9, 12.9, 19.5, 20.6, 11.1, 17, 20.3, 43.1, 18.2, 20.9, 
    26.7, 10.1), C = c(0.4, 0, 0.3, 1, 0.3, 0.1, 0.5, 0.2, 1.2, 
    0.3, 0.3, 0.9, 1, 0.1, 0.7, 1, 3.3, 0.8, 1.1, 1.6, 0), D = c(29.7, 
    18, 23.9, 46.2, 33.1, 20.1, 32.6, 21.1, 93.1, 39.9, 33, 116.8, 
    76.1, 21.4, 49, 66.7, 166.5, 53.7, 69.1, 127.4, 21)), row.names = c("G01", 
"G02", "G03", "G04", "G05", "G06", "G07", "G08", "G09", "G10", 
"G11", "G12", "H01", "H02", "H03", "H04", "H05", "H06", "H07", 
"H08", "Host.1"), class = "data.frame")

tt1 <- ttheme_minimal(
  core = list(fg_params = list(fontsize = 8), 
              padding = unit(c(0.1, 0.1), "mm")),
  colhead = list(bg_params = list(fill = "white"), 
                 fg_params = list(fontsize = 8, fontface = "bold")), 
  rowhead = list(fg_params = list(fontsize = 8, fontface = "bold"))
)

g <- tableGrob(table.plot, theme = tt1)


g <- gtable_add_grob(g,
                     grobs = rectGrob(gp = gpar(fill = NA, lwd = 2)),
                     t = 2, b = nrow(g), l = 1, r = ncol(g))
g <- gtable_add_grob(g,
                     grobs = rectGrob(gp = gpar(fill = NA, lwd = 2)),
                     t = 1, l = 1, r = ncol(g))

save_plot("table is cut off.tiff", g, dpi = 300)

【问题讨论】:

    标签: r


    【解决方案1】:

    假设save_plot来自cowplot包(有不止一个包有一个名为save_plot的函数),你可以像这样指定高度和纵横比:

    save_plot("table isnt cut off.tiff", g, dpi = 300, base_height = 5.5, base_asp = 0.4)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多