ggwidths | R Documentation |
Align two or more ggplots by scaling widths to equal size.
ggwidths(..., moreArgs)
... |
two or more ggplots |
moreArgs |
a list of additional arguments passed to
|
xx <- 0:100
dd <- data.frame(x = xx, y1 = sin(xx * pi / 10), y2 = xx ** 2, y3 = xx ** 3)
library('ggplot2')
p1 <- ggplot(dd, aes(x = x)) +
geom_line(aes(y = y1))
p2 <- ggplot(dd, aes(x = x)) +
geom_bar(aes(y = y2), stat = 'identity')
p3 <- ggplot(dd, aes(x = x)) +
geom_line(aes(y = x)) +
coord_cartesian(xlim = c(0,100))
library('gridExtra')
grid.arrange(p1, p2)
ggwidths(p1, p2, moreArgs = list(heights = c(1, 2)))
grid.arrange(p1, p2, p3)
ggwidths(p1, p2, p3)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.