将数学符号和下标与常规字母混合在一起 [英] Putting mathematical symbols and subscripts mixed with regular letters
问题描述
我想在ggplot2
中绘制一个看起来像这样的标签:
I want to plot a label that looks like this in ggplot2
:
Value is $\sigma$, R^{2} = 0.6
,其中Value is
是普通字体,$\sigma$
是希腊小写西格玛字母,R^{2} = 0.6
显示为带有上标2
后跟等号(=
)的R
0.6
.如何在ggplot factor
s和R的xlab,ylab
之类的参数中使用它?
Value is $\sigma$, R^{2} = 0.6
where Value is
is ordinary font, $\sigma$
is a Greek lowercase sigma letter and R^{2} = 0.6
appears as an R
with a superscript 2
followed by equal sign (=
) followed by 0.6
. How can this be used in ggplot factor
s and in arguments to things like xlab,ylab
of R?
推荐答案
类似这样的东西:
g <- ggplot(data=data.frame(x=0,y=0))+geom_point(aes(x=x,y=y))
g+ xlab( expression(paste("Value is ", sigma,",", R^{2},'=0.6')))
编辑
另一种选择是将annotate
与parse=T
一起使用:
Another option is to use annotate
with parse=T
:
g+ annotate('text', x = 0, y = 0,
label = "Value~is~sigma~R^{2}==0.6 ",parse = TRUE,size=20)
编辑
如果在绘制过程中计算常数0.6,则paste
解决方案可能会很有用.
The paste
solution may be useful if the constant 0.6 is computed during plotting.
r2.value <- 0.90
g+ xlab( expression(paste("Value is ", sigma,",", R^{2},'=',r2.value)))
这篇关于将数学符号和下标与常规字母混合在一起的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!