R进行绘图时输出希腊字符、上标、下标及数学公式 您所在的位置:网站首页 加号上角标怎么打 R进行绘图时输出希腊字符、上标、下标及数学公式

R进行绘图时输出希腊字符、上标、下标及数学公式

2023-07-29 08:37| 来源: 网络整理| 查看: 265

通常在我们写论文时,所需要的统计图是非常严谨的,里面的希腊字符与上下脚标都必须要严格书写。因此在使用R绘图时,如何在我们目标图中使用希腊字符、上标、下标及一些数学公式呢?在本博客中我们会进行详细的说明。

后面我们都将以一个最简单的绘图为例,只是将其标题进行修改。

希腊字母

使用希腊字符、上标、下标及数学公式,都需要利用一个函数:expression(),具体使用方式如下:

plot(cars) title(main = expression(Sigma))

输出:

上下标

expression()中的下标为[],上标为^,空格为~,连接符为*。示例代码如下:

plot(cars) title(main = expression(Sigma[1]~'a'*'n'*'d'~Sigma^2))

输出:

paste

想达到上面的效果,我们其实可以使用paste()与expression()进行组合,不需要上述繁琐的过程,也能够达到我们上述一模一样的输出,并且方便快捷:

plot(cars) title(main = expression(paste(Sigma[1], ' and ', Sigma^2))) 一个复杂的例子

目标:

代码:

expression(paste((frac(1, m)+frac(1, n))^-1, ABCD[paste(m, ',', n)])) 进阶

在我们想批量产生大量含有不同变量值的标题时,如果遇到变量与公式的混合输出该如何操作,可参考博客:R 绘图中的公式如何与变量对象混合拼接

数学公式

最后的数学公式,只需要在expression()中进行相应的符号连接即可,具体要求可参考:Mathematical Annotation in R,鉴于其很不稳定,这里将里面的细节搬运过来。

(下表也可以直接在 R help 中搜索 plotmath 获取。)

SyntaxMeaningx + yx plus yx - yx minus yx*yjuxtapose x and yx/yx forwardslash yx %±% yx plus or minus yx %/% yx divided by yx %*% yx times yx %.% yx cdot yx[i]x subscript ix^2x superscript 2paste(x, y, z)juxtapose x, y, and zsqrt(x)square root of xsqrt(x, y)yth root of xx == yx equals yx != yx is not equal to yx < yx is less than yx yx is greater than yx >= yx is greater than or equal to y!xnot xx %~~% yx is approximately equal to yx %=~% yx and y are congruentx %==% yx is defined as yx %prop% yx is proportional to yx %~% yx is distributed as yplain(x)draw x in normal fontbold(x)draw x in bold fontitalic(x)draw x in italic fontbolditalic(x)draw x in bolditalic fontsymbol(x)draw x in symbol fontlist(x, y, z)comma-separated list…ellipsis (height varies)cdotsellipsis (vertically centred)ldotsellipsis (at baseline)x %subset% yx is a proper subset of yx %subseteq% yx is a subset of yx %notsubset% yx is not a subset of yx %supset% yx is a proper superset of yx %supseteq% yx is a superset of yx %in% yx is an element of yx %notin% yx is not an element of yhat(x)x with a circumflextilde(x)x with a tildedot(x)x with a dotring(x)x with a ringbar(xy)xy with barwidehat(xy)xy with a wide circumflexwidetilde(xy)xy with a wide tildex %% yx double-arrow yx %->% yx right-arrow yx %% yx implies yx %% 0)limit of f(x) as x tends to 0min(g(x), x > 0)minimum of g(x) for x greater than 0inf(S)infimum of Ssup(S)supremum of Sx^y + znormal operator precedencex^(y + z)visible grouping of operandsx^{y + z}invisible grouping of operandsgroup("(",list(a, b),"]")specify left and right delimitersbgroup("(",atop(x,y),")")use scalable delimitersgroup(lceil, x, rceil)special delimitersgroup(lfloor, x, rfloor)special delimiters


【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有