Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>you can do that by coord_cartesian() and align.plots in ggExtra.</p> <pre><code>library(ggplot2) library(ggExtra) # from R-forge p1 &lt;- qplot(x = 1, y = mpg, data = mtcars, xlab = "", geom = 'boxplot') + coord_flip(ylim=c(10,35), wise=TRUE) p2 &lt;- qplot(x = mpg, data = mtcars, geom = 'histogram') + coord_cartesian(xlim=c(10,35), wise=TRUE) align.plots(p1, p2) </code></pre> <p>Here is a modified version of align.plot to specify the relative size of each panel:</p> <pre><code>align.plots2 &lt;- function (..., vertical = TRUE, pos = NULL) { dots &lt;- list(...) if (is.null(pos)) pos &lt;- lapply(seq(dots), I) dots &lt;- lapply(dots, ggplotGrob) ytitles &lt;- lapply(dots, function(.g) editGrob(getGrob(.g, "axis.title.y.text", grep = TRUE), vp = NULL)) ylabels &lt;- lapply(dots, function(.g) editGrob(getGrob(.g, "axis.text.y.text", grep = TRUE), vp = NULL)) legends &lt;- lapply(dots, function(.g) if (!is.null(.g$children$legends)) editGrob(.g$children$legends, vp = NULL) else ggplot2:::.zeroGrob) gl &lt;- grid.layout(nrow = do.call(max,pos)) vp &lt;- viewport(layout = gl) pushViewport(vp) widths.left &lt;- mapply(`+`, e1 = lapply(ytitles, grobWidth), e2 = lapply(ylabels, grobWidth), SIMPLIFY = F) widths.right &lt;- lapply(legends, function(g) grobWidth(g) + if (is.zero(g)) unit(0, "lines") else unit(0.5, "lines")) widths.left.max &lt;- max(do.call(unit.c, widths.left)) widths.right.max &lt;- max(do.call(unit.c, widths.right)) for (ii in seq_along(dots)) { pushViewport(viewport(layout.pos.row = pos[[ii]])) pushViewport(viewport(x = unit(0, "npc") + widths.left.max - widths.left[[ii]], width = unit(1, "npc") - widths.left.max + widths.left[[ii]] - widths.right.max + widths.right[[ii]], just = "left")) grid.draw(dots[[ii]]) upViewport(2) } } </code></pre> <p>usage:</p> <pre><code># 5 rows, with 1 for p1 and 2-5 for p2 align.plots2(p1, p2, pos=list(1,2:5)) # 5 rows, with 1-2 for p1 and 3-5 for p2 align.plots2(p1, p2, pos=list(1:2,3:5)) </code></pre> <p><img src="https://i.stack.imgur.com/OsDUy.png" alt="align.plots2 second example"></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload