R语言:plot函数的参数

cite:https://wenku.baidu.com/view/e35ac84c32687e21af45b307e87101f69e31fb71.html


最近用R语言画图,plot 函数是用的最多的函数,而他的参数非常繁多,由此总结一下,以供后续方便查阅。

plot(x, y = NULL,type = "p", xlim = NULL, ylim = NULL,
log = "", main = NULL, sub = NULL, xlab = NULL, ylab = NULL,
ann = par("ann"), axes = TRUE, frame.plot = axes,
panel.first = NULL, panel.last = NULL, asp = NA, ...)

plot 支持R 模块有:functions,data.frames,density,factor,table等常用结构。


plot参数:

(1) type类型

      

(2) xlim, x 用 (x1, x2) 限制 plot 的x 轴。同理,ylim,y 用(y1,y2)限制plot的y轴。

(3) main,给图片加标题.main="这是一幅图的标题".

     或者 

     title("MainTitle", sub = "sub title",
     cex.main = 2, font.main= 4, col.main= "blue",
     cex.sub = 0.75, font.sub = 3, col.sub = "red")

(4) xlab =“这是X轴表示什么”,ylab =“这是Y轴表示什么”

(5) axes指示是否两个坐标轴都画出。

(6) asp 限定 y/x aspect 比率

(7) points andlines

     参数描述

     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, text, mtext

title(main = NULL,sub = NULL, xlab = NULL, ylab = NULL, line = NA, outer = FALSE, ...) ###主要指定标题字体,大小,颜色,以及X和Y坐标轴的字体,大小,颜色。

main

The main title (on top) using font, size (character expansion) and color par(c("font.main", "cex.main", "col.main")).

sub

Sub-title (at bottom) using font, size and color par(c("font.sub", "cex.sub", "col.sub")).

xlab

X axis label using font, size and color par(c("font.lab", "cex.lab", "col.lab")).

ylab

Y axis label, same font attributes as xlab.

line

specifying a value for line overrides the default placement of labels, and places them this many lines outwards from the plot edge.

outer

a logical value. If TRUE, the titles are placed in the outer margins of the plot.

例如:title(main= list("Stopping Distance versus Speed", cex = 1.5, col = "red", font = 3))

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

在给定X和Y的基础上插入一段注释,

Pos:a positionspecifier for the text. If specified this overrides any adj valuegiven. Values of 1, 2, 3 and 4, respectively indicatepositions below, to the left of, above and to the right of the specifiedcoordinates.,1表示下方,2表示左方,3表示上方,4表示右方。

Labels: acharacter vector or expression specifying the text to bewritten. An attempt is made to coerce other language objects (names and calls)to expressions, and vectors and other classed objects to character vectorsby as.character. If labels is longer than x and y, thecoordinates are recycled to the length of labels.注释部分。


mtext(text, side =3, line = 0, outer = FALSE, at = NA, adj = NA, padj = NA, cex = NA, col = NA, font = NA, ...)

Text is written in one of the four margins of the current figure region orone of the outer margins of the device region。在作图的外围。

side

on which side of the plot (1=bottom, 2=left, 3=top, 4=right).

line

on which MARgin line, starting at 0 counting outwards.

Las:numeric in {0,1,2,3}; the style of axislabels. 标识坐标轴标签方向。

0:always parallelto the axis [default],

1:alwayshorizontal,

2:alwaysperpendicular to the axis,

3:always vertical.

 

legend(x, y =NULL, legend, fill = NULL, col = par("col"),

         border= "black", lty, lwd, pch,

         angle= 45, density = NULL, bty = "o", bg = par("bg"),

         box.lwd= par("lwd"), box.lty = par("lty"), box.col =par("fg"),

         pt.bg= NA, cex = 1, pt.cex = cex, pt.lwd = lwd,

         xjust= 0, yjust = 1, x.intersp = 1, y.intersp = 1,

         adj= c(0, 0.5), text.width = NULL, text.col = par("col"),

         text.font= NULL, merge = do.lines && has.pch, trace = FALSE,

         plot= TRUE, ncol = 1, horiz = FALSE, title = NULL,

         inset= 0, xpd, title.col = text.col, title.adj = 0.5,

         seg.len= 2)

x, y

X,y用于定位图例,也可用单键词"bottomright", "bottom", "bottomleft", "left", "topleft", "top", "topright", "right" and "center"

legend

字符或表达式向量

fill

用特定的颜色进行填充

col

图例中出现的点或线的颜色

border

当fill = 参数存在的情况下,填充色的边框

lty, lwd

图例中线的类型与宽度

pch

点的类型

angle

阴影的角度

density

阴影线的密度

bty

图例框是否画出,o为画出,默认为n不画出

bg

bty != "n"时,图例的背景色

box.lty, box.lwd, box.col

bty = "o"时,图例框的类型,box.lty决定是否为虚线,box.lwd决定粗线,box.col决定颜色

pt.bg

点的背景色

cex

字符大小

pt.cex

点的大小

pt.lwd

点的边缘的线宽

x.intersp

图例中文字离图片的水平距离

y.intersp

图例中文字离图片的垂直距离

adj

图例中字体的相对位置

text.width

图例字体所占的宽度

text.col

图例字体的颜色

text.font

图例字体

merge

logical, if TRUE,合并点与线,但不填充图例框,默认为TRUE

trace

logical; if TRUE显示图例信息.

plot

logical. If FALSE不画出图例

ncol

图例中分类的列数

horiz

logical; if TRUE,水平放置图例

title

给图例加标题

inset

当图例用关键词设置位置后,inset = 分数,可以设置其相对位置

xpd

xpd=FALSE,即不允许在作图区域外作图,改为TRUE即可,与par()参数配合使用。

title.col

标题颜色

title.adj

图例标题的相对位置,0.5为默认,在中间。0最左,1为最右。

seg.len

lty 与lwd的线长,长度单位为字符宽度

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值