r语言 箱线图怎么让数据点显示

Python017

r语言 箱线图怎么让数据点显示,第1张

可以使用数据标号“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 xy.coords(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 = 0.5, 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 byas.character. 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 1.0.

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, 0.5, and 1 specify(指定) left/bottom, middle and right/top alignment(队列), respectively(分别地). The default is for centered text, i.e., adj = c(0.5, 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 e.g. "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

text.formula for the formula(公式) methodmtext, 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 <- 16text(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, 8.4, "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, 10.2,

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

text(5, 9.8,

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

        /r/与现在相比,可能不仅仅是颤音;在那些现在是元音或以前是辅音和颤音,但现在已经消失的发音下它是一个颤音点的辅音。对应古英语中的r或hr和古法语中的r,拼写成r(rr)。发/r/音的单词例子如下:ride,ring,bring,priest,spread,drive,tree,stream,green,creep,scream,wring,friend,three,shrive,errand,sorrow,bury,sharp,lord,short,lark,sterve现在的starve,dwerf现在的dwarf,arm,horn, horse,burst,for,four,hammer,timber,river,branch,pray,dragon,treason,strife,grace,cry,fruit,very,fury,warrior,country,destroy,secret,marble,harp,art,clerk,service,arm,turn,merchant,pearl,purse,war,poor,chamber。

        古英语hr(==清辅音r或者带有滑音 ε )在早期的中古英语中成了/r/:古英语hring,hrycg,hræfn,hrōf分别演变成了ring,ridge,raven,roof。

在以下单词中,/r/早在10世纪就已经消失了:古英语specan,spǣc来自于sprecan,sprǣc。

        r的音位转换(Metathesis)在古英语中非常普遍;对应于西撒克逊(West Saxon)形式þridda,þrittig,brid,wyrhta,worhte,我们发现,在很早期的时候,盎格鲁(Anglian)方言的这种形式已经成了现在的标准形式third,thirty,bird,wright,wrought。也可对比nostril古英语nosþyrl,nosterle。

         在t和d之后,古英语通常用r替换掉 l ,英语里像这样的例子:charter派生于拉丁语cartula,chapter(法语chapitre)演变成了capitulu(m),slander(古法语sclandre)派生于scandalum。

        从古法语的coronel我们有英语里的coronel,现已是废弃的拼法,通过它来解释现代的发音[‘kənəl];从17世纪中期开始,拼法colonel,其与后期法语的拼法一致,已经用r来拼挤掉了这种拼法。

/r/已被加入到单词philosopher(词中,可能是代理名词(Agent noun,拉丁语nomen agentis)的词尾-er,正如scrivener,中古英语为scriveyn一样);还有单词provender(派生于provende,lavender派生于古法语lavende?似乎又不是来自于lavendula,对比德语和苏格兰语lavendel;也可对比charter(派生于古法语chartre,又派生于拉丁语cartula))。

        古法语在下列单词中有上颚音或上颚音化的r:glorie,之后为gloire;同样,英语有-ry(中古英语-rie):glory,story,memory(carry好像也算),adversary,Gregory。

        上面句中提到一个名词“代理名词”,或叫”施动者名词“,英文agent noun,拉丁文又叫nomen

agentis,看看它是如何定义的:

在语言学中,代理名词agent noun(拉丁语为nomen agentis),一个单词由另一个表示动作的单词派生,用于表示一个实体发出了这个动作。例如,driver是由动词drive派生。通常,这种派生有着严格的与之相关联的词态( morphology )意义,这种派生使用一个输入的语义(lexeme,词态分析学中的一个抽像的单位)产生另一个语义。尽管如此,将这种词素的分类归入派生词素(参见单词格式)和词态变化类,一般来讲,不是一个明确的理论问题,在面对分类的常用理论规范和一些语言常用的事实分类时(例如,代理名词构成词素法),不同的作者有不同的选择。举例,英语中动词用于构成代理名词的常用后缀:"-er", "-or","-ist"。