Align ggplot2 plots vertically

无人久伴 提交于 2019-11-26 05:27:29

问题


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\")

\"enter

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


回答1:


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



来源:https://stackoverflow.com/questions/17370853/align-ggplot2-plots-vertically

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!