将数学符号和下标与常规字母混合在R / ggplot2中 [英] putting mathematical symbols and subscripts mixed with regular letters in R/ggplot2

查看:1023
本文介绍了将数学符号和下标与常规字母混合在R / ggplot2中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在 ggplot2 中显示一个如下所示的标签:值为$ \sigma $,R ^ {2} = 0.6 其中值是是普通字体, $ \sigma $ 是一个希腊小写的西格玛字母和 R ^ {2} = 0.6 显示为 R ,上标 2 后跟等号( = ),后跟 0.6 。如何在ggplot factor s中使用它,并且在R的类型的 xlab,ylab 之类的参数中使用。感谢。

解决方案

$ c $ g $ ggplot(data = data.frame(x = 0,y = 0))+ geom_point(aes(x = x,y = y))
g + xlab (Value is,sigma,,,R ^ {2},'= 0.6')))

编辑

另一个选择是使用注释 parse = T

  g + annotate('text',x = 0,y = 0,
label =Value〜is〜sigma〜R ^ {2} == 0.6,parse = TRUE,size = 20)



编辑



paste 解决方案可能有用如果在绘图期间计算常数0.6。

  r2.value < -  0.90 
g + xlab(expression(paste(Value is,sigma, ,,R ^ {2},'=',r2.value)))


I want to plot a label that looks like this in ggplot2: 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 factors and in arguments to things like xlab,ylab of R? thanks.

解决方案

Something like this :

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

EDIT

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) 

EDIT

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

这篇关于将数学符号和下标与常规字母混合在R / ggplot2中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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