×

r语言fontfamily

r语言fontfamily(目前最全的R语言-图片的组合与拼接)

admin admin 发表于2024-04-16 20:19:34 浏览21 评论0

抢沙发发表评论

这篇文章给大家聊聊关于r语言fontfamily,以及目前最全的R语言-图片的组合与拼接对应的知识点,希望对各位有所帮助,不要忘了收藏本站哦。

本文目录

目前最全的R语言-图片的组合与拼接

***隐藏网址******隐藏网址***

customLayout用于拼图特别方便,尤其是仪表盘布局 支持R内置的base绘图对象,ggplot2对象(与grid结合 )

Hide

”library(ggplot2)library(customLayout)

通过设置简单的数字矩阵以及对应的宽高比,可以非常方便的设置出来数字拼图 关键函数:

mat数字矩阵必须从1开始,且必须连续

其它拼图包没有的功能,非常好用 跟合并矩阵类似。分为行合并和列合并

这个功能也是其它包没有的,非常有用 关键函数:

参数lay表示大画布,参数newlay表示要嵌套进去的小画布,field表示指定要嵌套的区域编号

关键函数:

cowplot是一个ggplot2包的简单补充,意味着其可以为ggplot2提供出版物级的主题等。 更重要的是,这个包可以组合多个”ggplot2”绘制的图为一个图,并且为每个图加上例如A,B,C等标签, 这在具体的出版物上通常是要求的。 语法结构与ggplot类似,将ggplot2图作为一个对象置于 ggdraw() 中 表达式:

draw_plot(plot, x = 0, y = 0, width = 1, height = 1, scale = 1) draw_text(text, x = 0.5, y = 0.5, size = 14, hjust = 0.5, vjust = 0.5,...) draw_plot_label(label, x = 0, y = 1, hjust = -0.5, vjust = 1.5, size = 16, fontface = "bold", family = NULL, colour = NULL, ...)

参数解释:

grid中文翻译为网格,可将其解释为画布分割,通过设定相应的参数,从而可以任意的摆放图形 常用函数:

语法:

参数解释:

layout参数

综合例子

子母图,主要是形成局部放大的效果,既可以从整体上对比,又兼顾特别小的数据组,或特别密的数据点可以查看,而没有必要单独做2张图

《pre style="box-sizing: border-box; font-family: Monaco, Menlo, Consolas, "Courier New", monospace; font-size: 13px; white-space: pre-wrap; display: block; padding: 9.5px; margin: 0px 0px 10px; line-height: 1.42857; color: rgb(51, 51, 51); word-break: break-all; overflow-wrap: break-word !important; background-color: white; border: 1px solid rgb(204, 204, 204); border-radius: 4px; max-width: 100%; font-variant-numeric: normal; font-variant-east-asian: normal; letter-spacing: 0.544px; text-align: justify; widows: 1; overflow: auto;"》## png

蝴蝶图

主要函数:

语法:

参数解释:

把绘图对象添加到列表总,并把该列表传递给 grid.arrange() 函数中的grobs参数

子母图 grid包可以画字母图 安装gridExtra包后,ggplot2中多了一个 ggplotGrob( )函数,可以创建grob对象参数

R语言可视化常用代码

(供自己记录) adj位置调整 ask询问 bg背景 bty图形边框风格,o四边都有边框,l左边和下边,7右边和上边,c上边、左边和下边, cex设置点和字符的大小,axis坐标轴上标签字的大小,lab坐标轴上命名的大小,main标题的大小,sub副标题的大小,col颜色。 family字体的风格, fg前景颜色 font图片字体的风格,字体,粗体,斜体 las坐标轴的运行关系,坐标轴上的字和坐标轴的关系,字会转 lend线的两端的样式 lty线的形式,直线、虚线 lwd线的粗细 Mai、mar、mex画布的大小 Mfcol、mfrow是来切分画布的,放几个fig在画布中,两个功能一样 pch是用来定义点的形状的,有25个形状 srt用来定义图中的文字的角度 Txk坐标轴上的刻度的大小,刻度的字体大小 Xaxt/yaxt不想要坐标轴的标签 Xlog/ylog是x轴和y轴设置为log值 Xpd把绘图区设置为整个画布 Fig表示图形的四个角的位置 New是在图中生成图

r语言 画图怎样设计 main title的字体大小

