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 ...
随机推荐
- phpstudy 升级mysql到mysql5.7
前言 今天在工作发现一个错误,在往本地导数据表的时候老是报错: ? 1 [Err] 1294 - Invalid ON UPDATE clause for '字段名' column 报错的数据表字段: ...
- SAP SOAMANAGER报错原因与故障排除方法
一些刚刚接触到SAP Webservice的开发者由于对SAP Netweaver组件的不熟悉,往往在使用事物码SOAMANAGER进行webservice配置的时候,发现无法正常启动SOAMANAG ...
- [专题总结]AC自动机
其实前面的模板也不是1A,我在题库里提前做过,也不必在意罚时,刚开始我在做别的专题 裸模板我就不说了,各个博客讲解的很明白 void insert(string s){ ,len=s.size(); ...
- UiPath之文件操作
今天给大家介绍一下,在UiPath中如何操作文件,比如需要在某个文件夹中自动创建一个当天日期的文本. 主要使用的activity有: l Assign l Path Exists l If l ...
- C语言:互质
今天遇到一道奇怪的程序题,和平常的不同.同样都是互质,但是一般的题目都是判断两个数字是否互质,但这道题则是给定一个数字n,要求输出所有小于等于n的与n互质的数,题目已经在下面给出: 质数与互质概念不是 ...
- 深入理解计算机系统 第二章 信息的表示和处理 part2
上一周遗留问题的解决 问题:原码.反码.补码是只针对有符号数吗?无符号数有没有这三种编码方式? 得到的答案:对于无符号数,原码.反码和补码是一致的 进一步,由于有符号数是以补码的形式存储在计算机中 ...
- Java基础:8种基本数据类型,取值范围和储存字节说明。
Java中,一共有8种基本数据类型: 4种整数型:int,short,long,byte. 2种浮点型:float,double. 1种字符类型:char. 1种表示真值的类型:boolean. [S ...
- 【SQL SERVER】2017 Developer 安装教程
官网下载地址:https://www.microsoft.com/zh-cn/sql-server/sql-server-downloads 1.下载之后双击exe文件,选择基本 自定义都行 2.选择 ...
- 一个ip, 两个域名, 两个ssl, 访问多个不同的项目
在前面一篇中说过, 入了好几个坑. 后来使用了nginx+tomcat配置的方式. 终于成功了. 因为头一次使用nginx, 不知道具体怎么操作, 于是我在操作的时候, 按照以下几个步骤执行的: 导航 ...
- mysql出现ERROR 1819 (HY000)的解决方法
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements, 出现这个问题怎么办? 为了加强安 ...