2014-02-21 88 views
1

我希望剧情内部的传说是水平的(每一个彼此相邻,而不是一个在另一个之上)如何强制图中的图例水平而不垂直?

有没有办法从垂直变为水平? 例子:

mtcars$cyl <- factor(mtcars$cyl, labels=c("four","six","eight")) 
    ggplot(mtcars, aes(x=wt, y=mpg, colour=cyl)) + geom_point(aes(colour=cyl)) + 
    opts(legend.position = c(0, 1), title="Legend placement makes me sad") 

回答

1

您可以通过当你创建你的传奇将参数legend.direction="horizontal"theme()opts()

theme(legend.direction="horizontal") 

旧版本

opts(legend.direction="horizontal") 
2

内获得水平的传说,你可以使用参数'horiz'这会自动变为FALSE

legend(... , horiz=TRUE) 
+0

传说不适用于ggplot2 – user3236841