ggplot multiple legends into one box

Solution 1:

I think you're looking for legend.box.background instead of legend.background:

ggplot(iris) +
  theme_classic() +
  geom_point(aes(x = Petal.Length, y = Sepal.Length, 
                 color = Species, size = Sepal.Width)) +
  theme(legend.position = c(0.1, 0.75), 
        legend.box.background = element_rect(fill = "white", color = "black"), 
        legend.spacing.y = unit(0,"cm"))

enter image description here