全局修改a《-c(1:10)#全局修改old_par《-par(no.readonly=TRUE) #记录默认样式到变量old_par中par(lty=2,pch=17) #设置线型lty=2虚线,pch=17实心三角形,键值对的方式进行设置#第一幅图,已经和默认样式不一样了b《-rnorm(10)plot(a,b,type=’b’)#第二幅图,和第一幅图样式一样b《-rnorm(10)plot(a,b,type=’b’)par(old_par) #应用默认样式#第三幅图,默认样式b《-rnorm(10)plot(a,b,type=’b’)针对一幅图片有效a《-c(1:10)b《-rnorm(10)plot(a,b,type=’b’,lty=2,pch=17)如下列表为可以设置的键值对参数 作用 描述 列表 pch 点的符号 指定绘制点时使用的符号 cex 符号的大小 指定符号的大小。cex是一个数值,表示绘图符号相对于默认大小的缩放倍数。默认大小为1,1.5表示放大为默认值的1.5倍,0.5表示缩小为默认值的50%,等等 lty 线条类型 lwd 线条宽度 指定线条宽度。lwd是以默认值的相对大小来表示的(默认值为1)。例如,lwd=2将生成一条两倍于默认宽度的线条 col 默认的绘图颜色。某些函数(如lines和pie)可以接受一个含有颜色值的向量并自动循环使用。例如,如果设定col=c(red, blue)并需要绘制三条线,则第一条线将为红色,第二条线为蓝色,第三条线又将为红色 col.axis 坐标轴刻度文字的颜色 col.lab 坐标轴标签(名称)的颜色 col.main 标题颜色 col.sub 副标题颜色 fg 图形的前景色 bg 图形的背景色 cex 表示相对于默认大小缩放倍数的数值。默认大小为1,1.5表示放大为默认值的1.5倍,0.5表示缩小为默认值的50%,等等 cex.axis 坐标轴刻度文字的缩放倍数。类似于cex cex.lab 坐标轴标签(名称)的缩放倍数。类似于cex cex.main 标题的缩放倍数。类似于cex cex.sub 副标题的缩放倍数。类似于cex font 整数。用于指定绘图使用的字体样式。1=常规,2=粗体,3=斜体,4=粗斜体,5=符号字体(以Adobe符号编码表示) font.axis 坐标轴刻度文字的字体样式 font.lab 坐标轴标签(名称)的字体样式 font.main 标题的字体样式 font.sub 副标题的字体样式 ps 字体磅值(1磅约为1/72英寸)。文本的最终大小为 ps*cex family 绘制文本时使用的字体族。标准的取值为serif(衬线)、sans(无衬线)和mono(等宽) pin 以英寸表示的图形尺寸(宽和高) mai 以数值向量表示的边界大小,顺序为“下、左、上、右”,单位为英寸 mar 以数值向量表示的边界大小,顺序为“下、左、上、右”,单位为英分*。默认值为c(5, 4, 4, 2) + 0.1 标题title坐标轴axis参考线abline图例legend文本标注text(绘图区域内部添加文字),mtext(图形四个边界添加文字)

完美解决R完中文无法显示或R语言中文乱码

由于R语言画图时对中文的支持,经常出现乱码,作图很难显示中文,尤其是ggplot2对中文支持不是特别友好,ggplot默认字体不支持显示中文,给许多使用的人带来不便,希望yihui大神能在Rstudio推动一下。 可以有一些变通的处理方法: 安装showtext包 install.packages("extrafont") library(extrafont) font_import() ggplot 用Cairo包进行保存为png、pdf等格式 使用因子数据变相替换。 举个例子

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

可以使用数据标号“text()”函数text()函数跟在画图函数语句后面,即先画出图,再标号。下面为来自R的text()函数使用方法(疑难词汇已经标出)Descriptiontext 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.Usagetext(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, ...)Argumentsx, 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 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.Detailslabels 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 symbolThe 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.ReferencesBecker, 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 Alsotext.formula for the formula(公式) method; mtext, title, Hershey for details on Hershey vector(矢量) fonts, plotmath for details and more examples on mathematical(数学的) annotation(注释).Examplesplot(-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, 8.4, "expression(hat(beta) == (X^t * X)^{-1} * X^t * y)", cex = .75)text(4, 7, expression(bar(x) == sum(frac(x, n), i==1, n)))## Two more latin1 examplestext(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语言中family=“ mono“是什么意思

