[R] Expression in R graphics

1. expression

If you want to write math symbol or expression in R plot, you can use function expression, which give you a formed latex style. And the expression can be included in

  • plot title
    plot(..., main=expression(....))
    title(expression(...))
  • axis anotations
    plot(..., xlab=expression(...))
  • the plot panel itself
    text(x,y, expression(...))

You can use ?plotmath to see how to use math notations in expression. A simple example

# demo
windows()
par(mfrow=c(1,3))
curve(dnorm,-3,3, main=substitute(paste("Normal density: N(", mu,"=",mean,",", sigma^2,"=", sd,")"), list(mean=0,sd=1)), lwd=2, col="coral")

curve(dnorm,-3,3, main=expression(paste("Normal density:", mu, "=", 0, ",",sigma,"=",1 )), col="cornflowerblue",lwd=2)
text(-2,0.3, expression(paste(frac(1,sqrt(2*pi)*sigma),"", e^{-frac((x-mu)^2,2*sigma^2)})),cex=1.8)

curve(pnorm,-3,3, main=expression(paste("Normal distribution:", mu, "=", 0, ",", sigma, "=", 1)), col="green", lwd=2)
text(-2,0.3, expression(paste(frac(1,sqrt(2*pi)*sigma),"", integral(e^{-frac((t-mu)^2,2*sigma^2)}*dt, -infinity, x))), cex=1.9)

这里写图片描述

So we can see that paste is often used together with expression. If we need to use a value of parameter in expression, substitute may be a more efficient alternative solution.

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值