匠人府分享 http://blog.sciencenet.cn/u/meiweipingg

博文

用 R 简单作图 (plot in R) 的各项参数设置

已有 6117 次阅读 2016-5-26 00:26 |个人分类:R语言|系统分类:科研笔记| plot, font, legend, axis, abline

# step 1. plot

> plot(x, y, type = "p", pch = NULL[variable.Code], bg = NA, cex = NULL, xlim = NULL,ylim = NULL,

    xaxt = NULL, yaxt = NULL, xaxs= NULL, yaxs= NULL, tck = NULL,

    main = NULL,  sub = NULL,  xlab = NULL, ylab = NULL, ann =par("ann"),

    axes = TRUE, frame.plot = axes, panel.first = NULL,panel.last = NULL, asp = NA, ...)


# for example, pch = c(0,15)[year.code-2014], if you are interested, just try it, a surprise.


Arguments

x, y

the x and y arguments provide the x and y coordinates for the plot.  Any reasonable way of defining the coordinates is acceptable.

type

character  string giving the type of plot desired. The following values are possible.

type

what type of plot should be drawn. Possible types are

   "p" for points,

   "l" for lines,

   "b" for both,

   "c" for the lines part alone of "b",

   "o" for both ‘overplotted’,

   "h" for ‘histogram’ like (or  ‘high-density’) vertical lines,

   "s" for stair steps,

   "S" for other steps, see  ‘Details’ below,

 "n" for no plotting.

xlim

the x limits (x1, x2) of the plot. Note  that x1 > x2 is allowed and leads to a ‘reversed  axis’.

The default value, NULL, indicates that the range of the finite values to be plotted should be used.

ylim

the y limits of the plot.

main
a main title for the plot, see also title.

sub

a sub title for the plot.

xlab

a label for the x axis, defaults to a  description of x.

ylab

a label for the y axis, defaults to adescription of y.

pch

a vector of plotting characters or symbols: see points.

Values of pch are storedinternally as integers. The interpretation is

  • NA_integer_:     no symbol.

  • 0:18:     S-compatible vector symbols.

  • 19:25:     further R vector symbols.

  • 26:31: unused     (and ignored).

  • 32:127: ASCII     characters.

  • 128:255 native     characters only in a single-byte locale and for the symbol font.     (128:159 are only used on Windows.)

  • -32 ... Unicode     code point (where supported).


The following R plotting symbolsare can be obtained with pch =19:25: those with 21:25can be colored andfilled with different colors: col gives the border color and bg the backgroundcolor (which is "grey" in the figure)

  • pch = 19:     solid circle,

  • pch = 20:     bullet (smaller solid circle, 2/3 the size of 19),

  • pch = 21:     filled circle,

  • pch = 22:     filled square,

  • pch = 23:     filled diamond,

  • pch = 24:     filled triangle point-up,

  • pch = 25:     filled triangle point down.

Note that unlike S(which uses octagons), symbols 1, 10, 13 and 16 use circles. Thefilled shapes 15:18 do not include a border.



cex

a numerical vector giving the amount by which plotting charactersand symbols should be scaled relative to the default. This works as a multipleof par("cex"). NULL andNA are equivalent to 1.0. Note that this doesnot affect annotation: see below

  • cex.axis。表示在当前的cex设定情况下,对坐标轴刻度值字体的放大倍数。

  • cex.lab。表示在当前的cex设定情况下,对坐标轴名称字体的放大倍数。

  • cex.main。表示在当前的cex设定情况下,对主标题字体的放大倍数。

  • cex.sub。表示在当前的cex设定情况下,对子标题字体的放大倍数。

#----------------------------------------------------------------------------------------------

#step 2. if in step 1 , xaxt = "n", yaxt = "n", then we should specify axis , see below.


> axis(side = 1, las = 0, labels = TRUE, font = NA, lty = "solid", lwd = 1, col.axis = NULL, cex = NULL, tck = NULL, ...)

> axis(side = 2, las = 2, labels = TRUE, font = NA, lty = "solid", lwd = 1, col.axis = NULL, cex = NULL, tck = NULL, ...)

Arguments

side  

an integer specifying which side of the plot the axis is to be  drawn on. The axis is placed as follows: 1=below, 2=left, 3=above and  4=right.

lty

line type for both the axis line and the tick marks.

lwd  

line widths for the axis line and the tick marks. Zero or  negative values will suppress the line or ticks.

col

The colors for lines and points. Multiple colors can be specifiedso that each point can be given its own color. If there are fewer colors thanpoints they are recycled in the standard fashion. Lines will all be plotted inthe first colour specified.

col.axis

The color to be used for axis annotation. Defaults to "black".

col.lab

The color to be used for x and y labels. Defaults to "black".

col.main

The color to be used for plot main titles. Defaults to "black".

col.sub

The color to be used forplot sub-titles. Defaults to "black".

font

An integer which specifies which font to use for text. Ifpossible, device drivers arrange so that 1 corresponds to plain text (thedefault), 2 to bold face, 3 to italic and 4 to bold italic. Also, font 5 isexpected to be the symbol font, in Adobe symbol encoding. On some devices font familiescan be selected by family to choose different sets of 5 fonts.

font.axis

The font to be used for axis annotation.

font.lab

The font to be used for x and y labels.

font.main

The font to be used for plot main titles.

font.sub

The font to be used for plot sub-titles.


particularly, cex.axis, col.axis and font.axis foraxis annotation, tck or tcl fortick mark length and direction, 坐标轴刻度长度,正数为在图内侧画,负数为在外侧画。las for vertical/horizontal label orientation. 表示坐标轴标签平行于坐标轴还是垂直于坐标轴,0-平行;2-垂直Parameters xaxt (sides1 and 3) and yaxt (sides 2 and 4) control if the axis isplotted at all.xaxt="n",yaxt="n"表示不绘制x轴或y轴。



#----------------------------------------------------------------------------------------------

# step 3.if need add some lines, for example


> abline(h = yvalue, v = xvalue, lty = NULL, ...)


#----------------------------------------------------------------------------------------------

# step 4.legend


> legend(x,y,legend,)

#----------------------------------------------------------------------------------------------



# References

# http://www.inside-r.org/r-doc/graphics/par

# http://www.aichengxu.com/view/2583064






http://wap.sciencenet.cn/blog-651374-979745.html

上一篇:我最常去的国际科研交流网站ResearchGate
下一篇:物种生态位重复度计算:“SIBER” (SIAR package)分析in R

0

该博文允许注册用户评论 请点击登录 评论 (0 个评论)

数据加载中...
扫一扫,分享此博文

Archiver|手机版|科学网 ( 京ICP备07017567号-12 )

GMT+8, 2021-10-24 14:56

Powered by ScienceNet.cn

Copyright © 2007- 中国科学报社

返回顶部