Learn R Programming

aplot (version 0.1.3)

xlim2: xlim2

Description

set axis limits (x or y) of a `ggplot` object (left hand side of `+`) based on the x (`xlim2`) or y (`ylim2`) limits of another `ggplot` object (right hand side of `+`). This is useful for using `cowplot` or `patchwork` to align `ggplot` objects.

Usage

xlim2(gg, limits = NULL)

ylim2(gg, limits = NULL)

Arguments

gg

ggplot object

limits

vector of limits. If NULL, determine from `gg`.

Value

ggplot2 object with new limits

Examples

Run this code
# NOT RUN {
library(ggplot2)
library(aplot)
p1 <- ggplot(mtcars, aes(cyl)) + geom_bar()
p2 <- ggplot(subset(mtcars, cyl != 4), aes(cyl)) + geom_bar()
p2 + xlim2(p1)
# }

Run the code above in your browser using DataLab