R语言低级绘图函数-text
text函数用来在一张图表上添加文字,只需要指定对应的x和y坐标,以及需要添加的文字内容就可以了
基本用法:
plot(1:5, 1:5, xlim = c(0,6), ylim = c (0,6), type = "n")
text(x = 3, y = 3, labels = "text")
效果图如下:

支持同时创建多个text标签
代码示例:
plot(1:5, 1:5, xlim = c(0,6), ylim = c (0,6), type = "n")
text(x = c(3, 3), y = c(3, 5), labels = c("text", "text"))
效果图如下:

参数调整:
col : 设置文字的颜色
代码示例:
plot(1:5, 1:5, xlim = c(0,6), ylim = c (0,6), type = "n")
text(x = c(3, 3), y = c(3, 5), labels = c("text", "text"), col = c("red", "blue"))
效果图如下:

cex : 设置文字的大小
代码示例:
plot(1:5, 1:5, xlim = c(0,6), ylim = c (0,6), type = "n")
text(x = c(3, 3), y = c(3, 5), labels = c("text", "text"), cex = c( 0.5 , 2 ))
效果图如下:

sort : 对文件进行旋转
代码示例:
plot(1:5, 1:5, xlim = c(0,6), ylim = c (0,6), type = "n")
text(x = 3, y = 3, labels = "text", srt = 45)
效果图如下:

adj : 调整文字的位置,一个值时调整的是x轴的位置,如果为两个值时,第一个调整的是x轴的位置,第二个调整的是y轴的位置,可选范围为[0, 1]
对x轴进行调整,代码示例:
par(mfrow = c(1,3))
plot(1:5, 1:5, xlim = c(0,6), ylim = c (0,6), type = "n", main = "adj = 0")
abline(h = 3, v = 3 , col = "gray", lty = 3)
text(x = 3, y = 3, labels = "text", adj = 0)
plot(1:5, 1:5, xlim = c(0,6), ylim = c (0,6), type = "n", main = "adj = 0.5")
abline(h = 3, v = 3 , col = "gray", lty = 3)
text(x = 3, y = 3, labels = "text", adj = 0.5)
plot(1:5, 1:5, xlim = c(0,6), ylim = c (0,6), type = "n", main = "adj = 1")
abline(h = 3, v = 3 , col = "gray", lty = 3)
text(x = 3, y = 3, labels = "text", adj = 1)
x轴调整的效果图如下:

对y轴进行调整,代码示例:
par(mfrow = c(1,3))
plot(1:5, 1:5, xlim = c(0,6), ylim = c (0,6), type = "n", main = "adj = 0")
abline(h = 3, v = 3 , col = "gray", lty = 3)
text(x = 3, y = 3, labels = "text", adj = c(0.5, 0))
plot(1:5, 1:5, xlim = c(0,6), ylim = c (0,6), type = "n", main = "adj = 0.5")
abline(h = 3, v = 3 , col = "gray", lty = 3)
text(x = 3, y = 3, labels = "text", adj = c(0.5, 0.5))
plot(1:5, 1:5, xlim = c(0,6), ylim = c (0,6), type = "n", main = "adj = 1")
abline(h = 3, v = 3 , col = "gray", lty = 3)
text(x = 3, y = 3, labels = "text", adj = c(0.5, 1))
y轴调整的效果图如下:

pos: 也是对文字的位置进行调整,不能和adj参数同时使用, 可选值为1, 2, 3, 4, 分别对应下, 上, 左, 右4个方向
代码示例:
par(mfrow = c(1, 4))
plot(1:5, 1:5, xlim = c(0,6), ylim = c (0,6), type = "n", main = "pos = 1")
abline(h = 3, v = 3 , col = "gray", lty = 3)
text(x = 3, y = 3, labels = "text", pos = 1)
plot(1:5, 1:5, xlim = c(0,6), ylim = c (0,6), type = "n", main = "pos = 2")
abline(h = 3, v = 3 , col = "gray", lty = 3)
text(x = 3, y = 3, labels = "text", pos = 2)
plot(1:5, 1:5, xlim = c(0,6), ylim = c (0,6), type = "n", main = "pos = 3")
abline(h = 3, v = 3 , col = "gray", lty = 3)
text(x = 3, y = 3, labels = "text", pos = 3)
plot(1:5, 1:5, xlim = c(0,6), ylim = c (0,6), type = "n", main = "adj = 4")
abline(h = 3, v = 3 , col = "gray", lty = 3)
text(x = 3, y = 3, labels = "text", pos = 4)
效果图如下:

