我怎样才能通过他们的标题来对齐多个地块而不是地块面积?

编程入门 行业动态 更新时间:2024-10-28 11:19:16
本文介绍了我怎样才能通过他们的标题来对齐多个地块而不是地块面积?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我使用软件包

left_col < - cowplot :: plot_grid(p1 + ggtitle(),p2 + ggtitle(), labels = c('a)', 'b)'),label_size = 14, ncol = 1,align ='v',axis ='lr') cowplot :: plot_grid(left_col,p3 + ggti tle(), labels = c('','c)'),label_size = 14, align ='h',axis ='b')

请参阅还

I'm using egg package developed by @baptiste. Below is an example from github. I'm wondering if it's possible to align two columns by the titles a) and c) instead of plot area? Thanks!

Code:

library(egg) library(grid) p1 <- ggplot(mtcars, aes(mpg, wt, colour = factor(cyl))) + geom_point() + ggtitle("a)") p1 p2 <- ggplot(mtcars, aes(mpg, wt, colour = factor(cyl))) + geom_point() + facet_wrap(~ cyl, ncol = 2, scales = "free") + guides(colour = "none") + theme() + ggtitle("b)") p2 p3 <- ggplot(mtcars, aes(mpg, wt, colour = factor(cyl))) + geom_point() + facet_grid(. ~ am, scales = "free") + guides(colour="none") + ggtitle("c)") p3 g1 <- ggplotGrob(p1) g2 <- ggplotGrob(p2) g3 <- ggplotGrob(p3) fg1 <- gtable_frame(g1, debug = TRUE) fg2 <- gtable_frame(g2, debug = TRUE) fg12 <- gtable_frame(gtable_rbind(fg1, fg2), width = unit(2, "null"), height = unit(1, "null")) fg3 <- gtable_frame( g3, width = unit(2, "null"), height = unit(1, "null"), debug = TRUE ) grid.newpage() combined <- gtable_cbind(fg12, fg3) grid.draw(combined)

Plot:

解决方案

I found another way by using cowplot package

left_col <- cowplot::plot_grid(p1 + ggtitle(""), p2 + ggtitle(""), labels = c('a)', 'b)'), label_size = 14, ncol = 1, align = 'v', axis = 'lr') cowplot::plot_grid(left_col, p3 + ggtitle(""), labels = c('', 'c)'), label_size = 14, align = 'h', axis = 'b')

See also here

Edit:

A recently developed package patchwork for ggplot2 can also get the job done

library(patchwork) { p1 + {p2} + patchwork::plot_layout(ncol = 1) } / p3 + patchwork::plot_layout(ncol = 2)

更多推荐

我怎样才能通过他们的标题来对齐多个地块而不是地块面积?

本文发布于:2023-07-19 16:59:28,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1158544.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:地块   他们的   多个   而不是   面积

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!