Reputation: 489
I'm working with bubble charts and I made up this one to ask this question. How would you get it so that the legend with two variables is also two lines? I would love for the legend to read
Cut: (color scheme)
line break
Price: (Size scheme)
test <- ggplot(diamonds, aes(x = carat, y = depth, size = price, fill = cut))
+ geom_point(shape=21) + theme(legend.position="bottom")
I've tried adding:
+ guide_legend(nrow = 2)
and that gave me:
Error: Don't know how to add o to a plot
Upvotes: 0
Views: 43
Reputation: 36084
You can use legend.box = "vertical"
.
ggplot(diamonds, aes(x = carat, y = depth, size = price, fill = cut)) +
geom_point(shape=21) +
theme(legend.position = "bottom", legend.box = "vertical")
Upvotes: 4