offset : 只有和和pos 函数搭配起来才会产生作用,对文字的文字进行调整
代码示例:
plot(1:5, 1:5, xlim = c(0,6), ylim = c (0,6), type = "n", main = "pos = 1")
abline(h = 3, v = 3 , col = "gray", lty = 3)
text(x = 3, y = 3, labels = "text", pos = 1, offset = 1, col = "red")
text(x = 3, y = 3, labels = "text", pos = 1, offset = -1, col = "blue")
效果图如下:

font: 设置文字的格式,1是默认值,就是普通的文字,2代表加粗,3代表斜体, 4代表加粗+斜体, 5只有用来ADOBE的设备上时,才有用
代码示例:
par(mfrow = c(1, 5))
plot(1:5, 1:5, xlim = c(0,6), ylim = c (0,6), type = "n", main = "font = 1")
abline(h = 3, v = 3 , col = "gray", lty = 3)
text(x = 3, y = 3, labels = "text", font = 1)
plot(1:5, 1:5, xlim = c(0,6), ylim = c (0,6), type = "n", main = "font = 2")
abline(h = 3, v = 3 , col = "gray", lty = 3)
text(x = 3, y = 3, labels = "text", font = 2)
plot(1:5, 1:5, xlim = c(0,6), ylim = c (0,6), type = "n", main = "font = 3")
abline(h = 3, v = 3 , col = "gray", lty = 3)
text(x = 3, y = 3, labels = "text", font = 3)
plot(1:5, 1:5, xlim = c(0,6), ylim = c (0,6), type = "n", main = "font = 4")
abline(h = 3, v = 3 , col = "gray", lty = 3)
text(x = 3, y = 3, labels = "text", font = 4)
plot(1:5, 1:5, xlim = c(0,6), ylim = c (0,6), type = "n", main = "font = 5")
abline(h = 3, v = 3 , col = "gray", lty = 3)
text(x = 3, y = 3, labels = "text", font = 5)
效果图如下:

text函数的常见用法和参数就参考上面的例子就够了,当我们想打印数学表达式或者一些特殊符号在图片上是,就需要对lables 参数进行特别设置
对于数据表达式,使用expression 函数将其转化成表达式后,在显示出来会更好
打印一个开平方的表达式,代码示例:
plot(1:5, 1:5, xlim = c(0,6), ylim = c (0,6), type = "n")
text(x = 3, y = 3, labels = expression(sqrt(x)))
效果图如下:

