Chapter 06—Basic graphs
三. 柱状图(Histogram)
1. hist():画柱状图
·breaks(可选项):控制柱状图的小柱子的条数;
·freq=FALSE:基于概率(probability),而非频率(frequencies),绘制图形。
·还可以有其他参数,如:xlab,ylab,main,col,lwd...
2. lines():在已有图形上添加线条。
3. box():给已有图形添加一个框。
4. rug()
5. diff()
6.box()
例07:
> par(mfrow=c(2,2))
> hist(mtcars$mpg)
>
> hist(mtcars$mpg,breaks=12,col="red",xlab="Miles Per Gallon",main="Histogram,rug plot,density curve")
>
> hist(mtcars$mpg,freq=FALSE,breaks=12,col="red",xlab="Miles Per Gallon",main="Histogram,rug plot,density curve")
> rug(jitter(mtcars$mpg))
> lines(density(mtcars$mpg),col="blue",lwd=2)
> x<-mtcars$mpg
> h<-hist(x,breaks=12,col="red",xlab="Miles Per Gallon",main="Histogram with normal curve and box")
> xfit<-seq(min(x),max(x),length=40)
> yfit<-dnorm(xfit,mean=mean(x),sd=sd(x))
> yfit<-yfit*diff(h$mids[1:2]*length(x))
> lines(xfit,yfit,col="blue",lwd=2)
> box()
四. 中心密度曲线(kernel dentity plots)
plot(dentity(x)):画中心密度曲线
sm包中的函数sm.density.compare()函数:在同一个图中,画出多组中心密度曲线。
例08:
> par(mfrow=c(2,1))
> > d<-density(mtcars$mpg)
> plot(d)
> > d<-density(mtcars$mpg)
> plot(d,main="Kernel Density of Miles Per Gallon")
> polygon(d,col="red",border="blue")
> rug(mtcars$mpg,col="brown")

例09:
> install.packages("sm")
trying URL 'http://cran.rstudio.com/bin/windows/contrib/3.0/sm_2.2-5.3.zip'
Content type 'application/zip' length 445006 bytes (434 Kb)
opened URL
downloaded 434 Kb
package ‘sm’ successfully unpacked and MD5 sums checked
The downloaded binary packages are in
C:\Users\seven-wang\AppData\Local\Temp\RtmpYfr9xm\downloaded_packages
> library(sm)
Package `sm', version 2.2-5: type help(sm) for summary information
> par(lwd=2)
> attach(mtcars)
> cyl.f<-factor(cyl,levels=c(4,6,8),labels=c("4 cylinder","6 cylinder","8 ylinder"))
> sm.density.compare(mpg,cyl,xlab="Miles Per Gallon")
> title(main="MPG Distribution by Car Cylinders")
> colfill<-c(2:(1+length(levels(cyl.f))))
> legend(locator(1),levels(cyl.f),fill=colfill)
> detach()

Chapter 06—Basic graphs的更多相关文章
- Chapter 04—Basic Data Management
1. 创建新的变量 variable<-expression expression:包含一组大量的操作符和函数.常用的算术操作符如下表: 例1:根据已知变量,创建新变量的三种途径 > my ...
- Chapter 2 Basic Elements of JAVA
elaborate:详细说明 Data TypesJava categorizes data into different types, and only certain operationscan ...
- 吴裕雄--天生自然 R语言开发学习:基本图形(续二)
#---------------------------------------------------------------# # R in Action (2nd ed): Chapter 6 ...
- 吴裕雄--天生自然 R语言开发学习:基本图形(续一)
#---------------------------------------------------------------# # R in Action (2nd ed): Chapter 6 ...
- 吴裕雄--天生自然 R语言开发学习:基本图形
#---------------------------------------------------------------# # R in Action (2nd ed): Chapter 6 ...
- 吴裕雄--天生自然 R语言开发学习:基本图形(续三)
#---------------------------------------------------------------# # R in Action (2nd ed): Chapter 6 ...
- 离散数学及其应用(Discrete Mathematica With Application 7th)学习笔记 第一章
目前本人只进行到了第五章的章末补充练习,应该是从4月6号开始学习的,又是英文版,而且基本就下班回家抽2个小时左右去学,所以进度较慢. 由于本质是数学,除了一些程序处理和大计算量的问题,基本上一本草稿本 ...
- tensorflow学习框架(炼数成金网络版学习记录)
chapter1 #变量 import tensorflow as tf x = tf.Variable([1,2]) a = tf.constant([3,3]) #增加一个减法op sub = t ...
- 吴裕雄--天生自然 R语言开发学习:中级绘图(续二)
#------------------------------------------------------------------------------------# # R in Action ...
随机推荐
- 前端技术之:如何创建一个NodeJs命令行交互项目
方法一:通过原生的NodeJs API,方法如下: #!/usr/bin/env node # test.js var argv = process.argv; console.log(argv) ...
- [Python]python面向对象 __new__方法及单例设计
__new__ 方法 使用 类名() 创建对象时,Python 的解释器 首先 会 调用 __new__ 方法为对象 分配空间 __new__ 是一个 由 object 基类提供的 内置的静态方法,主 ...
- Logback MDC
Mapped Diagnostic Contexts (MDC) (译:诊断上下文映射) Logback的设计目标之一是审计和调试复杂的分布式应用程序.大多数实际的分布式系统需要同时处理来自多个客 ...
- Scrapy进阶知识点总结(一)——基本命令与基本类(spider,request,response)
一.常见命令 scrapy全局命令可以在任何地方用,项目命令只能在项目路径下用 全局命令: 项目命令: startproject crawl genspider check settings list ...
- python机器学习——逻辑回归
我们知道感知器算法对于不能完全线性分割的数据是无能为力的,在这一篇将会介绍另一种非常有效的二分类模型--逻辑回归.在分类任务中,它被广泛使用 逻辑回归是一个分类模型,在实现之前我们先介绍几个概念: 几 ...
- nyoj 37-回文字符串(reverse, 动态规划, lcs)
37-回文字符串 内存限制:64MB 时间限制:3000ms Special Judge: No accepted:10 submit:17 题目描述: 所谓回文字符串,就是一个字符串,从左到右读和从 ...
- 如何在当前文件夹打开cmd(基于win10)
如何在当前文件夹打开cmd(基于win10) 方法一: 1.先打开你要进入的文件夹 2.在标记的位置输入cmd,就可以进入当前文件的cmd 方法二: 1.打开你要进入的文件夹 2.通过shift + ...
- Python3.7.1(四) Print如何在输出中插入变量
# 如果想在打印的字符串中的任意地方加入任意的变量,可以使用python的格式化输出.## 用例代码如下:s = 'Hello'x = len(s)print("The length of ...
- (二十九)golang--map
map:是key-value数据结构,又称为字段或者关联数组,类似其它编程语言的集合: 基本语法:var 名称 map[键类型]值类型 key的类型可以是:bool.数字.string.指针.管道,还 ...
- 函数的prototype
1.函数的prototype属性 每一个函数都有一个prototype属性,默认指向object空对象(原型对象),每一个原型对象都有一个constructor属性,指向函数对象 2.给原型对象添加属 ...