r - 将ggplot图和通过flextable获得的表格合并到网格中缺乏分辨率
问题描述
我正在尝试通过plot_grid
使用获得的绘图ggplot2
和使用获得的表格进行合并flextable()
。我从其他问题中看到了将转换为光栅的过程,但我意识到这样做会损失表格的分辨率。线条变得太粗了。我想拥有在我看来更好的原始分辨率弹性表。是否可以?
在原始代码下方:
library(ggplot2)
library(tidyverse)
library(ggthemes)
library(patchwork)
library(gridExtra)
library(grid)
library(cowplot)
library(flextable)
#generic, reproducible data
Graph1 <- data.frame(x = 1:100, y = runif(100))
Graph <- ggplot(Graph, aes(x = x)) + geom_line(aes(y = y)) + scale_x_discrete(expand = c(0,0)) #control axis parameters
`Sample name` <- c("Media1", "Media2")
`Valore medio Peel (N)` <- c(4.35, 4.31)
`Valore massimo Peel (N)` <- c(5.5, 6.5)
df <- data.frame(`Sample name`, `Valore medio Peel (N)`, `Valore massimo Peel (N)`)
df <- flextable(df)
df <- set_header_labels(df, Sample.name = "Sample name", `Valore.medio.Peel..N.` = "Valore medio peel (N)", `Valore.massimo.Peel..N.`= "Valore massimo Peel (N)")
df <- set_table_properties(df, layout = "autofit", width = .6)
df <- bold(df, bold = TRUE, part = "header")
df
##webshot::install_phantomjs() ##To be installed if needed
df <- as_raster(df, zoom = 2)
df <- ggplot() + theme_void() + annotation_custom(rasterGrob(df), xmin=-Inf, xmax=Inf, ymin=-Inf, ymax=Inf)
plot_grid(Graph, df, labels = NULL, ncol = 1, nrow = 2, scale = c(1, .75))
解决方案
推荐阅读
- ionic3 - Ionic storage Uncaught TypeError: Cannot read property 'storage' of null error when gettin onesignal playerid
- php - 如何将 $_POST 从 HTML 脚本传递到 PHP(出现“未定义索引”错误)
- php - 比较数组中多个值的最佳方法
- r - 如何使用 rvest 从 IMDB 获取电影的所有评论
- r - R根据条件从多个其他data.frames获取值
- vb.net - 在 vb.net 控制台应用程序中使用 URL 下载私有 Github 存储库
- java - 在 AWS Lambda (Java) 上的另一个线程上运行时出现 SSLHandshakeException
- android - java.lang.OutOfMemoryError 处理来自 Camera 的 14 个数据
- asp.net - 使用 System.IO.MemoryStream 处理相对较大的 zip 档案
- ssl - 在 thingsboard 上启用 HTTPS