垂直对齐ggplot2图 [英] Align ggplot2 plots vertically

查看:127
本文介绍了垂直对齐ggplot2图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用

指定ggplot2面板宽度
将相关矩阵绘制成图

解决方案

格网)
库(gtable)

p < - qplot(1,1)
g < - ggplotGrob(p)

panel_id < g $ layout [g $ layout $ name ==panel,c(t,l)]
g < - gtable_add_cols(g,unit(1,cm))

g < - gtable_add_grob(g,rectGrob(gp = gpar(fill =red)),
t = panel_id $ t,l (g,单元(1,in),0)
g <-gtable_add_grob(g,rectGrob(gp = gpar(fill) =blue)),
t = 1,l = panel_id $ l)

grid.newpage()
grid.draw(g)



和您的帐户




With the code found at https://gist.github.com/low-decarie/5886616 A dual dendodogram tile plot can be produced:

dual_dendogram_tile_plot(as.matrix(USArrests), main="USA Arrests")

The problem: Align the vertical dendogram with the tile plot area. (and/or improve the alignment of the horizontal dendogram)

This question relates to:

left align two graph edges (ggplot)
Specifying ggplot2 panel width Plot correlation matrix into a graph

解决方案

Here's an example to align more basic grobs,

library(ggplot2)
library(grid)
library(gtable)

p <- qplot(1,1)
g <- ggplotGrob(p)

panel_id <- g$layout[g$layout$name == "panel",c("t","l")]
g <- gtable_add_cols(g, unit(1,"cm"))

g <- gtable_add_grob(g, rectGrob(gp=gpar(fill="red")),
                     t = panel_id$t, l = ncol(g))

g <- gtable_add_rows(g, unit(1,"in"), 0)
g <- gtable_add_grob(g, rectGrob(gp=gpar(fill="blue")),
                     t = 1, l = panel_id$l)

grid.newpage()
grid.draw(g)

and with your grobs

这篇关于垂直对齐ggplot2图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