绘制文本时使用的字体族。标准的取值为serif(衬线)、sans(无衬线)和mono(等宽)

《R语言实战》自学笔记16-图形图例

数据准备

函数:legend(location, title, legend, ....)

参数详解:

x和y:用于定位图例,也可用关键词"bottomright", "bottom", "bottomleft", "left", "topleft", "top", "topright", "right" 和 "center";当图例用关键词设置位置后,inset = 分数,可以设置其相对位置; legend:指定图例标签,字符或表达式向量; fill:用特定的颜色进行填充; col:设置图例中出现的点或线的颜色; border:当fill = 参数存在的情况下,用于指定填充的边框颜色; lty, lwd:图例中线的类型与宽度; pch:点的类型; angle:阴影的角度; density:阴影线的密度; cex:指定图例显示大小; bg:指定图例的背景色; bty:指定图例框是否画出,默认o为画出,n为不画出; box.lty, box.lwd, box.col: 设置图例边框线型,线粗,颜色,box.lty为虚线,box.lwd决定粗线,box.col决定颜色; pt.bg:图例中点的背景色; pt.cex:图例中点的大小; pt.lwd:图例中点边缘的线宽; x.intersp:图例中文字离图片的水平距离; y.intersp:图例中文字离图片的垂直距离; adj:图例中字体的相对位置; text.width:图例中字体所占的宽度,调整后图例整个宽度也跟着变化了; text.col:图例字体的颜色; text.font:图例字体; merge:逻辑值,merge=TRUE,合并点与线,但不填充图例框,默认为TRUE; trace:逻辑值,trace=TRUE显示图例信息; plot:逻辑值,plot=FALSE不画出图例; ncol:图例中分类的列数; horiz:逻辑值,horiz=TRUE,水平放置图例; title:给图例加标题; xpd:xpd=FALSE,即不允许在作图区域外作图,改为TRUE即可,与par()参数配合使用; title.col:标题颜色; title.adj:图例标题的相对位置,0.5为默认,在中间。0最左,1为最右; seg.len:指定图例中线的线长,长度单位为字符宽度。

1 图例方位

2 修饰图例

3 图例绘制在图外

4 自定义图例 有时候绘制出的图是分组图,这时候需要自定义绘制图例。

参考资料: 《R语言实战》(中文版),人民邮电出版社,2013.***隐藏网址******隐藏网址******隐藏网址***

R语言中的mtext的所有参数及解释

在当前图形区域的四个边缘之一,显示文本。mtext(text, side = 3, line = 0, outer = FALSE, at = NA, adj = NA, padj = NA, cex = NA, col = NA, font = NA, ...)text是文本内容。side指定是哪个页边空白(1=下面,2=左边,3=上边,4=右边)。line指定文字出现的位置,文字和对应坐标轴平行。从坐标轴开始向外从0开始计数。具体设为多少合适需要自己尝试。at,以用户坐标指定字符串位置。adj 调整阅读方向。为使字符串平行坐标轴,adj=0,意味着左对齐或下对齐,而adj=1表示右对齐或上对齐。padj 调整每个字符串垂直阅读的方向(它通过adj控制)。对于平行轴的字符串, padj=0表示右或上对齐,padj=1表示左或下对齐。cex字体大小因子,默认为1,实际输出字体相对于默认字体的大小比例,得尝试才知道设为多少合适。font文字字体。 col是色彩。

r语言plot字体大小设置

1、打开r语言,利用windowsFonts加入到字体库中。2、在调用plot字体大小时,用family=myFont的参数实现即可。

R语言绘图时,如何指定背景参数为蓝色

原贴转自生物统计家园,原贴只贴出了代码,没有画图,这里运行了一下代码,复习了一下R的绘图,共有20多个。

案例01-基本绘图

cars 《- c(1, 3, 6, 4, 9)

plot(cars)

案例 1-基本绘图

案例02-增添标题

cars 《- c(1, 3, 6, 4, 9)

plot(cars, type="o", col="blue") # 绘制蓝色折线图,

title(main="Autos", col.main="red", font.main=4) # 增添标题,红色,粗斜体

案例 2-增添标题

