Learn R Programming

ggguides (version 1.1.4)

legend_reverse: Reverse Legend Order

Description

Reverses the order of entries in all legends. Useful when the natural data order doesn't match the desired visual order (e.g., when stacking bars).

Usage

legend_reverse()

Arguments

Value

A guides specification that can be added to a plot.

Details

This function applies guide_legend(reverse = TRUE) to all common discrete aesthetics: colour, fill, shape, size, linetype, and alpha.

See Also

legend_wrap, legend_style

Examples

Run this code
library(ggplot2)

# Default order
p1 <- ggplot(mtcars, aes(mpg, wt, color = factor(cyl))) +
  geom_point()

# Reversed order
p2 <- p1 + legend_reverse()

Run the code above in your browser using DataLab