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 ...
随机推荐
- vue 首次加载缓慢/刷新后加载缓慢 原因及解决方案
# vue 首次加载缓慢/刷新后加载缓慢 原因及解决方案 最近做项目发现一个问题,页面每次刷新后加载速度都非常慢,20s左右,在开发环境则非常流畅,几乎感觉不到,本文参考望山的各种方案优化 1,关闭打 ...
- 第二十九章 System V共享内存
共享内存数据结构 共享内存函数 shmget int shmget(key_t key, size_t size, int shmflg); 功能: 用于创建共享内存 参数: key : 这个共享内存 ...
- [Neo4j]Conda虚拟环境中安装python-igraph
neo4j算法需要用到python-igraph包,但试过很多方法,都失败了 pip install python-igraph 安装失败, 提示C core of igraph 没有安装. 在con ...
- 关于 Java 中多线程的面试问题 详解
多线程细节: 1. 面试题: sleep 方法 和 wait 方法异同点是什么? 相同点: 可以让线程 处于 冻结状态. 不同点: 1. sleep 必须指定时间 wait 可以指定时间, 也可以不指 ...
- Lucas的数论:杜教筛,莫比乌斯反演
Description: 求$\sum\limits_{i=1}^{n} \sum\limits_{j=1}^{n} d(i \times j)$ $d(i)$表示$i$的约数个数和.$n \leq ...
- Git基础使用
前言 Git是版本控制系统,由Linux开源社区开发.与其他的版本系统相比,Git更加快速,便捷.主要是Git存储的是快照,而非差异性比较.并且绝大数操作都是访问本地文件和资源,没有网络时也可以直接提 ...
- NOIP模拟测试12
T1 斐波那契 一道找规律题,被我做成了贼难的题. 观察图片可知x=f[i-1]+j.(j为x的父亲)且j<=f[i-1],然后就二分找父亲没了. #include<bits/stdc++ ...
- 一份自用的webpack配置文件及其配置说明
1.webpack.config.js const path = require('path') const HtmlWebpackPlugin = require('html-webpack-plu ...
- NOIP模拟赛18 皇帝的烦恼O(∩_∩)O 二分+DP
题目描述 经过多年的杀戮,秦皇终于统一了中国.为了抵御外来的侵略,他准备在国土边境安置n名将军.不幸的是这n名将军羽翼渐丰,开始展露他们的狼子野心了.他们拒绝述职.拒绝接受皇帝的圣旨. 秦皇已经准备好 ...
- 生活问题 | 对华为畅玩手机5X进行升级
步骤一:准备一张SD卡,建议使用Sandisk, Kingstone, 或Kingmax,大小建议在2G KIW-AL10C00B258 软件版本升级指导书 Secret 2016-11-25 Hu ...