注1:其中type设置画图的类型,有九种可能的取值,分别代表不同的样式:(1)’p’)画点;(2)’l’画线5;(3)’b’同时画点和线,但点线不相交;(4)’c’将type= ’b’中的点去掉,只剩下相应的线条部分;(5)’o’同时画点和线,且相互重叠,这是它与type = ’b’的区别;(6)’h’画铅垂线;(7)’s’画阶梯线,从一点到下一点时,先画水平线,再画垂直线;(8)’S’也是画阶梯线,但从一点到下一点是先画垂直线,再画水平线;(9)’n’作一幅空图,没有任何内容,但坐标轴、标题等其它元素都照样显示。

注2:font.main用于控制字体,分别为1: 正常,2: 斜体,3: 粗体,4: 粗斜体

案例03-增添新曲线

cars 《- c(1, 3, 6, 4, 9)

trucks 《- c(2, 5, 4, 5, 12)

plot(cars, type="o", col="blue", ylim=c(0,12)) # ylim控制y轴的范围

lines(trucks, type="o", pch=22, lty=2, col="red") #添加折线,lty=2表示虚线

title(main="Autos", col.main="red", font.main=4)

案例 3-增添新曲线

注1:pch控制点的符号;pch = 19)实圆点、pch = 20)小实圆点、pch = 21)圆圈、pch = 22)正方形、pch = 23)菱形、pch = 24)正三角尖、pch= 25)倒三角尖,其中,21-25可以填充颜色(用bg参数)

注2:lty控制连线的线型,可以是整数(1: 实线,2: 虚线,3: 点线,4: 点虚线,5: 长虚线,6: 双虚线),或者是不超过8个字符的字符串(字符为从"0"到"9"之间的数字)交替地指定线和空白的长度,单位为磅(points)或象素,例如lty="44"和lty=2效果相同。线条虚实样式:0 )不画线,1 )实线,2 )虚线,3 )点线,4 )点划线,5 )长划线,6 )点长划线;或者相应设置如下字符串(分别对应前面的数字):’blank’, ’solid’, ’dashed’, ’dotted’, ’dot dash’, ’longdash’, ’twodash’;还可以用由十六进制的数字组成 的字符串表示线上实线和空白的相应长度,如’F624’

案例04-添加图例

cars 《- c(1, 3, 6, 4, 9)

trucks 《- c(2, 5, 4, 5, 12)

g_range 《- range(0, cars, trucks)

plot(cars, type="o", col="blue", ylim=g_range, axes=FALSE, ann=FALSE) #axes=FALSE, ann=FALSE表示不绘制坐标轴与标题

axis(1, at=1:5, lab=c("Mon","Tue","Wed","Thu","Fri"))

axis(2, las=1, at=4*0:g_range)

# axis(),2表示坐标轴在左侧,at=4*0:g_range),#每4个单位显示一个刻度

box()

lines(trucks, type="o", pch=22, lty=2, col="red")

title(main="Autos", col.main="red", font.main=4) #添加总标题

title(xlab="Days", col.lab=rgb(0,0.5,0)) # 添加x轴标题

title(ylab="Total", col.lab=rgb(0,0.5,0)) # 添加y轴标题

legend(1, g_range, c("cars","trucks"), cex=0.8, col=c("blue","red"), pch=21:22, lty=1:2);

# legend(),1,g_range表示图例左上角的坐标;c("cars","trucks")标签,cex=0.8字体的放大倍数

案例 4-添加图例

案例5-从文本读取数据绘图

将下列数据复制到一个txt文件中,命名为data.txt,放至C盘目录下

cars trucks suvs

1 2 4

3 5 4

6 4 6

4 5 6

9 12 16

autos_data 《- read.table("C:/data.txt", header=TRUE, sep=" ") #sep=” “绰号中间为一空格,如果不输入空格,则会出现数据读取错误

max_y 《- max(autos_data)

plot_colors 《- c("blue","red","forestgreen")

png(filename="C:/figure.png", height=346, width=460, bg="white") # 将图片输出到C目录,名字为figure.png,大小为346*460,背景色为白色

plot(autos_data$cars, type="o", col=plot_colors, ylim=c(0,max_y), axes=FALSE, ann=FALSE)

axis(1, at=1:5, lab=c("Mon", "Tue", "Wed", "Thu", "Fri"))

axis(2, las=1, at=4*0:max_y)

