图例标题在ggplot2中的位置 [英] Legend title position in ggplot2

查看:182
本文介绍了图例标题在ggplot2中的位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



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

  p < -  p + opts(legend.position ='bottom',legend.direction ='horizo​​ntal')

但现在我希望标题位于图例左侧而不是以上。我已经看过以下地方,但无法找到它或找出它:



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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