将图例标题移近图例键

时间:2017-09-07 07:36:10

标签: r ggplot2 r-grid

我有以下情节:

library(grid)
library(ggplot2)

p <- 
  qplot(1:10, 1:10, color = letters[1:10]) + 
  theme_grey(base_size = 24)

enter image description here

但我希望传说标题更接近传奇键。我知道我可以将图例变白并使用grid.text覆盖它:

p <- 
  qplot(1:10, 1:10, color = letters[1:10]) + 
  theme_grey(base_size = 24) + 
  theme(legend.title = element_text(color = "white"))

grid.newpage()
grid.draw(p)
grid.text(x = 0.87, y = 0.7, label = "LETTERS")

enter image description here

但这种方法的缺点是缺乏灵活性。

我还尝试调整theme(legend.title = element_text(...))的参数,例如vjust = 1,但没有效果(apparently a known issue)。

是否有更好/规范的方法来修改图例标题位置?

0 个答案:

没有答案
相关问题