R语言中特殊符号的使用

电子说

1.3w人已加入

描述

有时候我们需要在图形上添加特殊符号,比如希腊字母和斜体字。有时候,我们还希望在图形上添加数学注释。在R语言中,我们可以使用expression()函数来完成这个任务。

希腊字母:

## 1 alpha
## 2 beta  
## 3 gamma  
## 4 delta
## 5 epsilon
## 6 zeta
## 7 eta
## 8 theta
## 9 iota  
## 10 kappa  
## 11 lambda
## 12 mu  
## 13 nu
## 14 xi
## 15 omicron  
## 16 pi
## 17 rho  
## 18 (final) sigma
## 19 sigma  
## 20 tau
## 21 upsilon
## 22 phi  
## 23 chi
## 24 psi  
## 25 omega  
Greek_text <- c("alpha", "beta", "gamma", "delta", "epsilon", "zeta", "eta", "theta", "iota", "kappa",  "lambda", "mu", "nu", "xi", "omicron",  "pi",  "rho",  "sigma", "tau", "upsilon", "phi",   "chi", "psi", "omega")
greek <- c(expression(alpha), expression(beta), expression(gamma), expression(delta), expression(epsilon), expression(zeta), expression(eta), expression(theta), expression(iota), expression(kappa), expression(lambda), expression(mu), expression(nu), expression(xi), expression(omicron), expression(pi), expression(rho), expression(sigma), expression(tau), expression(upsilon), expression(phi), expression(chi), expression(psi), expression(omega))
y_coord <- vector(mode = "numeric", length = 23L)
for(i in 1:23) {y_coord[i] <- 1 + 3*i}
plot(1:70, type = "n", ylab = "", xlab = "", axes = FALSE)
for(i in 1:24){
text(10, y_coord[i], labels = greek[i])
text(15, y_coord[i], labels = Greek_text[i], adj = c(0.1, 0.4), cex = 0.8)
}

r语言

公式:

xlab.name <- expression(paste(italic(vti), Delta, sep=""))
ylab.name <- expression(mu * "ml")
main.name <- expression(paste(plain(sin) * phi))
plot(0, 0, xlab=xlab.name, type ="n",  ylab=ylab.name, main=main.name, xlim=c(-pi, pi), ylim=c(-1.5, 1.5), axes=FALSE)
axis(1, at = c(-pi, -pi/2, 0, pi/2, pi), labels = expression(-pi, -pi/2, 0, pi/2, pi))
axis(2)
box()
text(-pi/2, 0, expression(hat(alpha) == (X^t * X)^{-1} * X^t * y))
text(pi/2, 0, expression(paste(frac(1, sigma*sqrt(2*pi)), plain(e)^{frac(-(x-mu)^2, 2*sigma^2)}, sep="")), cex = 1.2)

r语言

ylab.name <- expression(sigma[21])
main <- expression(paste(italic(Sch9), Delta, "(18s and 5.8s)"))
n <- 20
plot(0, 0, ylab = "",  xlab = "", type = "n", main = substitute(paste(n[i], " = ", k), list(k = n)))
i <- 2
range.name = substitute(paste(italic(Sch9), Delta, " ", p, "/", k, " hr"), list(k = i*12, p = (i+1)*12))
text(0, 0, range.name)

r语言

上下标:

plot(1,1, type = "n", ylab = "", xlab = "", main='Title')
text(1, 1.2, labels = expression('Title'^2), cex = 2, col = "darkgreen")
text(1, 0.8, labels = expression('Title'[2]), cex = 2, col = "red")

r语言

打开APP阅读更多精彩内容
声明:本文内容及配图由入驻作者撰写或者入驻合作网站授权转载。文章观点仅代表作者本人,不代表电子发烧友网立场。文章及其配图仅供工程师学习之用,如有内容侵权或者其他违规问题,请联系本站处理。 举报投诉

全部0条评论

快来发表一下你的评论吧 !

×
20
完善资料,
赚取积分