Reputation: 722
I'm kind of newbie in R and I'm trying to figure out how to use layout
to plot my 2 ggplots
next to each other with the help of multiplot
as well
Given 2 scaterplots:
p1 <- ggplot(mtcars, aes(wt, mpg))
p1 + geom_point()
p2 <- ggplot(mtcars, aes(wt, mpg))
p2 + geom_point()
y-axis are the same on both plots and it's of high importance to be in parallel. How can I produce the following layout:
-----------------------------
| | |
| | |
| p1 | p2 |
| | |
| | |
| | |
-----------------------------
Upvotes: 0
Views: 497
Reputation: 8072
I don't use multiplot
, but you can do this with gridExtra
and the command grid.arrange
using a custom layout_matrix
. You can learn more about grid.arrange
here.
EDIT: I'd listen to the creator of the package and use widths. If you get more complex later on use layout_matrix
library(ggplot2)
library(gridExtra)
p1 <- ggplot(mtcars, aes(wt, mpg)) + geom_point()
p2 <- ggplot(mtcars, aes(wt, mpg)) + geom_point()
grid.arrange(p1,p2, widths = c(1,2))
Upvotes: 2