# packages library(ggplot2)library(dplyr)
# set default global themetheme_set(theme_bw() + theme(legend.title = element_text(face = "bold", size = 12)))
<- iris %>% p ggplot(aes(x = Sepal.Length, y = Sepal.Width, shape = Species, color = Petal.Length, size = Petal.Width)) + geom_point(position = position_jitter(.2, .2, 1)) + scale_color_distiller(palette = "Spectral")
p
Reorder Multiple Legends in ggplot2
This tutorial explains how to rearrange the order of multiple legends.
Create a plot with many legends
Reorder three legends layout
Note that in the guides()
function, the continuous color bar is called “colorbar”, and discrete legends as “legend”. This differentiation does not apply in the theme()
function, where both colorbar and discrete legends are known as the “legend”.
+ p guides(shape = guide_legend(order = 1), color = guide_colorbar(order = 2))