r - 多个绘图的自定义布局和标签 (GGPLOT2)
问题描述
我使用以下代码创建了一个绘图列表:
plots <- list()
for(i in 1:(k*k)){
plots[[i]] <- ggplot(subset(mean_conf, Names == Names[i]), aes(x=nob)) +
geom_line (aes(y = Mean), color = "black") +
geom_line (aes(y = Left_Interval), color="black", linetype="twodash") +
geom_line (aes(y = Right_Interval), color="black", linetype="twodash") +
theme(axis.title.x=element_blank(),axis.title.y=element_blank()) + expand_limits(y = 0)
}
使用 grid.arrange 函数(do.call(grid.arrange,plots)
)带来下图
我检查了不同的功能,但找不到解决问题的方法。我将不胜感激任何建议、建议和帮助。
解决方案
gridExtra 和 grid 可能是您所追求的布局的朋友。
这是10的首发。
library(ggplot2)
library(gridExtra)
library(grid)
p <- ggplot(mtcars, aes(disp, wt)) + geom_line()
ver <- textGrob("Plots verion 1", gp = gpar(fontsize = 15))
A_top <- textGrob("A", gp = gpar(fontsize = 15))
A_left <- textGrob("A", gp = gpar(fontsize = 15), x = unit(45, "mm"), y = unit(15, "mm") )
B_top <- textGrob("B", gp = gpar(fontsize = 15))
B_left <- textGrob("B", gp = gpar(fontsize = 15), x = unit(45, "mm"), y = unit(15, "mm"))
grid.arrange(ver, A_top, B_top, A_left, p, p, B_left, p, p,
top = textGrob("Title", gp=gpar(fontsize = 20), x = unit(125, "mm")),
bottom = textGrob("Subtitle", gp=gpar(fontsize = 10), x = unit(65, "mm")),
ncol = 3,
widths = unit(c(50, 75, 75), "mm"),
heights = unit(c(10, 75, 75), "mm"))
这给了你:
可以探索以下链接以优化布局
https://cran.r-project.org/web/packages/gridExtra/vignettes/arrangeGrob.html#title-andor-annotations
推荐阅读
- android - 如何在菜单项单击时退出我的应用程序?
- winapi - 发送消息 TVM_EDITLABEL 失败
- android - 当我计算食物的平均评分时,将此值保存到显示为 0.0 的食物对象中
- .net-core - 在 .NET Core 3.1 中读取 RSS 不起作用
- javascript - 制作屏幕截图时 Puppeteer 和 Playwright chrome headful bug
- php - Laravel queue worker can't process jobs # 错误日志 local.ERROR: Class does not exist {"exception":"[object] (ReflectionException(code
- flutter - Flutter (Dart):合并两个视频并在设备的图库中查看新输出(照片)
- python - 'BlogPost' 对象没有属性 'post_id' + 无法显示 blog_post_id 与 blog_validated_id 相同的评论
- node.js - 在节点 js 中创建忘记密码功能的问题
- image-processing - 微弱但可见的单色边缘检测