3.1 使用图形

  • plot:基础绘图
  • abline:添加回归直线
  • hist:绘制直方图
  • boxplot:绘制箱线图
  • dev.new():returns the return value of the device opened, usually invisible NULL.
  • dev.cur(): returns a length-one named integer vector giving the number and name of the active device, or 1, the null device, if none is active.
  • dev.list(): returns the numbers of all open devices, except device 1, the null device. This is a numeric vector with a names attribute giving the device names, or NULL is there is no open device.
  • dev.next(which = dev.cur()):return the number and name of the next device in the list of devices. This will be the null device if and only if there are no open devices.
  • dev.prev(which = dev.cur()): return the number and name of the previous device in the list of devices. This will be the null device if and only if there are no open devices.
  • dev.off(which = dev.cur()): returns the number and name of the new active device (after the specified device has been shut down).
  • dev.set(which = dev.next()): returns the number and name of the new active device.
  • graphics.off()

Only one device is the ‘active’ device: this is the device in which all graphics operations occur. There is a "null device" which is always open but is really a placeholder: any attempt to use it will open a new device specified by getOption("device").

Devices are associated with a name (e.g., "X11" or "postscript") and a number in the range 1 to 63; the "null device" is always device 1. Once a device has been opened the null device is not considered as a possible active device. There is a list of open devices, and this is considered as a circular list not including the null device. dev.next and dev.prev select the next open device in the appropriate direction, unless no device is open.

3.2 一个简单的例子

dose <- c(20, 30, 40, 45, 60)
drugA <- c(16, 20, 27, 40, 60)
drugB <- c(15, 18, 25, 31, 40)
plot(dose, drugA, type="b")

3.3 图形参数

  • plot(x, y, ...): Generic function for plotting of R objects. For more details about the graphical parameter arguments, see par.

For simple scatter plots, plot.default will be used. However, there are plot methods for many R objects, including functions, data.frames, density objects, etc. Use methods(plot) and the documentation for these.

type: what type of plot should be drawn. Possible types are.

  1. "p" for points,
  2. "l" for lines,
  3. "b" for both,
  4. "c" for the lines part alone of "b",
  5. "o" for both ‘overplotted’,
  6. "h" for ‘histogram’ like (or ‘high-density’) vertical lines,
  7. "s" for stair steps,
  8. "S" for other steps, see ‘Details’ below,
  9. "n" for no plotting.

The two step types differ in their x-y preference: Going from (x1,y1) to (x2,y2) with x1 < x2, type = "s" moves first horizontal, then vertical, whereas type = "S" moves the other way around.

9种图形如下:

main: an overall title for the plot: see title.

sub: a sub title for the plot: see title.

xlab: a title for the x axis: see title.

ylab: a title for the y axis: see title.

asp: the y/x aspect ratio, see plot.window.(x和y的长宽比)

我们可以通过修改称为图形参数的选项来自定义一幅图形的多个特征(字体、颜色、坐标轴、标签)。一种方法是通过函数par()来指定这些选项。以这种方式设定的参数值除非被再次修改,否则将在会话结束前一直有效。
  • par(..., no.readonly = FALSE)

par can be used to set or query(查询) graphical parameters. Parameters can be set by specifying them as arguments to par in tag = value form, or by passing them as a list of tagged values.(通过tag=value传递或者通过标记列表传递)

no.readonly: logical; if TRUE and there are no other arguments, only parameters are returned which can be set by a subsequent par() call on the same device.

adj

The value of adj determines the way in which text strings are justified in text, mtext and title. A value of 0 produces left-justified text, 0.5 (the default) centered text and 1 right-justified text. (Any value in [0, 1] is allowed.)

Note that the adj argument of text also allows adj = c(x, y) for different adjustment in x- and y- directions.

确定文本和标题的对齐方式,0~1之间。

ann If set to FALSE, high-level plotting functions calling plot.default do not annotate the plots they produce with axis titles and overall titles. The default is to do annotation.
ask

logical. If TRUE (and the R session is interactive) the user is asked for input, before a new figure is drawn.

在绘图前对用户进行提醒。

bg

The color to be used for the background of the device region. When called from par() it also sets new = FALSE.

可以通过颜色下标、颜色名称、十六进制的颜色值、RGB值或HSV值来指定颜色。举例来说,col=1、col="white"、col="#FFFFFF"、col=rgb(1,1,1)和col=hsv(0,0,1)都是表示白色的等价方式。

bty

A character string which determined the type of box which is drawn about plots. If bty is one of "o" (the default), "l", "7", "c", "u", or "]" the resulting box resembles the corresponding upper case letter. A value of "n" suppresses the box.

边框形状通过形状相似的字母或数字来定义,"n"代表没有边框。

cex

A numerical value giving the amount by which plotting text and symbols should be magnified relative to the default. This starts as 1 when a device is opened, and is reset when the layout is changed.

图形放大倍数。

cex.axis The magnification to be used for axis annotation relative to the current setting of cex.
cex.lab The magnification to be used for x and y labels relative to the current setting of cex.
cex.main The magnification to be used for main titles relative to the current setting of cex.
cex.sub The magnification to be used for sub-titles relative to the current setting of cex.
cin

R.O.; character size (width, height) in inches.

只读!

> par()$cin
[1] 0.15 0.20
col A specification for the default plotting color.
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 for plot sub-titles. Defaults to "black".
cra

R.O.; size of default character (width, height) in ‘rasters’ (pixels).

> par()$cra
[1] 14.4 19.2
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   

