Description Usage Arguments See Also Examples
This is a shortcut for supplying the limits
argument to the
individual scales. Note that, by default, any values outside the limits
will be replaced with NA
.
1 2 3 4 5 |
... |
A name-value pair. The name must be an aesthetic, and the value must be either a length-2 numeric, a character, a factor, or a date/time. A numeric value will create a continuous scale. If the larger value
comes first, the scale will be reversed. You can leave one value as
A character or factor value will create a discrete scale. A date-time value will create a continuous date/time scale. |
For changing x or y axis limits without dropping data
observations, see coord_cartesian
. To expand the range of
a plot to always include certain values, see expand_limits
.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | # Zoom into a specified area
ggplot(mtcars, aes(mpg, wt)) +
geom_point() +
xlim(15, 20)
# reverse scale
ggplot(mtcars, aes(mpg, wt)) +
geom_point() +
xlim(20, 15)
# with automatic lower limit
ggplot(mtcars, aes(mpg, wt)) +
geom_point() +
xlim(NA, 20)
# You can also supply limits that are larger than the data.
# This is useful if you want to match scales across different plots
small <- subset(mtcars, cyl == 4)
big <- subset(mtcars, cyl > 4)
ggplot(small, aes(mpg, wt, colour = factor(cyl))) +
geom_point() +
lims(colour = c("4", "6", "8"))
ggplot(big, aes(mpg, wt, colour = factor(cyl))) +
geom_point() +
lims(colour = c("4", "6", "8"))
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.