将两行图例标题与表达式()左对齐 [英] Align two line legend title to the left with expression()

查看:150
本文介绍了将两行图例标题与表达式()左对齐的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用这个脚本

  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),浓度〜(mg〜L ^ {textstyle( - )}))))

我得到了这个数字





如何将图例标题的第二行对齐到左侧? / p>

解决方案

快速且丑陋的答案,但它的工作,直到有人发布更好... ...

  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] ^ {texts tyle( - )} - N),Concentration〜(mg〜L ^ {textstyle( - )})〜幻像(1000000)〜幻像(1000000)))))


Using this script

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("-")})))))

I got this figure

Any suggestions how to align the second line of the legend title to the left?

解决方案

quick and ugly answer but it does the job until someone post better...

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)))))

这篇关于将两行图例标题与表达式()左对齐的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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