三. 柱状图(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的更多相关文章

  1. Chapter 04—Basic Data Management

    1. 创建新的变量 variable<-expression expression:包含一组大量的操作符和函数.常用的算术操作符如下表: 例1:根据已知变量,创建新变量的三种途径 > my ...

  2. Chapter 2 Basic Elements of JAVA

    elaborate:详细说明 Data TypesJava categorizes data into different types, and only certain operationscan ...

  3. 吴裕雄--天生自然 R语言开发学习:基本图形(续二)

    #---------------------------------------------------------------# # R in Action (2nd ed): Chapter 6 ...

  4. 吴裕雄--天生自然 R语言开发学习:基本图形(续一)

    #---------------------------------------------------------------# # R in Action (2nd ed): Chapter 6 ...

  5. 吴裕雄--天生自然 R语言开发学习:基本图形

    #---------------------------------------------------------------# # R in Action (2nd ed): Chapter 6 ...

  6. 吴裕雄--天生自然 R语言开发学习:基本图形(续三)

    #---------------------------------------------------------------# # R in Action (2nd ed): Chapter 6 ...

  7. 离散数学及其应用(Discrete Mathematica With Application 7th)学习笔记 第一章

    目前本人只进行到了第五章的章末补充练习,应该是从4月6号开始学习的,又是英文版,而且基本就下班回家抽2个小时左右去学,所以进度较慢. 由于本质是数学,除了一些程序处理和大计算量的问题,基本上一本草稿本 ...

  8. tensorflow学习框架(炼数成金网络版学习记录)

    chapter1 #变量 import tensorflow as tf x = tf.Variable([1,2]) a = tf.constant([3,3]) #增加一个减法op sub = t ...

  9. 吴裕雄--天生自然 R语言开发学习:中级绘图(续二)

    #------------------------------------------------------------------------------------# # R in Action ...

随机推荐

  1. access技巧 access源码 这里都可找到哦

    这个网站不错,有很多access技巧 access源码 还有access公开课 access免费培训 access教程 大家要多看看哦: http://www.office-cn.net access ...

  2. 使用ESP8266 打造一款物联网产品---新版ESP8266-RTOS-SDK(V3.1以上)串口使用指南

    问题背景: 使用乐鑫的ESP8266做一个物联网的项目,要使用串口0通信,串口1作为打印log.本来是一个非常简单的事情.没想到居然里面有个大坑.本着前任踩坑,后任抱娃的原则. 这里就做个记录,给后面 ...

  3. Web for pentester_writeup之File Include篇

    Web for pentester_writeup之File Include篇 File Include(文件包涵) Example 1 加一个单引号 从报错中我们可以获取如下信息: 当前文件执行的代 ...

  4. 【XSY2131】【BZOJ1857】【SCOI2010】传送带

    Description 题目描述: 在一个二维平面上有两条传送带,每一条传送带可以看成是一条线段.两条传送带分别为线段AB和线段CD.小y在AB上的移动速度为P,在CD上的移动速度为Q,在平面上的移动 ...

  5. CSPS模拟 73

    被T3坑了 忘记考虑$atan$只会返回正数导致无法区分方向相反模长相等的两个向量 直接把向量拆成ab两个上三角函数干出来就对了 真的exhausted

  6. Mybatis精讲(一)---环境配置及架构梳理

    目录 简介 ORM模型 Hibernate Ibatis 环境搭建 jar 配置 xml方式配置 代码方式配置 两种方式对比 Mybatis结构 源码解读xml环境加载 映射器解读 Ibatis # ...

  7. SSM学习成果总结,图书管理系统进行三层整合

    一:先看一下效果图 二:目录结构  三:pojo package com.zh.pojo; import lombok.AllArgsConstructor; import lombok.Data; ...

  8. PHP 格式化公钥私钥(pem文件)

    <?php header("Content-Type: text/html; charset=utf-8"); $filename = dirname(__FILE__).& ...

  9. 物联网安全himqtt防火墙数据结构之红黑树源码分析

    物联网安全himqtt防火墙数据结构之红黑树源码分析 随着5G的发展,物联网安全显得特别重要,himqtt是首款完整源码的高性能MQTT物联网防火墙 - MQTT Application FireWa ...

  10. Java基础:数组的声明,循环,赋值,拷贝。

    数组的声明 一般有两种形式的声明: int[] a; int a[]; 这两种声明都没错,但是大多数都使用第一种声明,因为变量名是独立的,不带任何符号. 声明一个数组,并没有将a真正的初始化为一个数组 ...