View source: R/scale_discrete_reverse.R
scale_y_discrete_reverse | R Documentation |
scale_y_discrete_reverse()
and scale_x_discrete_reverse()
are standard discrete 'ggplot2'
scales with a reversed order of values. Since the ggplot2 coordinate system starts with 0 in
the lower left corner, factors on the y-axis are sorted is descending order by default
(i.e. alphabetically from Z to A). With this scale the the y-axis will start with the
first factor level at the top or with alphabetically correctly ordered values
scale_y_discrete_reverse(
name = waiver(),
limits = NULL,
...,
expand = waiver(),
position = "left"
)
scale_x_discrete_reverse(
name = waiver(),
limits = NULL,
...,
expand = waiver(),
position = "bottom"
)
name |
The name of the scale. Used as the axis or legend title. If
|
limits |
Can be either NULL which uses the default reversed scale values or a character vector which will be reversed. |
... |
Arguments passed on to |
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_epigantt()
, ggplot2::scale_y_discrete()
library(ggplot2)
# Create sample data
df <- data.frame(
category = factor(c("A", "B", "C", "D")),
value = c(10, 5, 8, 3)
)
# Basic plot with reversed y-axis
ggplot(df, aes(x = value, y = category)) +
geom_col() +
scale_y_discrete_reverse()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.