R语言正则表达式

R语言正则表达式,第1张

首先你要知道正则表达式怎么写,如果你的a变量第一个字符是字母那你就写gsub(“^\w”,“”,text);如果你的a变量第一个字符是数字那就写gsub(“^\d”,“”,text);如果第一个字符即可能是数字也可能是字母那就写gsub(“^[0-9a-zA-Z]”,“”,text)。如果第一个字符是中文,你去搜一下中文的正则表达式,再替换之即可。

R语言绘图系列:

⚠️在不确定将图例添加在什么位置时,可使用 locator函数

locator()函数可以定位图上的点。运行locator函数之后在图上随便点一个点,点击finish就会返回刚刚那个点的位置坐标。

使用text函数在每个条图下面添加标签

设置气泡透明度

⚠️调色板函数中有个参数叫alpha,也可以设置气泡的透明度。(在ggplot2中很容易实现)

关于layout函数:

可以使用数据标号“text()”函数text()函数跟在画图函数语句后面,即先画出图,再标号。

下面为来自R的text()函数使用方法(疑难词汇已经标出)

Description

text draws the strings given in the vector(矢量) labels at the coordinates(坐标) given by x and y y may be missing since xycoords(x, y) is used for construction of the coordinates

Usage

text(x, )

## Default S3 method:

text(x, y = NULL, labels = seq_along(x$x), adj = NULL,pos = NULL, offset = 05, vfont = NULL,cex = 1, col = NULL, font = NULL, )

Arguments

x, y

numeric(数) vectors(矢量) of coordinates(坐标) where the text labels should be written If the length of x and y differs, the shorter one is recycled

labels

a character vector or expression specifying the text to be written An attempt is made to coerce(强制) other language objects (names and calls) to expressions, and vectors and other classed objects to character vectors byascharacter If labels is longer than x and y, the coordinates(坐标) are recycled to the length of labels

adj

one or two values in [0, 1] which specify(指定) the x (and optionally(可选择的) y) adjustment(调整) of the labels(标签) On most devices(装置) values outside that interval will also work

pos

a position specifier for the text If specified this overrides(代理佣金) any adj value given Values of 1, 2, 3 and 4, respectively(分别地) indicate(表明) positions below, to the left of, above and to the right of the specified coordinates

offset

when pos is specified(指定), this value gives the offset(抵消) of the label(标签) from the specified coordinate(坐标) in fractions(分数) of a character width

vfont

NULL for the current font family, or a character vector(矢量) of length 2 for Hershey vector fonts The first element(元素) of the vector selects a typeface and the second element selects a style Ignored(驳回诉讼) if labels is an expression

cex

numeric character expansion factor(因素); multiplied by par("cex") yields(产量) the final character size NULL and NA are equivalent to 10

col, font

the color and (if vfont = NULL) font to be used, possibly vectors(矢量) These default to the values of the global graphical parameters in par()

further graphical parameters (from par), such as srt, family and xpd

Details

labels must be of type character or expression (or be coercible(可强迫的) to such a type) In the latter case, quite a bit of mathematical(数学的) notation(符号) is available such as sub- and superscripts(上标), greek letters,fractions(分数), etc

adj allows adjustment of the text with respect to (x, y) Values of 0, 05, and 1 specify(指定) left/bottom, middle and right/top alignment(队列), respectively(分别地) The default is for centered text, ie, adj = c(05, NA)Accurate(精确的) vertical(垂直的) centering needs character metric(度量标准) information on individual(个人的) characters which is only available on some devices(装置) Vertical alignment is done slightly differently for character strings and for expressions: adj = c(0,0) means to left-justify and to align(结盟) on the baseline for strings but on the bottom of the bounding box for expressions This also affects vertical(垂直的) centering: for strings the centeringexcludes(排除) any descenders(下降) whereas(然而) for expressions it includes them Using NA for strings centers them, including descenders

