通常在我们写论文时,所需要的统计图是非常严谨的,里面的希腊字符与上下脚标都必须要严格书写。因此在使用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 获取。)

Syntax Meaning
x + y x plus y
x - y x minus y
x*y juxtapose x and y
x/y x forwardslash y
x %±% y x plus or minus y
x %/% y x divided by y
x %*% y x times y
x %.% y x cdot y
x[i] x subscript i
x^2 x superscript 2
paste(x, y, z) juxtapose x, y, and z
sqrt(x) square root of x
sqrt(x, y) yth root of x
x == y x equals y
x != y x is not equal to y
x < y x is less than y
x <= y x is less than or equal to y
x > y x is greater than y
x >= y x is greater than or equal to y
!x not x
x %~~% y x is approximately equal to y
x %=~% y x and y are congruent
x %==% y x is defined as y
x %prop% y x is proportional to y
x %~% y x is distributed as y
plain(x) draw x in normal font
bold(x) draw x in bold font
italic(x) draw x in italic font
bolditalic(x) draw x in bolditalic font
symbol(x) draw x in symbol font
list(x, y, z) comma-separated list
ellipsis (height varies)
cdots ellipsis (vertically centred)
ldots ellipsis (at baseline)
x %subset% y x is a proper subset of y
x %subseteq% y x is a subset of y
x %notsubset% y x is not a subset of y
x %supset% y x is a proper superset of y
x %supseteq% y x is a superset of y
x %in% y x is an element of y
x %notin% y x is not an element of y
hat(x) x with a circumflex
tilde(x) x with a tilde
dot(x) x with a dot
ring(x) x with a ring
bar(xy) xy with bar
widehat(xy) xy with a wide circumflex
widetilde(xy) xy with a wide tilde
x %<->% y x double-arrow y
x %->% y x right-arrow y
x %<-% y x left-arrow y
x %up% y x up-arrow y
x %down% y x down-arrow y
x %<=>% y x is equivalent to y
x %=>% y x implies y
x %<=% y y implies x
x %dblup% y x double-up-arrow y
x %dbldown% y x double-down-arrow y
alpha – omega Greek symbols
Alpha – Omega uppercase Greek symbols
theta1, phi1, sigma1, omega1 cursive Greek symbols
Upsilon1 capital upsilon with hook
aleph first letter of Hebrew alphabet
infinity infinity symbol
partialdiff partial differential symbol
nabla nabla, gradient symbol
32*degree 32 degrees
60*minute 60 minutes of angle
30*second 30 seconds of angle
displaystyle(x) draw x in normal size (extra spacing)
textstyle(x) draw x in normal size
scriptstyle(x) draw x in small size
scriptscriptstyle(x) draw x in very small size
underline(x) draw x underlined
x ~~ y put extra space between x and y
x + phantom(0) + y leave gap for “0”, but don’t draw it
x + over(1, phantom(0)) leave vertical gap for “0” (don’t draw)
frac(x, y) x over y
over(x, y) x over y
atop(x, y) x over y (no horizontal bar)
sum(x[i], i==1, n) sum x[i] for i equals 1 to n
prod(plain§(X==x), x) product of P(X=x) for all values of x
integral(f(x)*dx, a, b) definite integral of f(x) wrt x
union(A[i], i==1, n) union of A[i] for i equals 1 to n
intersect(A[i], i==1, n) intersection of A[i]
lim(f(x), x %->% 0) limit of f(x) as x tends to 0
min(g(x), x > 0) minimum of g(x) for x greater than 0
inf(S) infimum of S
sup(S) supremum of S
x^y + z normal operator precedence
x^(y + z) visible grouping of operands
x^{y + z} invisible grouping of operands
group("(",list(a, b),"]") specify left and right delimiters
bgroup("(",atop(x,y),")") use scalable delimiters
group(lceil, x, rceil) special delimiters
group(lfloor, x, rfloor) special delimiters

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

  1. java控制台输出脚标上标下标,c – 如何在CLI上打印下标/上标?

    由于大多数CLI实际上只是终端(大多数都很笨,但有时会带有颜色),我做过的唯一跨平台方式就是为每条虚拟线分配多条物理线路,例如: 2 f(x) = x + log x 2 它并不理想,但它可能是没有G ...

  2. R语言绘图patchwork拼图详解快速实现组合图拼接

    pdf教程下载 此文内容来自微信公众号:R语言搬运工,扫码关注公众号浏览更多精彩内容** 我们在实际科研绘图或者写报告的时候,往往会同时出多幅统计图,如何将他们拼在一起是即将或者正在面临的问题.R语言 ...

  3. 汇编语言编写程序实现: 该数是奇数时输出 N,是偶数时输出 Y。

    下面是汇编语言实现该功能的代码: section .data msg db 'N' ; 奇数时输出的字符 msg2 db 'Y' ; 偶数时输出的字符section .bss num resb 1 ; ...

  4. R统计绘图-corrplot热图绘制细节调整2(更改变量可视化顺序、非相关性热图绘制、添加矩形框等)

    上一篇文章推送的是怎样调整corrplot热图的可视化参数,以修改字符和图例位置,数据可视化形式和字符小大和颜色等这篇是一个补充部分,记录怎样修改参数以变量排序方式和突出部分数据.本流程还是使用R统计 ...

  5. R统计绘图-PCA详解1(princomp/principal/prcomp/rda等)

    此文为<精通机器学习:基于R>的学习笔记,书中第九章详细介绍了无监督学习-主成分分析(PCA)的分析过程和结果解读. PCA可以对相关变量进行归类,从而降低数据维度,提高对数据的理解.分析 ...

  6. R统计绘图-VPA(变差分解分析)

    变差分解分析(Variance Partitioning Analysis)可用于确定指定环境因子对微生物(原生生物/植物/动物等等)群落结构变化的解释比例.要计算指定环境因子与群落结构的相关性,就需 ...

  7. R统计绘图-corrplot绘制热图及颜色、字体等细节修改1

    有师妹想要更改热图的颜色和字体,想着之前相关性绘图等推文只是使用corrplot默认的颜色绘图,为了帮师妹解惑,今天就写一篇,怎么设置热图颜色和字体等细节到推文.其实看一遍R语言实战|入门3:图形初阶 ...

  8. R统计绘图-多元线性回归(最优子集法特征筛选及模型构建,leaps)

    此文为<精通机器学习:基于R>的学习笔记,书中第二章详细介绍了线性回归分析过程和结果解读. 回归分析的一般步骤: 1. 确定回归方程中的自变量与因变量. 2. 确定回归模型,建立回归方程. ...

  9. R统计绘图-多元线性回归(平均加权模型/最优子集筛选,MuMIn)

    此文介绍如何使用MuMIn包使用最优子集法进行多重线性回归的模型筛选以及模型平均.多重线性回归需要进行的数据检验过程都写在R统计绘图-多重线性回归(最优子集法特征筛选,leaps)中了.大家可以自行查 ...

