有人知道如何在ggplot中更改图例标题的位置吗?
我使用以下代码将图例移到底部并使其水平
p <- p + opts(legend.position = 'bottom', legend.direction = 'horizontal')
但现在我希望标题位于图例左侧而不是上方。我看了下面的地方,但无法找到它或弄明白:
https://github.com/hadley/ggplot2/wiki/Legend-Attributes http://had.co.nz/ggplot2/book/toolbox.r
非常感谢任何帮助
答案 0 :(得分:13)
使用transition guide版本0.9作为参考,您可以尝试以下操作(假设您要更改colour
图例的标题位置):
library(scales)
+ guides(colour = guide_legend(title.position = "left"))
对于连续缩放,您使用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"))