R语言实战(三) 图形初阶的更多相关文章

  1. R语言实战读书笔记(三)图形初阶

    这篇简直是白写了,写到后面发现ggplot明显更好用 3.1 使用图形 attach(mtcars)plot(wt, mpg) #x轴wt,y轴pgabline(lm(mpg ~ wt)) #画线拟合 ...

  2. R提高篇(二): 图形初阶

    目录: 图形示例 图形参数 符号.线条 颜色 文本属性 尺寸与边界 自定义标题 自定义坐标轴 图例 文本标注 图形组合 图形示例 如下代码描述病人对两种药物五个剂量水平上的响应情况 > myda ...

  3. R语言实战(一)介绍、数据集与图形初阶

    本文对应<R语言实战>前3章,因为里面大部分内容已经比较熟悉,所以在这里只是起一个索引的作用. 第1章       R语言介绍 获取帮助函数 help(), ? 查看函数帮助 exampl ...

  4. R语言实战(三)基本图形与基本统计分析

    本文对应<R语言实战>第6章:基本图形:第7章:基本统计分析 =============================================================== ...

  5. R语言实战(七)图形进阶

    本文对应<R语言实战>第11章:中级绘图:第16章:高级图形进阶 基础图形一章,侧重展示单类别型或连续型变量的分布情况:中级绘图一章,侧重展示双变量间关系(二元关系)和多变量间关系(多元关 ...

  6. R入门<三>-R语言实战第4章基本数据管理摘要

    入门书籍:R语言实战 进度:1-4章 摘要: 1)实用的包 forecast:用于做时间序列预测的,有auto.arima函数 RODBC:可以用来读取excel文件.但据说R对csv格式适应更加良好 ...

  7. R语言实战(第二版)-part 1笔记

    说明: 1.本笔记对<R语言实战>一书有选择性的进行记录,仅用于个人的查漏补缺 2.将完全掌握的以及无实战需求的知识点略去 3.代码直接在Rsudio中运行学习 R语言实战(第二版) pa ...

  8. R语言实战

    教材目录 第一部分 入门 第一章 R语言介绍 第二章 创建数据集 第三章 图形初阶 第四章 基本数据管理 第五章 高级数据管理 第二部分 基本方法 第六章 基本图形 第七章 基本统计方法 第三部分 中 ...

  9. R 语言实战-Part 3 笔记

    R 语言实战(第二版) part 3 中级方法 -------------第8章 回归------------------ #概念:用一个或多个自变量(预测变量)来预测因变量(响应变量)的方法 #最常 ...

  10. R语言实战(四)回归

    本文对应<R语言实战>第8章:回归 回归是一个广义的概念,通指那些用一个或多个预测变量(也称自变量或解释变量)来预测响应变量(也称因变量.效标变量或结果变量)的方法.通常,回归分析可以用来 ...

随机推荐

  1. jquery框架概览(二)

    (function(window, undefined) { })(window) window对象作为参数传进闭包的好处 JavaScript 全局对象.函数以及变量均自动成为 window 对象的 ...

  2. 安装oracle 11g 客户端,检查过程中报物理内存不足的解决

    今早接到同事电话,说安装oracle 11g客户端的时候,在检查先决条件的时候,报错,说内存不足,但是本机的内存是2G,肯定够用:如图: 找了一圈,原来Oracle执行先决条件检查是依赖c$共享,很多 ...

  3. 使用dtree构建框架导航

    前言: 该例子就是个框架导航 , 左边包含dtree的框架,点击上面的节点右边框架显示 说明步骤: 1. 首先获得dtree  http://www.destroydrop.com/javascrip ...

  4. piranha(注意iptables和selinux的问题)

    piranha是红帽官方提供的一套工具,安装和配置都非常简单,可以快速部署. piranha方案原理结构描述: piranha方案是基于lvs基础上设计的一套负载均衡高可用解决方案 LVS运行在一对有 ...

  5. Navicat远程连接服务器Mysql

    使用NAVICAT远程访问MYSQL的步骤 1.修改远程访问权限 //进入MySQL服务器或使用其它工具 xxxx@ubuntu:/$ mysql -h localhost -u root -p xx ...

  6. <JZOJ5910>duliu

    愤怒 考场想到正解 然后觉得我的“正解”和正解差不多 一样的效果 被忽略的与正解的不同也想到了 然而 我懒得再写 于是快乐10分 气坏了 #include<cstdio> #include ...

  7. input系统——android input系统

    AndroidInput系统--JNI NativeInputManager InputManger InputReader AndroidInput系统--InputReader AndroidIn ...

  8. js 函数的防抖(debounce)与节流(throttle)

    原文:函数防抖和节流: 序言: 我们在平时开发的时候,会有很多场景会频繁触发事件,比如说搜索框实时发请求,onmousemove, resize, onscroll等等,有些时候,我们并不能或者不想频 ...

  9. 猫头鹰的深夜翻译:核心JAVA并发一

    简介 从创建以来,JAVA就支持核心的并发概念如线程和锁.这篇文章会帮助从事多线程编程的JAVA开发人员理解核心的并发概念以及如何使用它们. (博主将在其中加上自己的理解以及自己想出的例子作为补充) ...

  10. 组合数学之Pólya计数理论

    1 群 群$(G, cdot)$: 闭合, 结合律, 幺元, 逆 1.1 置换群 置换为双射$pi:[n]to [n]$, 置换之间的操作符 $cdot$ 定义为函数的复合, 即$(pi cdot s ...