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. hbuilder - wap to app

    官方文档: http://www.dcloud.io/wap2app.html 新建Wap2App,示例网址:www.baidu.com 随后,我们可以在 最后,我们可以 打包完成以后,下载即可

  2. Quaternion 四元数

    Quaternions are used to represent rotations. 四元数用于表示旋转. They are compact, don't suffer from gimbal l ...

  3. 【Excle】如何隐藏数据透视表中的错误值

    如下:数据透视表出现错误 怎么解决呢 步骤 方法① 单击数据透视表任意单元格→数据透视表工具→分析→选项→勾选"对于错误值显示"→确定 方法② 右键→数据透视表选项(同样可以修改)

  4. IIS7.5下的web.config 404应该如何配置

    IIS环境下web.config的配置的问题,在IIS7.5中添加配置404页面时遇到了一些问题,记录如下: 一开始在<customError>下的<error>节点配置404 ...

  5. 网站拓扑图(来自qq)

  6. linux路由服务

    本文介绍怎样使用linux创建一台简单的路由server. 主要包含几个參数的设置:ip_forward和rp_filter. 1.开启IP forwarding # 重新启动后失效 $ echo & ...

  7. 程序员必备SQL语句优化技巧

    1.任何地方都不要使用 select * from t ,用具体的字段列表代替"*",不要返回用不到的任何字段. 2.尽量使用数字型字段,字符型会降低查询和连接的性能,并会增加存储 ...

  8. 无法连接到服务器,用户xxx登陆失败"

    无法连接到服务器,用户xxx登陆失败" 该错误产生的原因是由于SQL Server使用了"仅 Windows"的身份验证方式, 因此用户无法使用SQL Server的登录 ...

  9. java中替换双引号 Java问题通用解决代码 Java问题通用解决代码

    http://blog.csdn.net/newhappy2008/article/details/4785263 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ...

  10. 正则表达式 判断IP 数字

    1.正则表达式 public static bool checkIP(string strIP) { //string regex = @"^(2[0-4]\d | 25[0-5] | [0 ...