ggplot2 reverse order of scale_brewer color
To reverse the order of the scale_brewer color in ggplot2, you can follow these steps:
- Load the required libraries:
library(ggplot2)
library(scales)
- Create a plot with the scale_brewer color palette:
ggplot(data = iris, aes(x = Sepal.Length, y = Sepal.Width, color = Species)) +
geom_point() +
scale_color_brewer(palette = "Set1")
- Reverse the order of the color scale by using the
trans
argument in thescale_color_brewer
function:
ggplot(data = iris, aes(x = Sepal.Length, y = Sepal.Width, color = Species)) +
geom_point() +
scale_color_brewer(palette = "Set1", trans = "reverse")
By following these steps, you can reverse the order of the scale_brewer color in ggplot2.