以下绘图以Weibull分布(韦伯分布、威布尔分布)为例

关于Weibull分布(韦伯分布、威布尔分布),请参考本人博客http://www.cnblogs.com/wwxbi/p/6141501.html

  1. library(ggplot2)
  2. # 这里的d和y都有大小顺序
  3. d<- seq(0, 5, length.out=10000)
  4. y<-dweibull(d, shape=5, scale=1, log = FALSE)
  5. df<-data.frame(x=d,y)
  6. ggplot(df,aes(x=d,y))+
  7. geom_line(colour="green")+
  8. ggtitle("Weibull distribution \n 概率密度图")

  1. # 这里的h没有大小顺序
  2. h <- rweibull(100000, shape=5, scale=1)
  3. ggplot(NULL,aes(x=h))+
  4. geom_histogram(binwidth = 0.01,fill="white",colour="red")+
  5. ggtitle("Weibull distribution \n 直方图")

  1. ggplot(NULL,aes(x=h))+
  2. geom_density(colour="green")+
  3. ggtitle("Weibull distribution \n 概率密度图")
  4.  
  5. ggplot(NULL,aes(x=h))+
  6. geom_line(stat="density",colour="green")+
  7. ggtitle("Weibull distribution \n 概率密度图")

  1. library(sqldf)
  2. library(ggplot2)
  3.  
  4. d<- seq(0, 5, length.out=10000)
  5. df1<-data.frame(num=seq(0,5,length=10000),groupID="λ=1,k=0.5",rw=dweibull(d, scale=1,shape=0.5 ))
  6. df2<-data.frame(num=seq(0,5,length=10000),groupID="λ=1,k=1",rw=dweibull(d, scale=1,shape=1 ))
  7. df3<-data.frame(num=seq(0,5,length=10000),groupID="λ=1,k=1.5",rw=dweibull(d, scale=1,shape=1.5 ))
  8. df4<-data.frame(num=seq(0,5,length=10000),groupID="λ=1,k=5",rw=dweibull(d, scale=1,shape=5 ))
  9.  
  10. df5<-sqldf("
  11. select num,groupID,rw from df1
  12. union all
  13. select num,groupID,rw from df2
  14. union all
  15. select num,groupID,rw from df3
  16. union all
  17. select num,groupID,rw from df4 ")
  18.  
  19. df<-subset(df5, rw <2 )
  20.  
  21. ggplot(df,aes(x=num,y=rw,group=factor(groupID),colour=factor(groupID)))+
  22. geom_line()+
  23. ggtitle("Weibull distribution \n 概率密度图")

  

  1. library(sqldf)
  2. library(ggplot2)
  3. df2<-data.frame(num=seq(0,5,length=10000),groupID="λ=1,k=1",rw=rweibull(10000, scale=1,shape=1 ))
  4. df3<-data.frame(num=seq(0,5,length=10000),groupID="λ=1,k=1.5",rw=rweibull(10000, scale=1,shape=1.5 ))
  5. df4<-data.frame(num=seq(0,5,length=10000),groupID="λ=1,k=5",rw=rweibull(10000, scale=1,shape=5 ))
  6.  
  7. df<-sqldf("
  8. select num,groupID,rw from df2
  9. union all
  10. select num,groupID,rw from df3
  11. union all
  12. select num,groupID,rw from df4 ")
  13.  
  14. ggplot(df,aes(x=rw,group=factor(groupID),colour=factor(groupID)))+
  15. geom_density()+
  16. ggtitle("Weibull distribution \n 概率密度图")

  1. library(sqldf)
  2. library(ggplot2)
  3.  
  4. d<- seq(0, 5, length.out=10000)
  5. df1<-data.frame(num=seq(0,5,length=10000),groupID="λ=0.5,k=1",rw=dweibull(d, scale=0.5,shape=1 ))
  6. df2<-data.frame(num=seq(0,5,length=10000),groupID="λ=1,k=1",rw=dweibull(d, scale=1,shape=1 ))
  7. df3<-data.frame(num=seq(0,5,length=10000),groupID="λ=1.5,k=1",rw=dweibull(d, scale=1.5,shape=1 ))
  8. df4<-data.frame(num=seq(0,5,length=10000),groupID="λ=3,k=1",rw=dweibull(d, scale=3,shape=1 ))
  9.  
  10. df5<-sqldf("
  11. select num,groupID,rw from df1
  12. union all
  13. select num,groupID,rw from df2
  14. union all
  15. select num,groupID,rw from df3
  16. union all
  17. select num,groupID,rw from df4 ")
  18.  
  19. df<-df5
  20.  
  21. ggplot(df,aes(x=num,y=rw,group=factor(groupID),colour=factor(groupID)))+
  22. geom_line()+
  23. ggtitle("Weibull distribution \n 概率密度图")

ggplot2绘制概率密度图的更多相关文章

  1. ggplot2绘制多图

    参考链接:http://www.cnblogs.com/nxld/p/6065237.html ggplot2.multiplot是一个易于使用的功能,将多个图形在同一页面上使用R统计软件和GGPLO ...

  2. R绘图 第六篇:绘制线图(ggplot2)

    线图是由折线构成的图形,线图是把散点从左向右用直线连接起来而构成的图形,在以时间序列为x轴的线图中,可以看到数据增长的趋势. geom_line(mapping = NULL, data = NULL ...

  3. R-forestplot包| HR结果绘制森林图

    本文首发于“生信补给站”微信公众号,https://mp.weixin.qq.com/s/2W1W-8JKTM4S4nml3VF51w 更多关于R语言,ggplot2绘图,生信分析的内容,敬请关注小号 ...

  4. R绘制韦恩图 | Venn图

    解决方案有好几种: 网页版,无脑绘图,就是麻烦,没有写代码方便 极简版,gplots::venn 文艺版,venneuler,不好安装rJava,参见Y叔 酷炫版,VennDiagram 特别注意: ...

  5. 用canvas绘制折线图

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  6. php中用GD绘制折线图

    php中用GD绘制折线图,代码如下: Class Chart{ private $image; // 定义图像 private $title; // 定义标题 private $ydata; // 定 ...

  7. 使用Canvas绘制背景图

    原文  http://www.imququ.com/post/use-canvas-as-background-image.html 最近iCloud Web的Beta版换了UI,整体风格变得和iOS ...

  8. Excel应该这么玩——7、我是预言家:绘制趋势图

    让我们先看一个场景:你是公司销售部的员工,你手里有公司最近几年的销售额相关的数据,经理希望你预测下个月的销售额.盯着一堆数据,你或许会想到画一张XY坐标图,然后将每个月份的销售额标定为一个坐标.但是下 ...

  9. 使用Excel 2007绘制甘特图

    本文将教大家如何使用Excel 2007制作甘特图.Excel并未提供甘特图类型,但还是可以绘制甘特图的,方法就是通过对堆积条形图类型进行自定义,使之显示任务.任务工期和层次结构. 下面的过程可帮助创 ...

随机推荐

  1. QT QGraphicsProxyWidget对象可选择或移动的一些tricks

    我在QT图形视图框架中使用QGraphicsProxyWidget嵌入widget,但是无法使其和其它的QGraphicsItem一样可以选择或移动,使用如下语句无效:  C++ Code  1234 ...

  2. javascript消除字符串两边空格的两种方式,面向对象和函数式编程。python oop在调用时候的优点

    主要是javascript中消除字符串空格,比较两种方式的不同 //面向对象,消除字符串两边空格 String.prototype.trim = function() { return this.re ...

  3. Core Java笔记

    前言 一·基础知识 二·定义,关键字和类型 三·表达式和控制流 四·数组 五·对象和类 六·高级语言特性 七·异常 八·图形用户接口 九·AWT(Abstract Window Toolkit) 事件 ...

  4. [AX]AX2012 R2 采购订单的“Request change”

    在采购订单List或者Detail窗口的操作面板上有一个叫做“Request change”的按钮,如果这个按钮是激活的,采购订单不能直接编辑,而必须先使用这个按钮请求修改后,采购订单才能进入编辑状态 ...

  5. 屏蔽win10中文输入法

    Windows 10自带的默认输入法,是通过Shift键来切换中/英文,这样为玩一些不需要打字,却需要使用Shift键的游戏带来了不便,比如,在进行游戏的时候,按下Shift键后,再按跳跃.射击等键, ...

  6. pycharm 激活

    方法1: (1)更新**hosts**文件 [hosts文件百度云下载地址](https://pan.baidu.com/s/1o9ZujxS) **hosts**文件在windows中的地址为: C ...

  7. An internal error occurred during: "Launching xxx on WebLogic10.x".

    An internal error occurred during: "Launching xxx on WebLogic10.x". java.lang.NullPointerE ...

  8. 【RF库Collections测试】Reverse List

    Name:Reverse ListSource:Collections <test library>Arguments:[ list_ ]Reverses the given list i ...

  9. 使用java连接数据库以后显示“ Establishing SSL connection without server's identity verification is not recommended”的警告如何解决

    今天写了一段查询数据库的操作,如下 package MySQL; import java.sql.*; public class MySQL { //JDBC驱动名以及数据库URL static fi ...

  10. 敏捷开发中的Scrum流程和术语【转】

    任何人力流程都离不开人来执行,所以在讲解Scrum流程之前,有必要先把Scrum中的角色讲一下. 一天,一头猪和一只鸡在路上散步,鸡看了一下猪说,“嗨,我们合伙开一家餐馆怎么样?”,猪回头看了一下鸡说 ...