图例标题在ggplot2中的位置 [英] Legend title position in ggplot2
问题描述
我使用下面的代码将图例移动到底部并使其水平
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.9作为参考,您可以尝试(假设你想改变颜色
图例的标题位置):
library(scale)
+ guides(color = guide_legend(title.position =left))
对于连续比例,您可以使用 guide_colorbar
而不是 guide_legend
。
只是为了提供一个具体的例子来证明我不只是做这件事,
library(ggplot2)
library(scales)
p < - ggplot(mtcars,aes(wt,mpg))
p + color = guide_legend(title.position =right))
Anone know how to change the position of the legend title in ggplot?
I have used the following code to move the legend to the bottom and make it horizontal
p <- p + opts(legend.position = 'bottom', legend.direction = 'horizontal')
But now I want the title to be to the left of the legend instead of above. I've looked in the follwing places but cant find it or figure it out:
https://github.com/hadley/ggplot2/wiki/Legend-Attributes http://had.co.nz/ggplot2/book/toolbox.r
Any assistance would be greatly appreciated
Using the transition guide to version 0.9 as a reference, you might try the following (assuming you want to change the title position for the colour
legend):
library(scales)
+ guides(colour = guide_legend(title.position = "left"))
For a continuous scale you'd use guide_colorbar
instead of guide_legend
.
Just to provide a concrete example to prove I'm not just making this up,
library(ggplot2)
library(scales)
p <- ggplot(mtcars, aes(wt, mpg))
p + geom_point(aes(colour = qsec)) +
guides(colour = guide_legend(title.position = "right"))
这篇关于图例标题在ggplot2中的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!