如何在ggplot中编写化学式 [英] How to write chemical formulas in ggplot
本文介绍了如何在ggplot中编写化学式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要绘制一些数据,并且其中之一必须在标签中包含硫酸盐分子式(SO42-).
I need to plot some data and one of the plot has to have the sulphate formula (SO42-) in the labels.
我正在使用此代码
a=c(1,2,3,4,5)
b=c(1,2,3,4,5)
dd=data.frame(a,b)
G<-ggplot(dd)+
geom_line(x=a, y=b, color="blue")+
labs(x="Depth (m)", y=expression("nss SO"[4]^{2-}"(ppb)"))
G
当然,这是行不通的:--写为2和ppb之间的破折号,或者在给了我一堆文字之后它什么也没做.我想念什么吗?
And, of course, it doesn't work: either the - is written as a dash between the 2 and the ppb or it simply does nothing after giving me a wall of text. Am I missing something?
推荐答案
首先,您缺少geom_line
的aes()
组件.对于表达式,您不太正确地使用语法.使用在此处中找到的信息,能够创建....
First, you're missing the aes()
component of geom_line
. For the expression, you're not quite hitting the syntax correctly. Using information found here, I was able to create....
library(ggplot2)
a=c(1,2,3,4,5)
b=c(1,2,3,4,5)
dd=data.frame(a,b)
G <-ggplot(dd)+
geom_line(aes(x=a, y=b), color = 'blue') + # need to include aes() designation here
labs(x="Depth (m)", y=expression("nss SO" ["4"] ^"2-"*" (ppb)"))
G
希望有效!
这篇关于如何在ggplot中编写化学式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文