axis_limits | R Documentation |
Manage axis limits. Enforce certain points to be included (e.g. 0), and/or force axis limits to be the same between x- and y-axes.
axis_limits(p, expand_limits = NULL, axis_limits_equal = FALSE)
p |
object of class 'ggplot'. Limits are adjusted for this plot. |
expand_limits |
list. If not |
axis_limits_equal |
logical. If |
data('cars', package = 'datasets')
library(ggplot2)
p <- ggplot(cars, aes(speed, dist)) +
geom_point()
axis_limits(
p,
axis_limits_equal = TRUE)
# both axes
axis_limits(
p,
expand_limits = list(200))
# x only
axis_limits(
p,
expand_limits = list(x = 75))
# y only
axis_limits(
p,
expand_limits = list(y = 200))
# lower and upper expansion
axis_limits(
p,
expand_limits = list(y = c(-50, 200),
x = c(-10, 75)))
# note that when fixing range and expanding, range is fixed
# after expansions are applied, so effectively the larger expansions apply to both.
# compare the following output to the previous output:
axis_limits(
p,
expand_limits = list(y = c(-50, 200),
x = c(-10, 75)),
axis_limits_equal = TRUE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.