box()

lines(autos_data$trucks, type="o", pch=22, lty=2, col=plot_colors)

lines(autos_data$suvs, type="o", pch=23, lty=3, col=plot_colors)

title(main="Autos", col.main="red", font.main=4)

title(xlab= "Days", col.lab=rgb(0,0.5,0))

title(ylab= "Total", col.lab=rgb(0,0.5,0))

legend(1, max_y, names(autos_data), cex=0.8, col=plot_colors, pch=21:23, lty=1:3);

dev.off()

案例 5-从文本读取数据绘图

案例06-输出图片到PDF以及坐标轴的控制

autos_data 《- read.table("C:/data.txt", header=T, sep=" ")

plot_colors 《- c(rgb(r=0.0,g=0.0,b=0.9), "red", "forestgreen")

pdf(file="C:/figure.pdf", height=3.5, width=5)

par(mar=c(4.2, 3.8, 0.2, 0.2)) #mar控制绘图区别的大小,4个数字代表绘图区域距离下,左,上,右边界的行数,类似的mai则是英寸数

plot(autos_data$cars, type="l", col=plot_colors, ylim=range(autos_data), axes=F, ann=T, xlab="Days",ylab="Total", cex.lab=0.8, lwd=4)

axis(1, lab=F)

text(axTicks(3), -0.8, srt=45, adj=0.5,labels=c("Mon", "Tue", "Wed", "Thu", "Fri"),xpd=T, cex=0.8)

# axTicks()函数的功能是计算坐标轴,取值分别为1,2,3,4。1是计算下方坐标轴,2是左,3是上,4是右。

# text()函数的前两个数字是说明坐标轴标签的位置,str=标签倾斜的角度,adj取值为0到1,精细调整坐标轴的左右位置,0是最左边,1是最右边,0.5居中

axis(2, las=1, cex.axis=0.8)

box()

lines(autos_data$trucks, type="l", lty=2, lwd=2, col=plot_colors)

lines(autos_data$suvs, type="l", lty=3, lwd=2, col=plot_colors)

legend("topleft", names(autos_data), cex=0.8, col=plot_colors, lty=1:3, lwd=2, bty="n");

# bty控制图形边框形状,可用的值为: "o", "l", "7", "c", "u" 和"]" (边框和字符 的外表相像);这些字符本身的形状对应着边框样式,比如(默认值)o表示四条边都显示,而c表示不显示右侧边如果bty="n"则不绘制边框

dev.off()

par(mar=c(5, 4, 4, 2) + 0.1) #恢复边界默认值

案例 6-输出图片到PDF以及坐标轴的控制

案例07-简单条形图

Bar Charts

cars 《- c(1, 3, 6, 4, 9)

barplot(cars)

案例 7-简单条形图

案例08-条形图加标签

autos_data 《- read.table("C:/data.txt", header=T, sep=" ")

barplot(autos_data$cars, main="Cars", xlab="Days",ylab="Total", names.arg=c("Mon","Tue","Wed","Thu","Fri"),border="blue", density=c(10,20,30,40,50))

# density控制条形图中斜线的密度

案例 8-条形图加标签

案例09-分组条形图

autos_data 《- read.table("C:/data.txt", header=T, sep=" ")

data 《- as.matrix(autos_data) #转化为矩阵

barplot(data, main="Autos", ylab= "Total",beside=TRUE, col=rainbow(5))

legend("topleft",c("Mon","Tue","Wed","Thu","Fri"),cex=0.6,bty="n", fill=rainbow(5));

案例 9-分组条形图

案例10-条形图的堆叠

autos_data 《- read.table("C:/data.txt", header=T, sep=" ")

par(xpd=T, mar=par()$mar+c(0,0,0,4))

# xpd对超出边界的图形的处理方式;取值FALSE把图形限制在作图区域内,出界的图形截去;取值TRUE出界的图形不截去

barplot(t(autos_data), main="Autos", ylab="Total", col=heat.colors(3), space=0.2, cex.axis=0.8, las=1,names.arg=c("Mon","Tue","Wed","Thu","Fri"), cex=0.8)

# space为条形间隔,las 坐标轴标签样式;取0、1、2、3四个整数之一,分别表示“总是平行于坐标轴”、“总是水平”、“总是垂直于坐标轴”和“总是竖直”。

