我想让我的ggplot图例并排显示在图的下方,变量名在符号上方,就像它们在this博客文章中一样(第二个图)。 opts函数现已失效,并且theme似乎没有复制其行为...

library("ggplot2")
ggplot(diamonds, aes(x = carat, y=price, shape = cut, group=interaction(cut, color), color=color)) +
geom_point() +
#opts(legend.direction = "horizontal", legend.position = "bottom")
#potential options, not all seem have an effect...
theme(legend.direction = "horizontal") +
theme(legend.position = "bottom") +
theme(legend.box = "vertical") +
theme(legend.title.align = 0)

...利用我的MS绘画技巧来说明所需的情节。

最佳答案

您需要指定theme(legend.box = "horizontal")
尝试这个:

library("ggplot2")
ggplot(diamonds, aes(x = carat, y=price, shape = cut, group=interaction(cut, color), color=color)) +
  geom_point() +
  theme(legend.direction = "horizontal",
        legend.position = "bottom",
        legend.box = "horizontal"
        )

关于r - ggplot2中的并排水平图例,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/28065604/

10-12 17:11