最新文章

  1. C++ ——统一初始化
  2. python程序员在公司都是做什么的-在一家公司呆了 10 年的程序员,最后都怎么了?...
  3. class多项式(链表实现)
  4. 【Matlab 图像】边缘检测算法及效果演示
  5. 初二计算机辅导记录,(初中信息技术兴趣小组活动记录.doc
  6. node-inspector使用方法
  7. 把mac地址转换为标准mac地址
  8. 七牛云存储:通过SDK上传图片
  9. 腾讯技术直播间 | 走进小程序云开发
  10. 360浏览器一打开就是瑞星安全网址怎么办
  11. SpringBoot Scheduled Cron表达式范例记录
  12. WPF和Expression Blend开发实例:Adorner(装饰器)应用实例
  13. UIImagePickerController PAD /IPHONE 上注意事项
  14. 你见过哪些操蛋的代码?切勿模仿! 否则后果自负
  15. oracle rman异地备份,通过RMAN磁盘备份进行异地恢复
  16. 用计算机弹的数字,在计算器上弹两只老虎是用那几个数字
  17. [JavaME]手机玩点对点MSN传情动漫之补充说明
  18. 安卓和苹果上线流程:
  19. 散粒噪声是白噪声吗_散粒噪声
  20. 玩转python网络爬虫 黄永祥_玩转Python网络爬虫

热门文章

  1. 小白怎样入门程序开发
  2. 加载自己的键盘加速键
  3. 携职教育:注册人数下滑27%!一建证书还值得考吗?
  4. 北京大学计算机系张润楠,耀华吧:物理竞赛之”我爸是李刚“
  5. 反射避开field.setAccessible(true); field.set(t, lineArray[i]); 赋值
  6. Visual Studio 2017最新版正式发布!适用于任何开发人员、平台及APP
  7. 新版迅雷与360浏览器
  8. 首席数据官丨富士康CDO史喆:To B 产品切忌臃肿,数字化不分对错只求更好
  9. Rockchip开发系列 - 4.2.Uart问题汇总
  10. 已解决ImportError: DLL 1oad failed while importing, onnxruntime_pybind11_state: 参数错误。