tangerine7199
tangerine7199

Reputation: 489

GGplot2-Legends w/ Multi Variables-Two Lines?

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")

enter image description here

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

Answers (1)

aosmith
aosmith

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")

enter image description here

Upvotes: 4

Related Questions