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 ...
随机推荐
- windows 360浏览器打开网站白屏
1.场景 使用windows的360浏览器打开网页白屏 使用mac 谷歌,360,火狐浏览器打开均正常 2.原因 windows浏览器默认使用的是ie浏览器内核渲染的,js执行时发生错误 3.添加he ...
- Spring Boot 如何给微信公众号返回消息
hello 各位小伙伴,今天我们来继续学习如何通过 Spring Boot 开发微信公众号.还没阅读过上篇文章的小伙伴建议先看看上文,有助于理解本文: Spring Boot 开发微信公众号后台 上篇 ...
- token和session
什么是token? token是服务端生成的一串字符串,目的是作为客户端进行请求的一个令牌.当第一次登录后,服务器生成一个token(一串字符串),并将此token返回给客户端,此后页面接收到请求后, ...
- Java编程思想——第14章 类型信息(一)
运行时类型信息使得你可以在程序运行时发现和使用类型信息.Java是如何让我们在运行时识别对象和类的信息得呢? 主要有两种方式:1.传统RTTI,他假定我们在编译期间已经知道了所有类型:2.反射,它允许 ...
- 死磕 java线程系列之ForkJoinPool深入解析
(手机横屏看源码更方便) 注:java源码分析部分如无特殊说明均基于 java8 版本. 注:本文基于ForkJoinPool分治线程池类. 简介 随着在硬件上多核处理器的发展和广泛使用,并发编程成为 ...
- Unity3-各个内置面板,对象说明
*在Inspector面板中,是表示每个物体(诸如摄像机,圆柱,正方体)的组件. 组件包含: 1.Transform,在第一节当中,可以用于变换物体的位置.每个物体对象都有. 2.cube,网格,对于 ...
- 如何在双向绑定的Image控件上绘制自定义标记(wpf)
我们的需求是什么? 答:需要在图片上增加一些自定义标记,例如:2个图片对比时,对相同区域进行高亮. 先上效果图: 设计思路 1.概述 1.通过TargeUpdated事件,重新绘制图片进行替换. 2. ...
- m98 lsc rp-- 赛
lsc 这次又烧rp了! T1随机化艹spj 本机测试输出字符串长度没有低于1W的,考完发现凉凉 但是lemon又救了我的*命,垃圾lsc又烧rp了!
- jquery设置html5音量的方法
jquery设置html5音量的方法<pre> setTimeout(function() { alert(1); $('#music1')[0].volume = 0; setTimeo ...
- WIN7安装Docker Toolbox、制作镜像并发到阿里云
一.安装Docker Toolbox,并配置国内源加速 WIndows7不支持Hyper-v,所以只能采用Docker Toolbox的方式使用Docker.传送门:http://mirrors.al ...