x<-c(1:10)
y<-x
z<-10/x
opar<-par(no.readonly = T)
par(mar=c(5,4,4,8)+0.1)
plot(x,y,type="b",pch=23,col="red",yaxt="n",lty=3,ann=F)
lines(x,z,type = "b",pch=22,col="blue",lty=2)
axis(2,at=x,labels = x,col.axis="red",las=2)
axis(4,at=z,labels = round(z,digits = 2),col.axis="blue",las=2,cex.axis=0.7,tck=-.01)
mtext("y=10/x",side = 4,line = 3,cex.lab=1,las=2,col="blue")
title("An example of crestive axes",xlab="X value",ylab="Y=X")
par(opar)

我们可以通过函数text()和mtext()将文本添加到图形中。text可以向绘图区域内部添加文本,而mtext则向图形的四个边界之一添加文本。使用格式分别如下:
例:

opar<-par(no.readonly = T) #生成一个可以修改的当前图形参数表
par(cex=1)
plot(1:7,1:7,type="n")
text(3,3,"Example of default text")
text(4,4,family="mono","Example of mono-spaced text")
text(5,5,family="serif","Example of serif text")
par(opar)
 
下面简单介绍图形组合:

attach(mtcars)
opar<-par(no.readonly = T)
par(mfrow=c(2,2))    
#2行2列的图形矩阵
plot(wt,mpg,main = "Scatterplot of vs.mpg")
plot(wt,disp,main = "Scatterplot of vs.disp")
hist(wt,main="Histogram  of wt")
boxplot(wt,main="Boxplot  of wt")
par(opar)
detach(mtcars)
attach(mtcars)
layout(matrix(c(1,1,2,3),2,2,byrow=T))
hist(wt)
hist(mpg)
hist(disp)
detach(mtcars)

attach(mtcars)
layout(matrix(c(1,1,2,3),2,2,byrow=T),
     
 widths = c(3,1),heights = c(1,2))
hist(wt)
hist(mpg)
hist(disp)
detach(mtcars)

opar <- par(no.readonly=T)
par(fig=c(0,0.8,0,0.8))
plot(mtcars$wt,mtcars$mpg,
   
 xlab="Miles per Gallon",
   
 ylab="Car weight")
par(fig=c(0,0.8,0.55,1),new=T)
boxplot(mtcars$wt,horizontal=T,axes=F)
par(fig=c(0.65,1,0,0.8),new=T)
boxplot(mtcars$mpg,axes=F)
mtext("Enhenced Scatterplot",side=3,outer=T,line=-3)
par(opar)
本篇内容摘自《R语言实战》第三章:图形初阶
 
 
2016年8月30日补充:
> hh <- hist(Nile) #得到直方图的同时,hist()函数也有一返回值列表> hh
$breaks
 [1]  400  500  600  700  800  900 1000 1100 1200 1300 1400

$counts
 [1]  1  0  5 20 25 19 12 11  6  1

$density
 [1] 0.0001 0.0000 0.0005 0.0020 0.0025 0.0019 0.0012 0.0011 0.0006 0.0001

$mids
 [1]  450  550  650  750  850  950 1050 1150 1250 1350

$xname
[1] "Nile"

$equidist
[1] TRUE

attr(,"class")
[1] "histogram"

R语言图形base系统(二)的更多相关文章

  1. R语言图形base系统(一)

           一般R作图有三大绘图系统:base系统.ggplot2绘图系统.lattice绘图系统.        本篇主要介绍base系统绘图时的图形参数.一般用plot()函数来完成.在R中,若 ...

  2. R语言图形base系统(三)

     本篇介绍R语言base系统绘制散点图.条形图.直方图.箱线图.饼图,还将简单介绍点图.核密度图.折线图. 散点图: attach(mtcars) plot(wt, mpg, main="B ...

  3. R语言-图形初阶

    在本节中,主要目的是如何使用R语言做出简单的图形 案例1:做出wt和mpg之间的关系 attach(mtcars) plot(wt,mpg) abline(lm(mpg~wt)) title('Reg ...

  4. R语言基础入门之二:数据导入和描述统计

    by 写长城的诗 • October 30, 2011 • Comments Off This post was kindly contributed by 数据科学与R语言 - go there t ...

  5. R语言与概率统计(二) 假设检验

    > ####################5.2 > X<-c(159, 280, 101, 212, 224, 379, 179, 264, + 222, 362, 168, 2 ...

  6. R语言学习笔记(二)

    今天主要学习了两个统计学的基本概念:峰度和偏度,并且用R语言来描述. > vars<-c("mpg","hp","wt") &g ...

  7. R语言实战读书笔记(二)创建数据集

    2.2.2 矩阵 matrix(vector,nrow,ncol,byrow,dimnames,char_vector_rownames,char_vector_colnames) 其中: byrow ...

  8. R语言学习笔记(二十一五):如何如何提升R语言运算的性能以及速度

    在R中获得快速运行代码的方法 使用向量化运算 R语言的并行计算可以用parallel和foreach包 加快R运行速度还可以使用cmpfun()函数即字节码编译器 再者就是在R中调用C或C++ 同时还 ...

  9. R语言高性能编程(二)

    接着上一篇 一.减少内存使用的简单方法1.重用对象而不多占用内存 y <- x 是指新变量y指向包含X的那个内存块,只有当y被修改时才会复制到新的内存块,一般来说只要向量没有被其他对象引用,就可 ...

随机推荐

  1. 微信小程序 - .gitignore失效问题

    -------------------------------------------- Last Update Date:2018-8-8 ----------------------------- ...

  2. ionic准备之angular基础———服务provider 和 factory和service(9)

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  3. 如果你报createSQLQuery is not valid without active transaction,请看这里

    原文:https://blog.csdn.net/yinjian520/article/details/8666695 很多时候我们使用hibernate的session时,都是让session在某一 ...

  4. &&与&符号区别

    http://topic.csdn.net/u/20080915/16/f5125300-f69f-4da8-9c3a-a7458590553f.html && 与 &区别: ...

  5. mysql主从从

    1.从官网下载安装percona-xtrabackup2.xtrabackup只能备份和恢复innodb的表,所以这里用innobackupex,可以实现对myisam和innodb的表在线备份和恢复 ...

  6. Atitit.常见的4gl 第四代编程语言  与 dsl

    Atitit.常见的4gl 第四代编程语言  与 dsl 1. 4gl dsl发展历史1 2. 4gl dsl的特点1 3. 常见的4gl 第四代编程语言 dsl2 4. 未来趋势与标准2 4.1.1 ...

  7. python函数形参中的*args和**kwargs

    转载:https://www.cnblogs.com/xuyuanyuan123/p/6674645.html 多个实参,放到一个元组里面,以*开头,可以传多个参数:**是形参中按照关键字传值把多余的 ...

  8. iOS tableView Section圆角方案

    给tableView的section设置圆角 首先给让cell左右偏移一点的距离,通过重写cell的setframe方法来实现 -(void)setFrame:(CGRect)frame{ CGFlo ...

  9. Java中常用的加密算法MD5,SHA,RSA

    1. MD5加密,常用于加密用户名密码,当用户验证时. protected byte[] encrypt(byte[] obj){  try {  MessageDigest md5 = Messag ...

  10. maven 依赖文件 pom.xml 编译 mvn compile 运行 不用mvn exec:java -Dexec.mainClass="hello.HelloWorld" 打成jar包 mvn package mvn install http://blog.csdn.net/yaya1943/article/details/48464371

    使用maven编译Java项目 http://blog.csdn.net/yaya1943/article/details/48464371  使用"mvn clean"命令清除编 ...