【问题标题】:Align two line legend title to the left with expression()用表达式()将两行图例标题向左对齐
【发布时间】:2017-02-10 08:40:37
【问题描述】:

使用这个脚本

df <- data.frame(x = 1:5, y = 1:5, color = letters[1:5])
ggplot(df, aes(x, y, fill = color)) +
  geom_point(size = 4, pch = 21) + 
  guides(fill = guide_legend(
     title = expression(atop(Median~Nitrate-Nitrogen~(NO[3]^{textstyle("-")}-N), ".\n Concentration"~(mg~L^{textstyle("-")})))))

我得到了这个数字

关于如何将图例标题的第二行左对齐有什么建议吗?

【问题讨论】:

  • @akrun 我不这么认为。
  • @akrun 谢谢。我很感激。
  • theme(legend.title.align = 0) 似乎只对“正常”的两行图例标题有效,但对表达式无效。

标签: r ggplot2 legend


【解决方案1】:

快速而丑陋的答案,但它可以完成工作,直到有人发布更好...

ggplot(df, aes(x, y, fill = color)) +
  geom_point(size = 4, pch = 21) + 
  guides(fill = guide_legend(
    title = expression(atop(Median~Nitrate-Nitrogen~(NO[3]^{textstyle("-")}-N), "Concentration"~(mg~L^{textstyle("-")})~phantom (1000000)~phantom (1000000)))))

【讨论】:

  • 感谢您的宝贵时间和帮助
猜你喜欢
  • 2017-12-08
  • 1970-01-01
  • 1970-01-01
  • 2017-11-26
  • 2015-03-22
  • 1970-01-01
  • 1970-01-01
  • 2011-01-19
  • 1970-01-01
相关资源
最近更新 更多