GGplot2-Legends w / Multi Variables-Two Lines?

时间:2017-08-01 15:07:23

标签: r ggplot2

我正在使用气泡图,我编写了这个问题。你如何得到它,以便两个变量的图例也是两行?我很想读传说

剪切:(配色方案)

换行

价格:(尺寸方案)

test <- ggplot(diamonds, aes(x = carat, y = depth, size = price, fill = cut)) 
+     geom_point(shape=21) + theme(legend.position="bottom")

enter image description here

我尝试添加:

+ guide_legend(nrow = 2)

这给了我:

Error: Don't know how to add o to a plot

1 个答案:

答案 0 :(得分:4)

您可以使用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