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. Recycling Settings for an Application Pool <recycling>

    Overview The <recycling> element contains configuration settings that control the conditions t ...

  2. keycode值大全

    13 我们只知道13是回车,主要是其他的也不是很常用,所以不用记. keycode 8 = BackSpace BackSpace   keycode 9 = Tab Tab   keycode 12 ...

  3. [转]Tomcat工作原理详解

    一.Tomcat背景 自从JSP发布之后,推出了各式各样的JSP引擎.Apache Group在完成GNUJSP1.0的开发以后,开始考虑在SUN的JSWDK基础上开发一个可以直接提供Web服务的JS ...

  4. Web用户的身份验证及WebApi权限验证流程的设计和实现(尾)

    5. WebApi 服务端代码示例 5.1 控制器基类ApiControllerBase [csharp] view plaincopy   /// /// Controller的基类,用于实现适合业 ...

  5. MVC组件分析

    MVC组件分析   2 System.Web.Mvc V 4.0.0.0 组件分析 2.1 Routing组件(路由选择) Routing的作用就是负责分析Url Action的要求• 必须是一个公有 ...

  6. PHP框架认识初步

    PHP框架比較 CodeIgniter Codeigniter 相当轻量级.下载下来就能用, CI 的最大特点就是可扩展性非常强 你能够通过不改动源代码的方式 优雅的扩展差点儿全部的东西. think ...

  7. python测试网页是否能正常登陆

    #!/usr/bin/python #encoding:utf-8 ##实现网页的登陆检查 import HTMLParser import urlparse import cookielib imp ...

  8. GDBus

    1. https://en.wikipedia.org/wiki/D-Bus In computing, D-Bus (for "Desktop Bus"[4]), a softw ...

  9. win10 安装anaconda 无法使用pip 报错缺少SSL模块

    在anaconda prompt里可以正常使用pip,普通cmd下activate后也可以使用.但不激活就不行. 解决方法: 是环境变量的问题. 安装anaconda需要添加三个环境变量,而不是只添加 ...

  10. 二路归并排序的java实现

    转载请注明出处 http://www.cnblogs.com/dongxiao-yang/p/6410775.html 参考引言:在排序算法中快速排序的效率是非常高的,但是还有种排序算法的效率可以与之 ...