ggplot2中的图例标题位置

Mik*_*eTP 12 position r legend ggplot2

Anone知道如何在ggplot中更改图例标题的位置?

我使用以下代码将图例移到底部并使其水平

p <- p + opts(legend.position = 'bottom', legend.direction = 'horizontal')
Run Code Online (Sandbox Code Playgroud)

现在我希望标题位于图例的左侧而不是上方.我看了下面的地方,但无法找到它或弄明白:

https://github.com/hadley/ggplot2/wiki/Legend-Attributes http://had.co.nz/ggplot2/book/toolbox.r

任何帮助将不胜感激

jor*_*ran 14

使用版本0.9 的过渡指南作为参考,您可以尝试以下操作(假设您要更改colour图例的标题位置):

library(scales)
+ guides(colour = guide_legend(title.position = "left"))
Run Code Online (Sandbox Code Playgroud)

对于连续的比例,你可以使用guide_colorbar而不是guide_legend.

只是提供一个具体的例子来证明我不仅仅是这样做,

library(ggplot2)
library(scales)
p <- ggplot(mtcars, aes(wt, mpg))
p + geom_point(aes(colour = qsec)) + 
    guides(colour = guide_legend(title.position = "right"))
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述