legend(6.2, 30, names(autos_data), cex=0.8, fill=heat.colors(3));

par(mar=c(5, 4, 4, 2) + 0.1)

案例 10-条形图的堆叠

案例11-直方图

suvs 《- c(4,4,6,6,16)

hist(suvs)

案例 11-直方图

案例12-直方图2

autos_data 《- read.table("C:/data.txt", header=T, sep=" ")

autos 《- c(autos_data$cars, autos_data$trucks, autos_data$suvs)

hist(autos, col="lightblue", ylim=c(0,10))

案例 12-直方图2

案例13-直方图3

autos_data 《- read.table("C:/data.txt", header=T, sep=" " )

autos 《- c(autos_data$cars, autos_data$trucks, autos_data$suvs)

max_num 《- max(autos)

hist(autos, col=heat.colors(max_num), breaks=max_num, xlim=c(0,max_num), right=T, main="Autos Histogram", las=1)

# right = TRUE (默认)直方图的范围是(a, b]左开右闭,right = FALSE区间为[a, b)

案例 13-直方图3

案例14-不均匀间隔直方图

autos_data 《- read.table("C:/data.txt", header=T, sep=" ")

autos 《- c(autos_data$cars, autos_data$trucks, autos_data$suvs)

max_num 《- max(autos)

brk 《- c(0,3,4,5,6,10,16) # 建立不均匀的区间

hist(autos, col=heat.colors(length(brk)), breaks=brk,

xlim=c(0,max_num), right=F, main="Probability Density",

las=1, cex.axis=0.8, freq=F)

案例 14-不均匀间隔直方图

案例15-对数正态分布

r 《- rlnorm(1000)

hist(r)

案例 15-对数正态分布

案例16-饼图

cars 《- c(1, 3, 6, 4, 9)

pie(cars)

案例 16-饼图

案例17-饼图2

cars 《- c(1, 3, 6, 4, 9)

pie(cars,main="Cars",col=rainbow(length(cars)),labels=c("Mon","Tue","Wed","Thu","Fri"))

案例 17-饼图2

案例18-饼图3

cars 《- c(1, 3, 6, 4, 9)

colors 《- c("white","grey70","grey90","grey50","black")

car_labels 《- round(cars/sum(cars) * 100, 1)

car_labels 《- paste(car_labels, "%", sep="")

pie(cars, main="Cars", col=colors, labels=car_labels,cex=0.8)

legend(1.5, 0.5, c("Mon","Tue","Wed","Thu","Fri"), cex=0.8,

fill=colors)

案例 18-饼图3

案例19-点图

autos_data 《- read.table("C:/data.txt", header=T, sep=" ")

dotchart(t(autos_data))

案例 19-点图

案例20-点图上色

autos_data 《- read.table("C:/data.txt", header=T, sep=" ")

dotchart(t(autos_data), color=c("red","blue","darkgreen"),

main="Dotchart for Autos", cex=0.8)

案例 20-点图上色

案例21-Misc

plot(1, 1, xlim=c(1,5.5), ylim=c(0,7), type="n", ann=FALSE)

text(1:5, rep(6,5), labels=c(0:4), cex=1:5, col=1:5)

# text(1:5, rep(6,5))表示其坐标,分别为(1,6),(2,6),(3,6),(4,6),(5,6)

points(1:5, rep(5,5), cex=1:5, col=1:5, pch=0:4) # 添加点,倍数逐步放大

text((1:5)+0.4, rep(5,5), cex=0.6, (0:4)) # 添加文字0到4

points(1:5, rep(4,5), cex=2, pch=(5:9)) #添加点,类型为pch=5到9

text((1:5)+0.4, rep(4,5), cex=0.6, (5:9)) # 添加文字5到9,(5:9)表示添加的文字

points(1:5, rep(3,5), cex=2, pch=(10:14))

text((1:5)+0.4, rep(3,5), cex=0.6, (10:14))

points(1:5, rep(2,5), cex=2, pch=(15:19))

text((1:5)+0.4, rep(2,5), cex=0.6, (15:19))

points((1:6)*0.8+0.2, rep(1,6), cex=2, pch=(20:25))

text((1:6)*0.8+0.5, rep(1,6), cex=0.6, (20:25))

关于r语言fontfamily到此分享完毕,希望能帮助到您。