r - R - cowplot:使用 plot_grid 排列 png 图像和 ggplot
问题描述
plot_grid
我正在尝试使用来自 cowplot 包的 png 图像和 ggplot 对象并排排列:
library(cowplot)
library(tableHTML)
sg <- data.frame(start = c(0,5,10),
end = c(10,20,30),
duration = c(10,15,20),
row.names = c("A","B","C"))
p1 <- ggplot(sg)+
geom_segment(aes(x=start, y=row_number(start), xend=end, yend=row_number(start)),
size = 3) +
scale_y_reverse(labels = NULL) +
labs(y = "", x = "") +
theme(aspect.ratio = 1/5)
sg %>%
tableHTML() %>%
add_theme("scientific") %>%
tableHTML_to_image(file = "image2.png", zoom = 2)
p2 <- ggdraw() + draw_image("image2.png", scale = 0.7)
plot_grid(p2, p1, ncol = 2, scale = c(0.9,1), rel_widths = c(1, 2))
但是,在生成的图中,我发现很难根据需要安排这两个图。
理想情况下,我希望表格图像的下边界与图表的 x 轴一致。我还希望这两个项目彼此更接近。
我曾尝试修改绘图 p2 的比例、命令中的缩放参数tableHTML_to_image
或命令中的比例、rel_widths、对齐和轴参数plot_grid
,但没有一个真正让我更接近所需的输出。
我还在这里阅读: 插入图像/PNG ggplot2 - Cowplot 但这仅用于在现有绘图内添加图像,而不是在它旁边。
虽然plot_grid
在安排两个 ggplot 时效果很好,但我无法用图像和 ggplot 来正确处理它。
解决方案
推荐阅读
- python - Python。从 Worker 发送信号
- javafx - 行开始/结束到嵌套的 javafx 组/窗格
- php - 从 MySQL 设置一个数组,然后将每个值设置为变量 PHP
- ionic-framework - Ionic 3 Virtual Scroll:更改项目大小
- python - 将 .shp 文件写入 S3
- python - Python - 即使使用常用方法也无法从另一个文件导入变量
- javascript - 用 javascript ipinfo 响应填充输入字段
- javascript - 动画数字计数器不添加逗号
- c# - 带有附加日期列的 EF6 多对多表
- php - 将多个表中的数据合并到具有多个值的数组中