ggwidths: Scale ggplot widths

Description Usage Arguments Examples

View source: R/ggplots.R

Description

Align two or more ggplots by scaling widths to equal size.

Usage

1
ggwidths(..., moreArgs)

Arguments

...

two or more ggplots

moreArgs

a list of additional arguments passed to arrangeGrob

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
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)

raredd/plotr documentation built on Nov. 13, 2018, 7:05 a.m.