ggwidths: Scale ggplot widths

View source: R/ggplots.R

ggwidthsR Documentation

Scale ggplot widths

Description

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

Usage

ggwidths(..., moreArgs)

Arguments

...

two or more ggplots

moreArgs

a list of additional arguments passed to arrangeGrob

Examples

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. 19, 2023, 4:09 a.m.