scale_continuous_diverging | R Documentation |
These scales automatically create symmetrical limits around a centre point (zero by default).
They're useful for diverging continuous variables where the visual encoding should
be balanced around a center point, such as positive and negative values.
They are intended to be used with geom_bar_diverging()
, geom_area_diverging()
and stat_diverging()
.
scale_x_continuous_diverging(
name = waiver(),
limits = NULL,
labels = NULL,
transform = "identity",
...,
breaks = waiver(),
n.breaks = NULL,
expand = waiver(),
position = "bottom"
)
scale_y_continuous_diverging(
name = waiver(),
limits = NULL,
labels = NULL,
transform = "identity",
...,
breaks = waiver(),
n.breaks = NULL,
expand = waiver(),
position = "left"
)
name |
The name of the scale. Used as the axis or legend title. If
|
limits |
Numeric vector of length two providing limits of the scale.
If |
labels |
Either |
transform |
Defaults to "identity". Use "reverse" to invert the scale. Especially useful to flip the direction of diverging bar charts. |
... |
Other arguments passed on to |
breaks |
One of:
|
n.breaks |
An integer guiding the number of major breaks. The algorithm
may choose a slightly different number to ensure nice break labels. Will
only have an effect if |
expand |
For position scales, a vector of range expansion constants used to add some
padding around the data to ensure that they are placed some distance
away from the axes. Use the convenience function |
position |
For position scales, The position of the axis.
|
A ggplot2
scale object that can be added to a plot.
geom_bar_diverging()
, geom_area_diverging()
, stat_diverging()
library(ggplot2)
# Create sample data with positive and negative values
df <- data.frame(
x = c(-5, -2, 0, 3, 7),
y = c(2, -1, 0, -3, 5)
)
# Basic usage
ggplot(df, aes(x, y)) +
geom_point() +
scale_x_continuous_diverging() +
scale_y_continuous_diverging()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.