首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >具有gtable对象的arrangeGrob

具有gtable对象的arrangeGrob
EN

Stack Overflow用户
提问于 2013-04-11 14:45:26
回答 1查看 4K关注 0票数 4

https://stackoverflow.com/a/13295880中,我学会了如何用对齐的绘图区排列两个绘图。

我的问题是:我如何才能获得排列好的地块的对象?

示例:

代码语言:javascript
复制
require(ggplot2)
require(gridExtra)

A <- ggplot(CO2, aes(x=Plant)) + geom_bar() +coord_flip() 
B <- ggplot(CO2, aes(x=Type)) + geom_bar() +coord_flip() 

gA <- ggplot_gtable(ggplot_build(A))
gB <- ggplot_gtable(ggplot_build(B))
maxWidth = grid::unit.pmax(gA$widths[2:3], gB$widths[2:3])
gA$widths[2:3] <- as.list(maxWidth)
gB$widths[2:3] <- as.list(maxWidth)

## works:
grid.arrange(gA, gB, ncol=1)

## does not work:
theplot <- grid.arrange(gA, gB, ncol=1, plot=FALSE)
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-04-11 14:49:30

使用function arrangeGrob()将两个绘图另存为对象。

代码语言:javascript
复制
theplot <- arrangeGrob(gA, gB, ncol=1)
票数 5
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/15942313

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档