下标和上标“-"表示或"+" ggplot2轴标签? (离子化学符号) [英] Subscripts and superscripts "-" or "+" with ggplot2 axis labels? (ionic chemical notation)

查看:197
本文介绍了下标和上标“-"表示或"+" ggplot2轴标签? (离子化学符号)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用下面的代码得到了这个情节

I got this plot using the code below

在我的情节中,我希望NO3带有负号-",如下图所示

In my plot, I want the NO3 to have negative sign"-" as superscript like below

在x轴的标签中,我不能仅使用负号作为NO3的上标,因此我必须使用-1,如下所示

In the label of x axis, I couldn't use negative sign only as a superscript to NO3 so I had to use -1 as shown below

x <- seq(0,2*pi,0.1)
y <- sin(x)

df <- data.frame(x, y)
ggplot(df, aes(x=x, y=y))+
geom_point(size=4)+
labs(x=expression(Production~rate~" "~mu~moles~NO[3]^{-1}-N~Kg^{-1}),
     y=expression(Concentration~mg~L^{-1})) 

关于如何将标签更改为仅不带负号的任何建议?

Any suggestions on how to change the label to have a negative sign only without 1?

推荐答案

尝试在上标运算符后引用减号:

Try quoting the minus sign after the superscript operator:

ggplot(df, aes(x=x, y=y))+
geom_point(size=4)+
labs(x=expression(Production~rate~" "~mu~moles~NO[3]^{"-"}-N~Kg^{-1}),
     y=expression(Concentration~mg~L^{-1})) +
theme(legend.title = element_text(size=12, face="bold"),
      legend.text=element_text(size=12),
      axis.text=element_text(size=12),
      axis.title = element_text(color="black", face="bold", size=18))

我认为在单元之间使用%.%运算符看起来更科学准确:

I think it looks more scientifically accurate to use the %.% operator between units:

+ labs(x=expression(Production~rate~" "~mu~moles~NO[3]^{textstyle("-")}-N %.% Kg^{-1}),
     y=expression(Concentration~mg~L^{-1})) +

textstyle应该防止上标文本缩小.我也不确定为什么在两个波浪号之间有一个" ".您可以将一大串波浪号串在一起以增加空间":

textstyle should keep the superscript-ed text from being reduced in size. I'm also not sure why you have a " " between two tildes. You can string a whole bunch of tildes together to increase "spaces":

ggplot(df, aes(x=x, y=y))+
geom_point(size=4)+
labs(x=expression(Production~rate~~~~~~~~~~~~mu~moles~NO[3]^{textstyle("-")}-N %.% Kg^{-1}),
     y=expression(Concentration~mg~L^{-1})) +
theme(legend.title = element_text(size=12, face="bold"),
      legend.text=element_text(size=12),
      axis.text=element_text(size=12),
      axis.title = element_text(color="black", face="bold", size=18))

还有一个奖励的绘图员技巧:引用数字是一种避免记录在使用绘图员生成斜体数字的难度上的方法. (使用italic(123)不会成功,...但是italic("123")会成功.)

And a bonus plotmath tip: Quoting numbers is a way to get around the documented difficulty in producing italicized digits with plotmath. (Using italic(123) does not succeed, ... but italic("123") does.)

这篇关于下标和上标“-"表示或"+" ggplot2轴标签? (离子化学符号)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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