The pos and offset arguments can be used in conjunction(结合) with values returned by identify to recreate(再创造) an interactively(交互式地) labelled(贴上标签的) plot(情节)

Text can be rotated(旋转的) by using graphical parameters srt (see par); this rotates about the centre set by adj

Graphical parameters col, cex and font can be vectors(矢量) and will then be applied cyclically(周期的) to the labels (and extra values will be ignored(驳回诉讼)) NA values of font are replaced by par("font"), and similarly for col

Labels whose x, y or labels value is NA are omitted(省略) from the plot(情节)

What happens when font = 5 (the symbol(象征) font) is selected can be both device- and locale-dependent Most often labels will be interpreted(说明) in the Adobe symbol encoding, so eg "d" is delta, and "\300" is aleph

Euro symbol

The Euro symbol may not be available in older fonts In current versions of Adobe symbol fonts it is character 160, so text(x, y, "\xA0", font = 5) may work People using Western European locales(场所) on Unix-alikes can probably select ISO-8895-15 (Latin-9) which has the Euro as character 165: this can also be used for postscript and pdf It is \u20ac in Unicode, which can be used in UTF-8 locales(场所)

In all the European Windows encodings the Euro is symbol(象征) 128 and \u20ac will work in all locales: however not all fonts will include it It is not in the symbol font used for windows and related devices(装置), including the Windows printer

References

Becker, R A, Chambers, J M and Wilks, A R (1988) The New S Language Wadsworth & Brooks/Cole

Murrell, P (2005) R Graphics Chapman(叫卖小贩) & Hall/CRC Press

See Also

textformula for the formula(公式) method; mtext, title, Hershey for details on Hershey vector(矢量) fonts, plotmath for details and more examples on mathematical(数学的) annotation(注释)

Examples

plot(-1:1, -1:1, type = "n", xlab = "Re", ylab = "Im")

K <- 16; text(exp(1i 2 pi (1:K) / K), col = 2)

## The following two examples use latin1 characters: these may not

## appear correctly (or be omitted entirely)

plot(1:10, 1:10, main = "text() examples\n~~~~~~~~~~~~~~",

sub = "R is GNU ©, but not ® ")

mtext("«Latin-1 accented chars»: éè øØ å<Å æ<Æ", side = 3)

points(c(6,2), c(2,1), pch = 3, cex = 4, col = "red")

text(6, 2, "the text is CENTERED around (x,y) = (6,2) by default",

cex = 8)

text(2, 1, "or Left/Bottom - JUSTIFIED at (2,1) by 'adj = c(0,0)'",

adj = c(0,0))

text(4, 9, expression(hat(beta) == (X^t X)^{-1} X^t y))

text(4, 84, "expression(hat(beta) == (X^t X)^{-1} X^t y)",

cex = 75)

text(4, 7, expression(bar(x) == sum(frac(x[i], n), i==1, n)))

## Two more latin1 examples

text(5, 102,

"Le français, c'est façile: Règles, Liberté, Egalité, Fraternité")

text(5, 98,

"Jetz no chli züritüütsch: (noch ein bißchen Zürcher deutsch)")

如果两向量为a,b

a <- c(1:5) #长度5

b <- c(1:7) #长度7

# 写入到文本texttxt

writetable(t(a), file = "testtxt", append = T, colnames = F, rownames = F)

writetable(t(b), file = "testtxt", append = T, colnames = F, rownames = F)

# t() 函数将向量转置 以便以行的形式写入

# append 是继续在文件末尾写入而非擦写

# colnames 和rownames 设定为行和列的标签为空。

以上就是关于R语言正则表达式全部的内容,包括:R语言正则表达式、R语言可视化及作图2--低级绘图函数、r语言 箱线图怎么让数据点显示等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/zz/9800048.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-05-02
下一篇2023-05-02

发表评论

登录后才能评论

评论列表(0条)

    保存