对于表达式的打印,具体的可以参考 plotmath 函数的帮助文档
R语言低级绘图函数-text的更多相关文章
- R语言低级绘图函数-symbols
严格意义上将symbols 并不能算是一个低级的绘图函数,因为它不仅可以在一幅已经存在的图标上添加元素,还可以创建一张新的图表 鉴于它绘图时的灵活性,我把它归入到低级绘图函数中 symbols 可以创 ...
- R语言低级绘图函数-axis
axis函数用来在一张图表上添加轴线,区别于传统的x轴和y轴,axis 允许在上,下,左, 右4个方向添加轴线 以x轴为例,一条轴线包含3个元素,水平的一条横线,叫做axis line , 刻度线, ...
- R语言低级绘图函数-abline 转载
abline 函数的作用是在一张图表上添加直线, 可以是一条斜线,通过x或y轴的交点和斜率来确定位置:也可以是一条水平或者垂直的线,只需要指定与x轴或y轴交点的位置就可以了 常见用法: 1)添加直线 ...
- R语言低级绘图函数-grid
grid 函数用来在一张图表上添加网格线, 基本用法:默认在添加刻度线的地方添加网格线 plot(1:5, 1:5, xlim = c(0,6), ylim = c (0,6), type = &qu ...
- R语言低级绘图函数-title
title 函数用来在一张图表上添加标题 基本用法: main 表示主标题,通常位于图像的上方, sub 表示副标题,位于图像的下方, xlab 表示x轴的标签,ylab 表示y轴的标签 par(om ...
- R语言低级绘图函数-points
points 用来在一张图表上添加点,指定好对应的x和y坐标,就可以添加不同形状,颜色的点了: 基本用法: 通过x和y设置点的坐标 plot(1:5, 1:5, xlim = c(0,6), ylim ...
- R语言低级绘图函数-rect
rect 函数用来在一张图上添加矩形,只需要指定左下角和右上角的坐标的位置,就可以画出一个矩形 基本用法: plot(1:5, 1:5, xlim = c(0,6), ylim = c (0,6), ...
- R语言低级绘图函数-arrows
arrows 函数用来在一张图表上添加箭头,只需要分别指定起始坐标和终止坐标,就可以添加箭头了,还可以通过一些属性对箭头的形状,大小进行调整 基本用法: xo, yo 指定起始点的x和y坐标,x1, ...
- R语言低级绘图函数-abline
abline 函数的作用是在一张图表上添加直线, 可以是一条斜线,通过x或y轴的交点和斜率来确定位置:也可以是一条水平或者垂直的线,只需要指定与x轴或y轴交点的位置就可以了 常见用法: 1)添加直线 ...
随机推荐
- linux怎么查看一个文件夹的大小
linux查看一个文件夹的大小的命令为: -lh 该文件夹的完整路径 例,查询/var文件夹的大小: -lh /var du 递归查询该路径下所有文件的大小(若不加任何参数,则显示文件夹内的所有文件, ...
- python中if __name__ == '__main__'的说明
这个表示执行的是此代码所在的文件. 如果这个文件是作为模块被其他文件调用,不会执行这里面的代码. 只有执行这个文件时, if 里面的语句才会被执行. 这个功能经常可以用于进行测试. python中,当 ...
- Linux下的tree命令 --Linux下文件夹树查看
Linux下的tree命令 --Linux下文件夹树查看 有时我们须要生成文件夹树结构,能够使用的有ls -R,可是实际效果并不好 这时须要用到tree命令,可是大部分Linux系统是默认不安装该命令 ...
- vim设置文本宽度
'textwidth' 'tw' number (default 0) local to buffer ...
- cocos2d-x -- removeChild
Test5::Test5() { CCSprite* sp1 = CCSprite::create(s_pPathSister1); CCSprite* sp2 = CCSprite::create( ...
- angular学习笔记(二十)-表单验证
本篇主要介绍angular中的表单验证: 表单验证主要有以下一些内容: 1. required指令: 相当于html5的required属性,验证不能为空 2. ng-maxlength属性: 验证内 ...
- python 开发在线音乐播放器-简易版
在线音乐播放器,使用python的Tkinter库做了一个界面,感觉这个库使用起来还是挺方便的,音乐的数据来自网易云音乐的一个接口,通过urllib.urlopen模块打开网址,使用Json模块进行数 ...
- Oracle PLSQL Demo - 03.流程判断[IF ELEIF ELSE]
declare v_job ) := 'Programmer'; v_sal number; begin if v_job = 'Programmer' then v_sal :; elsif v_j ...
- gulp入门与一些基本设置
这里是gulp入门的一些操作,实现了编译sass文件.压缩.合并.添加版本号等基本功能. 友情提示,如果npm出现无法下载可以安装 cnpm.在安装完Nodejs 后 npm install cnpm ...
- mysql 5.7.15 安装配置方法图文教程(转)
http://www.jb51.net/article/92521.htm ******************************* MySQL数据库作为关系型数据库中的佼佼者,因其体积小,速度 ...